Repository navigation
fix(agents): only a request that cannot fit may fail a turn - #200714
Conversation
Context pressure had several independent deciders. The mid-turn check, the prompt preflight, the ChatGPT V2 fallback, reply-level pre-turn compaction and CLI post-turn compaction each stopped or failed a turn on a reserve-based soft threshold, even when the request fit the model window. On team-metal, Peanutto and HamVerBot, 44 of 79 recorded stops in two days were soft-threshold stops. src/agents/context-pressure.ts is now the single owner, with one decision table: - request > window: "overflow"; recovery may still fail the turn - soft pressure at a settled tool boundary: "maintenance"; compact, then always continue the turn, whatever the compaction outcome - soft pressure with an open tool batch: send now and defer - maintenance that cannot reduce context is declined for the rest of the run The mid-turn signal and preflight recovery now carry a required `pressure`, so recovery can no longer turn maintenance into a failed turn. Maintenance stops are no longer logged as `context_overflow` agent failures. Supersedes #200483. Thanks @fuller-stack-dev for the report and the first fix. Co-authored-by: Jason (Json) <[email protected]> Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
|
🦞👀 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. |
Co-authored-by: obviyus <[email protected]>
|
Codex review: needs changes before merge. What this changesThe PR separates optional context maintenance from hard overflow so fitting requests can continue when compaction fails. Example: A settled tool batch produces an estimated 211,600-token request 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⛔ Needs changes before merge - 4 items remain Keep open: this maintainer-authored PR addresses a source-confirmed false-overflow failure still present on main, but cancellation handling, lifecycle classification, and the affected CLI tests need repair. Priority: P1 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe agent runner combines projected request size with tool-settlement evidence to choose normal inference or compaction recovery, while reply and CLI maintenance handle their surrounding lifecycle boundaries. flowchart TD
A[Prepared model request] --> B[Request pressure estimate]
C[Tool settlement evidence] --> D[Context pressure decision]
B --> D
D --> E[Normal inference]
D --> F[Compaction recovery]
F --> E
Technical reviewBest possible solution: Keep the shared pressure decision, preserve cancellation independently of token size, normalize maintenance throughout lifecycle publication, and align the existing CLI regressions. Do we have a high-confidence way to reproduce the issue? Current main routes reserve-threshold pressure into fallible overflow recovery, and the body supplies matching base-versus-head Gateway results; this read-only review did not execute the reproduction. Is this the best way to solve the issue? Sharing the pressure verdict across the existing compaction owners is appropriate, but optional maintenance must preserve cancellation and avoid publishing provider-failure lifecycle facts. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d0a5dbb9c133. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +296, Tests +235, Other +2. Total +533 across 38 files. Added test files: 1. 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. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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, 12:49 PM ET / 17:49 UTC. |
A parked Code Mode run is bound to its session, and compaction may rotate the session, so a boundary with a parked run is not safe for maintenance. CLI post-turn maintenance now honours cancellation before continuing. Co-authored-by: obviyus <[email protected]>
|
Landed as fb9337a. Bug: five paths stopped or failed turns on the soft compaction threshold even when the request fit the window (44 of 79 production stops in two days). Fix: one owner, |
…#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]>
Staging route 1 for openclaw#129388 (staging only; no PR ref move). Upstream main b894fe5 (fetched 2026-11-18T19:00Z), merge base 9122a49 (the chain's own absorb). 42 conflicted paths, all resolved here; rerere replayed none. Agent schema: upstream 703c82d (openclaw#200533) owns 43 (pending-input endings) and 44 is free in this tree, so continuation's recipient authority moves 43 -> 44: - SQLite owner runs upstream's 43 step, then the idempotent authority step; - PostgreSQL ladder: 42 tool usage, 43 endings (from V42), 44 authority (from V43); - backup scopes 43 session_pending_inputs (upstream), 44 session_recipient_authority; - port descriptor pin 44, historical 27-43; witness admits upstream's 43; - the fleet bridge classifies 38-43; it admits only upstream's own 43 there, so the never-deployed chain 43 (upstream 42 + authority) is refused before any write; - jump-14 42 (the fleet on ab5a30e) now runs upstream's 42 and 43, then authority; - package schemaVersions.agent 44; agent-schema-history doc rows 42/43/44 and the authority section (the chain had left it at 42). One owner where upstream now owns a fork extraction: - session-restart-resume: upstream's resolveStartupRestartMarker (openclaw#201060) replaces the fork's session-restart-resume-marker.ts (deleted); the fork's tombstone early return stays ahead of upstream's interrupted-settle check. - user-turn-transcript: upstream's applyUserTurnReplacementText replaces the fork's byte-identical applyPersistedUserTurnReplacementText (deleted). - migration witness: upstream's agentSchemaVersions (+43) replaces the fork's AGENT_WITNESS_SCHEMA_VERSIONS. - session-event delivery: the fork's #1447 cron failure-copy withholding moves into upstream's createSessionEventReplyDelivery; session-event-handoff equals upstream. Other resolutions keep both sides (import unions checked against real uses; upstream openclaw#200533 marker shape `{}`, end causes, lifecycleRestartScope; fork restart tombstones and operator recovery). attempt.cwd-split.test.ts follows upstream's deletion (openclaw#198916); its one fork case moves to attempt.continuation-tools.test.ts. Generated outputs regenerated (config docs, gateway validators, postgres schema, worker inventory). Compile follow-through: compactionTarget.storePath (openclaw#200714) and two fork test cleanups pass upstream's new finishPendingInput end cause. Refs: openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…route the rehomed attempt case - agent-runner.continuation-postcompaction-autocompaction: upstream openclaw#200714 (fb9337a) fails a turn on a failed preflight compaction only when the request cannot fit the context window. The "required compaction's failure" case now crosses the 200k window (still fails, delegate staged), and a new case pins the fitting request that proceeds with the delegate still staged. Red at 8e63e3d (expected the failure copy at 150k), green here. - attempt.continuation-tools.test.ts (rehomed from upstream's deleted cwd-split suite) has no `vi` of its own, so the classifier routed it to unit-fast-isolated, where the attempt harness has no host owner ("Agent admission requires its host owner"). It joins the host-broker list. Refs: openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rk fixtures Compile and behavior follow-through for upstream APIs the merge brought in, each red on ddd0ec7 and green here: - sessions-spawn-cloud: upstream's new paired-device case (openclaw#197469) mocks registerRun as void; the fork's registration returns ownership, so the mock returns a committed-row ownership (tsgo agents-tools TS2322; 16/16). - finishPendingInput now takes an end cause (openclaw#200533): the fork's recorder case and transcript-events case pass "failed" (tsgo other TS2554). - postcompaction-autocompaction: upstream's SessionMaintenanceRequest needs sourceTarget/sourceIdentities (prepareSessionMaintenanceRequest), so the command case prepares the request before scheduling (TS2739); the pressure-handoff report supplies the four subtrees upstream interns (openclaw#199748; 10 cases "snapshot is not an Object" without it, from chain 47edd05); and the required-compaction-failure case crosses the 200k window with a new fitting-request case for openclaw#200714's fit-only preflight failure (from staging ead2225; red at 150k without it). 13/13. (cherry picked from commit 47edd05) Refs openclaw#129388 Co-Authored-By: Claude Opus 5.5 <[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)
Supersedes #200483. Thanks @fuller-stack-dev for finding this and for the first fix; this PR applies the same rule to every route that had the bug.
The rule
Only a request that cannot fit the model window may fail a turn. Any other context-pressure signal only schedules maintenance, and maintenance runs only at a boundary where the current tool batch can continue.
What was wrong
Five independent paths stopped or failed a turn on a reserve-based soft threshold even when the request still fit:
checkMidTurnPrecheck, #73499/#168338/#190017)MidTurnPrecheckSignal→ recovery; a failed compaction surfaced "Auto-compaction failed"maintenanceonly at a settled boundary; send otherwiseattempt-prompt-preflight)overflowonly when over the windowrunSessionCompactionIfNeeded, #49479/#130863)cli-compaction)Production evidence (gateway logs, 2026-11-16..17): 79 context-pressure stops across team-metal (62), Peanutto (15) and HamVerBot (2). 44 were soft-threshold stops whose request fit the window. Every stop was logged as an
embedded_run_agent_endcontext_overflowfailure.Fix
src/agents/context-pressure.tsis the single owner:overflow(recovery may fail the turn)maintenance(compact, always continue)waitis bound to the session that compaction may rotate), and no approval prompt is waiting.MidTurnPrecheckRequest.pressureandpreflightRecovery.pressureare required, so recovery cannot turn maintenance into a failed turn.context_overflowagent failures, nor aslivenessState=blocked.Evidence
Real-model E2E,
openai/gpt-6.1-sol(272k window, 204k client threshold,responsesServerCompaction: false). A 182k-token seed turn, then four sequentialexeccalls; the soft check fires at an estimated 211.6k tokens with the batch settled.237e3e4fe0d1kind=compaction_failure)HERON-5521, 0493(correct); logpressure=maintenance→[context-maintenance] declined … continuingHERON-5521, 0493Head runs use a dist built from
a69e3de; base is a dist of237e3e4fe0d1(ocx base merge-base). Raw stderr and replies are below.Base also logged
embedded run agent end … failoverReason=context_overflowfor each; head logged none.Captured E2E output (openclaw agent --local, gpt-6.1-sol; head built from a69e3de)
base / settled:
head / settled:
base / compaction-fails:
head / compaction-fails:
Historical replay of all 79 recorded stops through the new owner:
context_overflow)maintenance(turn continues), 2send(open exec batch)overflow(unchanged)Some of the 35 over-window stops are estimator artifacts after a model switch (e.g. 1,084,694 estimated vs 229,033 measured). That is a separate estimator bug, tracked as a follow-up.
Tests
context-pressure.test.ts: every combination of the decision inputs (48 cases), the fix(agents): never fail a turn on the soft compaction threshold #200483 example (206k on 272k/204k), window and boundary predicates.maintenanceat a settled boundary; new rows cover "soft pressure, open tool batch" (sends) and "over window, open tool batch" (overflow).src/agents/embedded-agent-runnervitest projects, plus reply memory and CLI compaction suites, pass.