fix(agents): preserve preflight overflow token counts into recovery budgeting#101181
Conversation
Budget context engine assembly against the reserve and rendered prompt pressure, and carry the preflight estimated prompt tokens, prompt budget, and overflow tokens into the outer overflow recovery loop so compaction engines compact against the prompt OpenClaw actually rendered instead of a minimally over-budget guess.
d3b227c to
94d9056
Compare
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(agents): preserve preflight overflow token counts into recovery budgeting This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
Codex review: needs real behavior proof before merge. Reviewed July 6, 2026, 5:19 PM ET / 21:19 UTC. Summary PR surface: Source +81, Tests +69. Total +150 across 6 files. Reproducibility: yes. source-reproducible: current main computes precheck budget counts, then drops them from preflightRecovery before the outer overflow compaction path chooses currentTokenCount. I did not run a live near-full session in this read-only review. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land one reconciled fix after redacted real recovery proof and maintainer confirmation of the context-engine assemble budget contract. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main computes precheck budget counts, then drops them from preflightRecovery before the outer overflow compaction path chooses currentTokenCount. I did not run a live near-full session in this read-only review. Is this the best way to solve the issue? Yes for the count-propagation path: carrying existing measured fields through the existing recovery object is narrow and keeps provider-reported counts first. The context-engine assemble budget change is plausible but needs maintainer contract confirmation because it changes plugin-facing semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c7295e417d5d. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +81, Tests +69. Total +150 across 6 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
…openclaw#101181) Budget context engine assembly against the reserve and rendered prompt pressure, and carry the preflight estimated prompt tokens, prompt budget, and overflow tokens into the outer overflow recovery loop so compaction engines compact against the prompt OpenClaw actually rendered instead of a minimally over-budget guess.
…openclaw#101181) Budget context engine assembly against the reserve and rendered prompt pressure, and carry the preflight estimated prompt tokens, prompt budget, and overflow tokens into the outer overflow recovery loop so compaction engines compact against the prompt OpenClaw actually rendered instead of a minimally over-budget guess.
What Problem This Solves
When a rendered prompt overflows preflight token checks, the overflow token counts observed during preflight were dropped before recovery ran. Compaction engines then compacted against a stale/underestimated size instead of the prompt OpenClaw actually rendered, and context-engine assembly was not budgeted against the compaction reserve plus rendered prompt pressure before the precheck.
Why This Change Was Made
Recovery decisions should use the best token evidence available at the moment of failure:
buildPreflightRecoveryBudgetSnapshothelper captures estimated prompt tokens, pre-reserve prompt budget, and observed overflow tokens into every token-pressure-drivenpreflightRecoveryassignment.observedOverflowTokens → preflightEstimatedPromptTokens → minimally-over-budget, and logspreflightEstimatedTokens=for diagnosis.tokenBudgetas context budget minus compaction reserve minus rendered prompt pressure, passing the reserve asmaxOutputTokens.The aggregate tool-result char-pressure recovery site keeps no snapshot deliberately — no token estimate exists in that scope; the optional fields plus the fallback chain cover it.
User Impact
Agents recovering from prompt overflow compact against realistic sizes, reducing repeated overflow/compaction loops on long sessions. No config or API changes; the new
preflightRecoveryfields are optional.Evidence
run.overflow-compaction.test.tsand a context-engine assembly budget test inrun/attempt.spawn-workspace.context-engine.test.ts; 120 tests pass across the two touched test files.