feat(coding-agent): add staged context compaction#332
Draft
minpeter wants to merge 1 commit into
Draft
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.
Summary
Why
The current overflow retry makes a single summary request over one large old prefix. If that summary request itself exceeds the model context, or if the resulting checkpoint still exceeds the active-context budget, no durable progress can be made. The previous speculative fallback also removed messages from summary input while retaining the original checkpoint boundary, which could claim history was summarized when it was not.
Safety and bounds
Validation
npm run buildnpm run checkgit diff --checkKnown baseline issue
packages/coding-agent/test/suite/agent-session-compaction.test.tshas 34 passing tests and one existing characterization failure:does not consume the overflow compact-and-retry attempt when compaction fails before retrying. The same failure was reproduced from clean upstream commit38bd3a3cf8a47c1201969117b1a82a5af7daac9c; that harness uses no configured auth and does not persist the synthetic messages intoSessionManager, so no overflow compaction start is emitted. This PR does not change that unrelated test.Summary by cubic
Adds staged context compaction to
packages/coding-agent, keeping the existing one-shot path and falling back to a bounded, durable staged sequence when a compaction or its summary would overflow. This makes overflow recovery reliable, restart-safe, and prevents silent history drops.New Features
AgentSession: up to 8 stages or 5 minutes, each accepted stage writes a normal checkpoint; only the final stage triggerswillRetry.planStagedCompactionChunk()selects the largest token-budgeted contiguous prefix of the oldest complete turns, retains the newest turn, and keeps tool-call/result pairs together.CompactionSummaryOverflowErrorand switches to staged recovery.stagemetadata added to compaction events and extension hooks (index, maxStages, final).Bug Fixes
would-overflowand hands off to staged recovery.Written for commit 626210c. Summary will update on new commits.