Repository navigation
fix(agents): align mid-turn tool-result projection precheck - #101952
ZengWen-DT wants to merge 2 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 8, 2026, 2:16 AM ET / 06:16 UTC. Summary PR surface: Source +29, Tests +58. Total +87 across 2 files. Reproducibility: yes. at source level: current main estimates mid-turn overflow from contextMessages while the later provider prompt path applies aggregate tool-result projection. The linked issue also includes concrete logs and billed-usage deltas, but I did not rerun the original cron scenario. Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land one projection-only fix with exact-head checks and redacted runtime proof, then close or rebase the ratio-only alternatives against the canonical behavior. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main estimates mid-turn overflow from contextMessages while the later provider prompt path applies aggregate tool-result projection. The linked issue also includes concrete logs and billed-usage deltas, but I did not rerun the original cron scenario. Is this the best way to solve the issue? Yes for the projection mismatch: projecting through the same aggregate cap before mid-turn route selection is the narrowest owner-boundary fix I found. The separate global estimator-density debate should remain out of this PR unless maintainers ask to combine it. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 19f7b72a7473. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +29, Tests +58. Total +87 across 2 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
Review history (4 earlier review cycles)
|
|
The linked failure is real, but this branch currently combines two different fixes and the regression does not prove the projection half.
More importantly, the new “fits after boundary projection” case uses 250,000 tool-result chars with a 200,000-token context window and Please split or tighten this before merge: either prove the local mid-turn projection alignment with a case above the actual 400,000-char aggregate cap while retaining the existing density safety policy, or separately justify the global estimator relaxation with provider/tokenizer evidence and token-dense plain-text/JSON negative controls. The current branch is not a low-risk estimator alignment as written. |
|
Thanks, tightened this along the first option. Changes pushed in b134543:
Validation rerun: Autoreview also came back clean: no accepted/actionable findings, overall patch is correct (0.78). |
|
Added the requested live behavior proof to the PR body. Summary of the redacted run: This is the real CLI/provider/tool path with payloads and local state paths redacted. It shows the aggregate-over-cap mid-turn check using the projected provider-boundary view: after projection, overflow remains, but there are no further tool-result chars to reduce, so the route is @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Refs #101929
What Problem This Solves
Mid-turn tool-result precheck estimated the raw in-memory tool-result history, while the next provider prompt path sends the post-truncation projection. When accumulated tool results exceed the live aggregate cap, the mid-turn signal can report route/reducible-char facts from a view that the provider-boundary prompt will not actually send.
This PR now addresses only that projection mismatch. It intentionally keeps the existing conservative 2 chars/token tool-result density policy for the normal pre-prompt estimator.
Why This Change Was Made
The mid-turn precheck now projects messages through
resolveLiveToolResultAggregateMaxCharsandtruncateOversizedToolResultsInMessagesbefore callingshouldPreemptivelyCompactBeforePrompt, using the same context-window-based aggregate cap as the provider prompt path. The globalestimateLlmBoundaryTokenPressuretool-result density behavior is unchanged.Risk note: this touches session-state context routing, so the tests cover the structured mid-turn signal, the aggregate-over-cap projection case, and the lower-budget overflow case where the signal must still fire.
User Impact
Tool-heavy agent sessions with history above the provider-boundary tool-result aggregate cap should get mid-turn routing based on the same bounded prompt view used for the next model call. This does not relax token-density safety for ordinary pre-prompt compaction decisions or for tool-result histories below the projection cap.
Evidence
Source/dependency checks:
truncateOversizedToolResultsInMessagesbefore model submission, while the mid-turn precheck previously estimated the raw post-tool transcript.codex-rs/codex-api/src/common.rs:209,codex-rs/codex-api/src/common.rs:232,codex-rs/codex-api/src/endpoint/responses_websocket.rs:811, andcodex-rs/core/src/client.rs:822,codex-rs/core/src/client.rs:1178,codex-rs/core/src/client.rs:1525,codex-rs/core/src/client.rs:1582. The request builders serialize the supplied input/messages and preserve websocket request fields; there is no hidden expansion that would make the mid-turn raw transcript a better estimator than OpenClaw's provider-boundary projection.Focused validation:
Review:
Live behavior proof:
The live proof used the real CLI, real DeepSeek provider transport, and real exec tool results. The important regression signal is the mid-turn route computed from the projected provider-boundary view: even after the tool-result projection there is still overflow, but
toolResultReducibleChars=0, so the route iscompact_onlyrather than a raw-history truncation route.What was not tested:
AI-assisted: implementation and validation were AI-assisted; focused validation commands were run locally.