fix: recover precheck context overflows with measured counts#98090
fix: recover precheck context overflows with measured counts#98090jalehman wants to merge 1 commit into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed June 30, 2026, 4:40 AM ET / 08:40 UTC. Summary PR surface: Source +49, Tests +41. Total +90 across 5 files. Reproducibility: yes. source-reproducible but not live-reproduced here: current main computes precheck budget counts, then returns a preflightRecovery object that drops them before outer overflow compaction chooses currentTokenCount. Review metrics: none identified. 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
Security Review detailsBest possible solution: Land this narrow count-propagation fix after redacted real runtime proof is added or a maintainer explicitly overrides the proof gate. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible but not live-reproduced here: current main computes precheck budget counts, then returns a preflightRecovery object that drops them before outer overflow compaction chooses currentTokenCount. Is this the best way to solve the issue? Yes for the code shape: carrying the existing measured fields through the existing recovery object is narrower than adding config or a new compaction policy, and provider-reported counts still take precedence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3d4b7cade9cd. Label changesLabel justifications:
Evidence reviewedPR surface: Source +49, Tests +41. Total +90 across 5 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
|
|
Closing because the same-author broader implementation landed in #101181 as commit Thank you @jalehman for the fix and follow-through. |
|
Oops, thanks for cleaning this up! |
Related: #96625
What Problem This Solves
Fixes an issue where users with near-full conversations could see auto-compaction report recovery attempts but still fail with a context-overflow warning when OpenClaw's own pre-prompt check detected the overflow before a provider request was sent.
Why This Change Was Made
The pre-prompt and mid-turn overflow checks already measure the rendered prompt pressure, but the synthetic recovery signal dropped those budget facts before the outer compaction loop ran. This change carries the measured token counts through the attempt result and uses them when provider error text has no parseable token count, while preserving provider-reported counts as higher-priority evidence.
User Impact
Auto-compaction can now target the prompt size OpenClaw actually measured for precheck-triggered overflows, reducing false recovery loops where compaction reports success but the retry remains over budget.
Evidence
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.overflow-compaction.test.ts src/agents/embedded-agent-runner/run.overflow-compaction.loop.test.ts src/agents/embedded-agent-runner/run/preemptive-compaction.test.ts src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.ts.agents/skills/autoreview/scripts/autoreview --mode branch --base upstream/maingit diff --check upstream/main..HEAD