fix: make automatic compaction durable and recoverablefix: make automatic compaction durable and recoverable - #378
Open
jiah0231 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #373
Problem
Compressed requests can become unrecoverable when the next provider call fails
immediately after compaction.
Two related runtime problems also show up in long Agent sessions:
the user pauses or sends another message;
Summarizing chat contextcan wait indefinitely when the provider stalls.Root cause
guaranteed to be published back to Cursor.
revision progress.
history and immediately recompact.
cannot safely be used for suffix accounting.
Fix
Publish the compacted checkpoint and wait for its commit barrier before the
next provider call.
Re-estimate token usage from the compacted state.
Rearm automatic compaction after the revision advances instead of limiting a
run to one compaction.
Allow automatic compaction at Resume/model boundaries, so long-running Agent
work does not require a pause or another user message to trigger it.
On initial Resume, directly estimate the recovered state until the current
run has fresh provider usage, avoiding stale pre-compaction usage anchors.
Preserve current upstream projected-message usage-anchor accounting.
Reserve:
max(10_000, max_output_tokens + 4096)and use an inclusive threshold.
Reduce automatic summary max output from 4096 to 2048 tokens.
Add a 30-second total automatic-compaction deadline.
If the summary provider stalls or fails, cancel the summary cycle, build a
durable local fallback summary, publish the compacted checkpoint, and
continue the Agent.
Share token-estimation logic between automatic thresholding and compacted
checkpoint accounting.
Preserve the latest request context across compaction.
Recovery guarantees covered by tests
The regression suite covers the failure sequence from #373:
It verifies that:
It also covers an oversized Resume state that automatically compacts without a
new user message.
Stalled compaction test
A dedicated test uses a provider stream that remains permanently pending.
The real timeout path is exercised:
This test completes successfully after the actual timeout rather than using a
mocked instant timeout.
Validation
Passed on the branch rebased onto current upstream
main:The full
cursor-server --all-targetssuite also passes with only the existingAwaitShell assertion skipped.