Repository navigation
fix(compaction): cap summary reasoning, degrade on truncation, key the failure breaker by attempt - #376
Open
ZouR-Ma wants to merge 1 commit into
Open
fix(compaction): cap summary reasoning, degrade on truncation, key the failure breaker by attempt#376ZouR-Ma wants to merge 1 commit into
ZouR-Ma wants to merge 1 commit into
Conversation
…e failure breaker by attempt Automatic compaction of a long session could fail repeatedly: the summary request inherited the session thinking level (for example max), adaptive thinking has no budget, reasoning consumed most of the output cap and truncated the summary body, and the whole compaction was reported as failed. The prompts also asked for a complete handoff that never dropped finished items, so summaries grew on every compaction, and switching models reset the failure count so the breaker never tripped. - Add compaction.thinkingLevel (default low, inherit keeps the old behavior). The summary request uses min(session level, configured level), clamped to what the model supports. - Add compaction.summaryTargetTokens (default 16000, capped at half the output limit). The prompts state a length budget and the update prompt consolidates the previous summary instead of copying it forward. - When a summary stops on length, retry once with reasoning removed and once with a tightened target before failing. Attempts are recorded as degradations in the diagnostics and a truncated summary is still never persisted. - Count threshold-compaction failures per attempt fingerprint (provider/model, maxTokens, context window, summary thinking level) instead of resetting on every model switch. A pause only applies to the fingerprint that failed, and a summary that is still truncated after the whole ladder pauses automatic compaction on the first occurrence.
ZouR-Ma
requested review from
MelodyVAR,
Uking-xxx and
liuedcson
as code owners
November 29, 2026 08:13
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.
Problem
Automatic compaction of a long session (1M context window, 64k output cap, session thinking level
max) failed twice in a row on the same input, each attempt taking about 8.7 minutes, and succeeded on the third attempt by chance. The agent loop was blocked for about 28 minutes.Root causes:
stopReason=length).Changes
compaction.thinkingLevel(defaultlow,inheritkeeps the old behavior). The summary request usesmin(session level, configured level), clamped to what the model supports.compaction.summaryTargetTokens(default 16000, capped at half the model output limit). The prompts state a length budget, and the update prompt consolidates the previous summary instead of copying it forward.length, retry once with reasoning removed, then once with a tightened target, before failing. The steps are recorded asdegradationsin the diagnostics. A truncated summary is still never persisted.provider/model | maxTokens | window | summary thinking level) instead of being cleared on every model switch. A pause applies only to the fingerprint that failed. A summary that is still truncated after the whole recovery ladder pauses automatic compaction on the first occurrence.New files:
src/core/compaction/summary-policy.ts,test/compaction-thinking-level.test.ts. Docs (docs/compaction.md,docs/settings.md) andschema/config.schema.jsonare updated.Verification
Run on a clean checkout of
main:pnpm install --frozen-lockfile,tsgo --noEmit,biome check --error-on-warnings packages/coding-agent,generate-config-schema.ts --check: all exit 0check-public-boundary.mjsandcheck-no-observability.mjs: passNotes for reviewers
compaction.thinkingLevel = lowis provisional. It has not yet been validated by replaying a real long session at each level.inheritrestores the previous behavior if a more conservative rollout is preferred.test/suite/regressions/compaction-adaptive-wire.test.tspins the SHA256 of the three summary prompt templates. The hashes are updated for the new prompts, and any later prompt change must update them again.budget_tokens, and whether 64k is the gateway's real output limit.