fix(compaction): auto-continue after OpenAI Responses output-budget underflow - #1690
Conversation
Treat retry-worthy max_output_tokens/max_tokens underflow errors as threshold compaction continuations, drop the trailing error assistant before rebuilding retry context, and track post-compaction continuations generically. Also clamp OpenAI Responses max_output_tokens to the provider minimum. Assistant-model: GPT-5.5
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
Code Review — PR #1690: continue after OpenAI Responses output-budget underflowThanks for the detailed writeup and transcript evidence — the root-cause analysis is clear and the two-layer fix (classify the error as retry-worthy and clamp Strengths
Observations / discussion points
Nits
Security / performance
Nice fix. The behavioral-await broadening in point 1 is the only thing I'd explicitly confirm is intentional before merge. |
Assistant-model: GPT-5.5
Code Review — fix(compaction): continue automatically after OpenAI Responses output-budget underflowThanks for the detailed writeup and transcript evidence — the root-cause analysis is clear and the fix is well-scoped. Overall this is solid, well-tested defensive work. A few things worth considering before merge. 🔴 Potential unbounded compact→retry loop on the new error pathThe overflow path is guarded by Two failure shapes are possible depending on where the usage anchor lands:
Consider a small consecutive-attempt counter for this family (mirroring 🟡 Clamp-to-16 interaction & coupling
🟢 Nits
👍 Strengths
Nice work — the loop/stall guard is the one item I'd want addressed (or explicitly reasoned about) before merge; the rest are optional. Reviewed against CLAUDE.md conventions (Bun, versionless |
Assistant-model: GPT-5.5
|
Review — fix(compaction): continue after OpenAI Responses output-budget underflow Reviewed the full diff against the CLAUDE.md conventions. This is a well-scoped, well-tested fix. The root-cause analysis (a Strengths
Points to confirm
Minor / nits
Verification
Overall: looks good to merge once (1) is documented and (2) / the Automated review — generated with Claude Code. |
Assistant-model: GPT-5.5
Review: fix(compaction) — continue after OpenAI Responses output-budget underflowNice, well-scoped fix with clear root-cause analysis. The defense-in-depth approach (clamp at the source in the sanitizer and classify the error as retry-worthy in auto-compaction) is the right call, the renames are consistent, and the test coverage is genuinely thorough — structured vs. unstructured error bodies, the exhaustion path, the non- A few observations, all minor / non-blocking: 1. Scope is 2. Two unrelated test files in the diff. 3. 4. Attempt counter increments before the compaction actually runs. 5. Redundant/over-specific regex alternative. 6. Consistency note (not a defect): the exhaustion branch emits Overall this looks solid and safe to merge once the stray test-file changes (#2) are confirmed intentional. Automated review by Claude. |
Summary
Fixes Atomic auto-compaction so a session continues automatically after an OpenAI Responses output-budget underflow error (
Invalid 'max_output_tokens': integer below minimum value. Expected a value >= 16, but got 1 instead.), instead of compacting and then sitting idle until the user manually typesContinue.Root cause
_checkCompaction()runs after every assistant turn. Threshold compaction could fire for an assistant that ended withstopReason: "error", but the retry-worthiness check (shouldRetryAfterThresholdCompaction) only recognizedstopReason: "length"turns. The underflow error therefore compacted withwillRetry: falseand left no automatic continuation path, so the session appeared stuck right afterAuto-compacting....Transcript evidence
A user-provided session transcript showed the manual-continuation pattern repeating at lines
387-390,694-697,886-889, and1085-1088: an assistantstopReason:"error"(invalidmax_output_tokens, got1), followed bycontext_compaction, followed by a manualcontinuefrom the user, followed by the assistant resuming successfully.Changes
agent-session-auto-compaction.ts: Split the retry check intoisRetryWorthyLengthStop(the existingstopReason:"length"case) and a newisRetryWorthyOutputBudgetError, which matchesstopReason:"error"turns on theopenai-responsesAPI whose error message names an output-token budget parameter (max_output_tokens) and underflow/minimum-token wording (e.g.>= 16,got 1 instead), parsing structured JSON error bodies where present.shouldRetryAfterThresholdCompactionnow returns true for either case, so threshold compaction passeswillRetry: truefor this specific error family, drops the trailing error assistant, and schedules automatic continuation. Genericinvalid_request_bodyerrors (e.g. malformed tool schemas) remain non-retryable.MAX_OUTPUT_BUDGET_ERROR_CONTINUATION_ATTEMPTS = 1and a new_outputBudgetErrorContinuationAttemptscounter (reset once an assistant turn completes without failing) so output-budget-triggered compact-and-retry only auto-continues once per failure streak. If the same underflow error recurs after that single retry,_checkCompactionnow emits acompaction_endevent withwillRetry: falseand an explanatoryerrorMessageinstead of looping indefinitely._pendingOverflowPostCompactionContinuation,_overflowPostCompactionContinuationToken,_awaitPendingOverflowPostCompactionContinuation) to generic post-compaction names, since the continuation path is no longer overflow-only. Updated call sites inagent-session-methods.ts,agent-session-prompt.ts, andagent-session.ts.openai-responses-payload-sanitizer.ts: Hardened payload sanitization so a finite numericmax_output_tokensbelow the provider minimum (MIN_RESPONSES_MAX_OUTPUT_TOKENS = 16) is clamped up to16before the request is sent, preventing the underflow error at its source for future requests.docs/compaction.mdanddocs/json.mdto describe the new output-budget-underflow retry path and clarify thatcompaction_end.willRetrynow also covers this case.packages/coding-agent/CHANGELOG.md[Unreleased] > Fixed.agent-session-auto-compaction-queue-03.suite.tsandopenai-responses-payload-sanitizer.test.tsto cover the new retry classification, the attempt-bounding/recovery-exhaustion path, and themax_output_tokensclamping. Also touchedfirst-run-onboarding.test.tsandinteractive-mode-clone-command.test.tsfor the rename of the post-compaction continuation fields.Validation
Continuepattern at387-390,694-697,886-889, and1085-1088.bun run test -- test/agent-session-auto-compaction-queue-03.suite.ts test/openai-responses-payload-sanitizer.test.ts— passed.bun run typecheck— passed.bun run check:file-length— passed.bun packages/coding-agent/src/cli.ts --help | head -40— passed.git diff --check main— clean.BUN_OPTIONS=--timeout=10000to avoid an unrelated Windows full-suite child-process timeout flake while still running hooks).Notes
No version bumps;
mainremains versionless as required.