Repository navigation
fix(agents): never fail a turn on the soft compaction threshold - #200483
fuller-stack-dev wants to merge 4 commits into
Conversation
Mid-turn maintenance pressure stopped the attempt before checking whether compaction could continue the tool batch. When recovery then refused the batch (for example, a Code Mode wait that parked its run), the user saw a context-overflow error for a request that fit the model window. The provider-request precheck now asks recovery's own question with live evidence before stopping. A request that fits the window is sent and compaction waits for a boundary that can continue or for the turn end. A Code Mode wait that returns status waiting now parks its run like exec, including for the conditional sessions_yield check.
OpenClaw-Publication: 35abb358-ecb3-4815-89db-3befe4f1eb2c
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
OpenClaw-Publication: a394597a-0617-4fc4-951a-7028323c6c4c
|
Codex review: needs maintainer review before merge. What this changesThe PR defers soft-threshold compaction when continuation is unsafe and recognizes marked Code Mode wait results as parked runs. Example: A Code Mode wait returns waiting at an estimated 206,084 tokens in a 272,000-token window with a 204,000-token maintenance threshold.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a source-confirmed false-overflow failure still present on main. No introduced runtime or security defect was found; the documentation overstates the guarantee. Priority: P2 Before mergeNone. Findings
Tests
Agent review detailsHow this fits togetherThe embedded runner combines projected provider-request pressure with subscription completion evidence to choose between sending the request and entering transcript compaction recovery. flowchart TD
A[Tool batch results] --> B[Subscription evidence]
A --> C[Provider request projection]
B --> D[Shared continuation predicate]
C --> E[Context pressure guard]
D --> E
E --> F[Send fitting request]
E --> G[Compaction recovery]
D --> G
Technical reviewBest possible solution: Retain the shared continuation predicate and marked-control identity, and describe the guarantee specifically as deferring maintenance for non-continuable batches. Do we have a high-confidence way to reproduce the issue? Main can stop a below-window request on maintenance pressure and then reject continuation because a parked wait lacks the exec-only suspension marker; the PR supplies concrete production values, but this review executed no target code. Is this the best way to solve the issue? The implementation uses the existing pressure and settlement owners, shares the continuation decision, preserves asynchronous-work rejection and session-binding checks, and updates the renamed metadata consumers without adding persistent state. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 96763b979fed. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +87, Tests +81, Docs +9, Other +2. Total +179 across 29 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 17, 2026, 3:11 AM ET / 08:11 UTC. |
|
Thanks for finding this. Your PR showed the soft threshold failing turns at the mid-turn check, and the same mistake turned out to exist in four more places: preflight, the ChatGPT V2 fallback, reply pre-turn compaction and CLI post-turn compaction. #200714 moves all five behind one owner: only a request that cannot fit the window may fail a turn. It credits you as co-author. Once it lands I'll close this one as superseded. |
Context pressure had several independent deciders that stopped or failed a turn on a reserve-based soft threshold even when the request fit the model window: the mid-turn check, prompt preflight, the ChatGPT V2 fallback, reply pre-turn compaction and CLI post-turn compaction. src/agents/context-pressure.ts is now the single owner. Only a request larger than the window may fail a turn. Soft pressure compacts only at a settled tool boundary (no pending, active, background or parked Code Mode work) and always continues the turn; maintenance that cannot reduce context is declined for the rest of the run. Real-model E2E on gpt-6.1-sol (272k window, 204k threshold): base failed the turn with "Auto-compaction failed"; head completed with the correct answer in both journeys. Replay of 79 production stops: 44 soft-threshold stops now continue. Supersedes #200483. Thanks @fuller-stack-dev. Co-authored-by: Jason (Json) <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…#200714) Context pressure had several independent deciders that stopped or failed a turn on a reserve-based soft threshold even when the request fit the model window: the mid-turn check, prompt preflight, the ChatGPT V2 fallback, reply pre-turn compaction and CLI post-turn compaction. src/agents/context-pressure.ts is now the single owner. Only a request larger than the window may fail a turn. Soft pressure compacts only at a settled tool boundary (no pending, active, background or parked Code Mode work) and always continues the turn; maintenance that cannot reduce context is declined for the rest of the run. Real-model E2E on gpt-6.1-sol (272k window, 204k threshold): base failed the turn with "Auto-compaction failed"; head completed with the correct answer in both journeys. Replay of 79 production stops: 44 soft-threshold stops now continue. Supersedes openclaw#200483. Thanks @fuller-stack-dev. Co-authored-by: Jason (Json) <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…#200714) Context pressure had several independent deciders that stopped or failed a turn on a reserve-based soft threshold even when the request fit the model window: the mid-turn check, prompt preflight, the ChatGPT V2 fallback, reply pre-turn compaction and CLI post-turn compaction. src/agents/context-pressure.ts is now the single owner. Only a request larger than the window may fail a turn. Soft pressure compacts only at a settled tool boundary (no pending, active, background or parked Code Mode work) and always continues the turn; maintenance that cannot reduce context is declined for the rest of the run. Real-model E2E on gpt-6.1-sol (272k window, 204k threshold): base failed the turn with "Auto-compaction failed"; head completed with the correct answer in both journeys. Replay of 79 production stops: 44 soft-threshold stops now continue. Supersedes openclaw#200483. Thanks @fuller-stack-dev. Co-authored-by: Jason (Json) <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> Release adaptation: Reviewed soft pressure safe-boundary maintenance and preserved overflow protections. Includes final unchanged memory/gateway helper extractions needed by cap. (cherry picked from commit fb9337a) Co-authored-by: RomneyDa <[email protected]>
Context pressure had several independent deciders that stopped or failed a turn on a reserve-based soft threshold even when the request fit the model window: the mid-turn check, prompt preflight, the ChatGPT V2 fallback, reply pre-turn compaction and CLI post-turn compaction. src/agents/context-pressure.ts is now the single owner. Only a request larger than the window may fail a turn. Soft pressure compacts only at a settled tool boundary (no pending, active, background or parked Code Mode work) and always continues the turn; maintenance that cannot reduce context is declined for the rest of the run. Real-model E2E on gpt-6.1-sol (272k window, 204k threshold): base failed the turn with "Auto-compaction failed"; head completed with the correct answer in both journeys. Replay of 79 production stops: 44 soft-threshold stops now continue. Supersedes #200483. Thanks @fuller-stack-dev. Co-authored-by: Jason (Json) <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit fb9337a) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 28703d8fbcd79dd6cfb5a82aea5ca3b370862590) (cherry picked from commit 5050a8b2af18d68a2e2c509819387206ca1a002a)
Problem
Between tool rounds, the embedded runner stops the attempt (
MidTurnPrecheckSignal) when projected occupancy crosses the client maintenance threshold (for example 204,000 of a 272,000-token window). Recovery then decides whether it can compact and continue the transcript. When it cannot (replay_unsafe), the user sees "Context overflow: prompt too large for the model" for a request that would have fit the real window, and has to press Continue.Production evidence (one Odin gateway, two days): 73 mid-turn precheck aborts with median estimate 207k and p90 215k against a 272k window, none near the window, and no provider-side overflow rejections. One user-visible failure: estimate 206,084 vs threshold 204,000, last batch a Code Mode
waitreturningstatus: "waiting". Recovery rejected it because only Code Modeexecwas recorded as parking a run, soparkedCodeModeRunwas false. The next run compacted 206,029 → 14,530 without trouble.Fix
checkMidTurnPrecheckasks recovery's own question (canCompactAndContinueMidTurn, now shared by the boundary andattempt-recovery) before stopping for reserve-based pressure. It uses live subscription evidence for the current batch. If compaction could not continue the batch and the request fits the hard window (the same nominal full-window check as today's hard admission), the request is sent and compaction waits for a later boundary or the end of the turn. The run still stops for a request over the window, with the existing overflow copy.waitthat parks its run counts as parked.codeModeExecToolNamesbecomescodeModeControlToolNamesand includes the markedexecandwaitcontrols (isCodeModeControlTool). Plain tools namedexecorwaitare excluded. This feeds the completion handler (codeModeSuspended), the conditionalsessions_yieldcheck inattempt.tsand the worker runtime.The boundary predicate trusts subscription evidence only after every call in the current batch has a terminal record. Subscription events trail the agent loop in order, so incomplete evidence makes it defer compaction rather than stop the turn.
Consistent with #189810, #189891 and #190017: hard admission and the soft maintenance threshold remain. This PR only stops the soft threshold from failing a turn that compaction cannot safely continue.
Tests
attempt-context-guards.test.ts: proactive (measured occupancy) pressure that fits the window is sent when the batch cannot continue after compaction, and still signals when it can. Red on base.attempt-midturn-precheck.test.ts(real session/request flow): deferred pressure sends the second request; a deferred request over the window still stops. Red on base for the deferral row.attempt-client-tools.test.ts: the marked Code Mode controls yield{exec, wait}; plainexec/waityield none. Red on base.embedded-agent-subscribe.handlers.tools.test.ts: a markedexecorwaitreturningwaitingparks; unmarked ones do not.run.midturn-precheck-retry.test-support.ts: exec waiting → wait waiting compacts and continues with no error; a replay-unsafe stop shows overflow copy (it is now reached only for a real over-window request).Evidence
attempt-stream-custody.test.tsandattempt.sessions-yield.test.tshave the same 13 local failures on the unmodified base. They are environmental and were left for CI.tsrs) of core plus the agents/cron/gateway test projects shows no errors in touched files. Oxfmt and oxlint pass on touched files, except amax-linescount onattempt-stream-prepare.tsthat this one-line rename does not change.Known gaps
chatgpt-v2-compaction.ts) still signals at its soft trigger. That path is not involved in this incident.