fix(agent): auto-continue output-cap truncations below compaction threshold - #1684
Conversation
…eshold A response truncated at the provider's per-turn output-token cap (stopReason "length") only auto-continued as a side effect of threshold compaction. When the context was still below the compaction budget, _checkCompaction did nothing, so the model's work dead-ended with the red "maximum output token limit" error and the task was left half-finished. Continue length-truncated turns directly when compaction is not needed: drop the incomplete assistant from retry context and resume generation via the existing post-compaction continuation probe so the model finishes where it left off. A small consecutive-continuation cap (MAX_LENGTH_CONTINUATION_ATTEMPTS) prevents runaway loops when a turn keeps exceeding the per-turn output cap, and the resume is gated to the live turn-completion path so a fresh user prompt never resumes an old turn. Adds coverage for the below-threshold continue, zero-output no-op, the non-live pre-prompt guard, and the attempt bound.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Review: auto-continue output-cap truncations below the compaction thresholdNice, well-scoped fix that closes a real gap left by #1662. The design reuses the existing post-compaction continuation lifecycle rather than inventing a new path, the live-turn gating ( A couple of things worth considering before merge: 1.
|
Problem
When a model response is truncated at the provider's per-turn output-token cap (
stopReason: "length"), the model's work dead-ends with the red "Error: Model stopped because it reached the maximum output token limit. The response may be incomplete." banner, and the task is left half-finished.The existing recovery only kicks in as a side effect of threshold auto-compaction:
_checkCompactioncontinues a length-truncated turn (willRetry: true) only when the context also crosses the compaction threshold. When the context is still below the compaction budget — genuine long output with input room to spare —_checkCompactiondid nothing, so the truncation was never continued.This closes the gap left by the compaction-path fix (#1662), which only handled length stops large enough to compact.
Fix
In
_checkCompaction(packages/coding-agent/src/core/agent-session-auto-compaction.ts), when a response is length-truncated with real output (shouldRetryAfterThresholdCompaction) but the context is below the compaction budget, continue the generation directly without compacting via the new_resumeAfterLengthTruncation:agent.continue()rejects an assistant tail), keeping it in persisted history._schedulePostAutoCompactionContinuationProbe) so the model finishes where it left off, reusing the normal continuation lifecycle.MAX_LENGTH_CONTINUATION_ATTEMPTS(3) so a turn that keeps exceeding the per-turn output cap still terminates. The counter (_lengthContinuationAttempts) resets inagent-session-events.tson any non-lengthassistant completion.agent_end,skipAbortedCheck = true), so a fresh user prompt never resumes a previously truncated turn.Compaction-driven continuation and overflow recovery are unchanged.
Tests
Added coverage in
agent-session-auto-compaction-queue-03.suite.ts:_runAutoCompactionMAX_LENGTH_CONTINUATION_ATTEMPTSAll existing auto-compaction / retry / safety-refusal suites pass;
typecheck,lint,check:file-length, andtest:unitare green. Docs (packages/coding-agent/docs/compaction.md) andCHANGELOG.mdupdated.