Repository navigation
fix #95219: [Bug]: Historical tool results are re-truncated between turns, breaking prompt cache prefix stability - #95305
mikasa0818 wants to merge 5 commits into
Conversation
|
Thanks for the context here. I did a careful shell check against current Current main already solves the PR's central bug with the merged per-attempt tool-result projection implementation from #95624, so this separate live-quantum branch is no longer needed as a merge candidate. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. So I’m closing this as already implemented rather than keeping a duplicate issue open. Review detailsBest possible solution: Keep the current-main per-attempt projection-state implementation from #95624 and close this superseded branch; reopen only with evidence that current main still rewrites historical tool-result bytes. Do we have a high-confidence way to reproduce the issue? No current-main failing reproduction remains from source inspection: current main keeps a request-local projection state and has a growing-history regression test that asserts the old projected prefix stays byte-stable. I did not run tests in this read-only review. Is this the best way to solve the issue? No, this PR is no longer the best landing path because current main already solved the bug through the merged per-attempt projection-state implementation. The safer path is to keep that implementation rather than add this alternate live-quantum policy. Security review: Security review cleared: No concrete security or supply-chain concern is visible; the PR touches agent prompt-projection logic and a colocated test only. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 89b2db77d4d5; fix evidence: commit 708c1b31e097, main fix timestamp 2026-06-22T01:17:50Z. |
Co-Authored-By: Claude <[email protected]>
…ishable Co-Authored-By: Claude <[email protected]>
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Fixes #95219.
This stabilizes live prompt-history tool-result projection by rounding aggregate live truncation overflow up to a coarse quantum and taking selected older entries to a stable floor instead of progressively shaving the same old result on every prompt build. Persisted session/transcript recovery and its estimator keep exact aggregate shaving.
What Problem This Solves
Long channel sessions can accumulate large historical tool outputs. The live prompt aggregate truncation pass previously rebuilt model-facing content from the current message set and spent the exact aggregate overflow on older tool results first. When a later turn appended more tail tool output, the same historical tool result could be truncated to a different target and appear with different bytes in adjacent model requests, cutting the prompt-cache prefix at that old message.
Real behavior proof
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/tool-result-truncation.test.tsnode --import tsxalso completed with exit status 0 and invokedtruncateOversizedToolResultsInMessages()plusestimateToolResultReductionPotential()from the built source tree.oldestProjectionStable: true, first/second oldest projection lengths both69, and exact persisted recovery estimateaggregateReducibleChars: 3000. The focused tests also confirm durable recovery still honors the exact aggregate cap.sonarlint,sonar-scanner, andsonarjswere not available in this environment.Evidence
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/tool-result-truncation.test.ts— exit status 0.node --import tsx <inline production prompt-projection proof>— exit status 0; observedoldestProjectionStable: true,firstOldestLength: 69,secondOldestLength: 69, andrecoveryEstimateAggregateReducibleChars: 3000.sonarlint,sonar-scanner, orsonarjsexecutable in this environment.Review findings addressed
estimateToolResultReductionPotential(), keeping persisted recovery estimates exact, and adding a regression that reportsaggregateReducibleChars: 3000for a 15k -> 12k exact recovery case.node --import tsxthat invokes the prompt projection owner and records the stable-prefix result. A live provider prompt-cache trace remains unavailable in this Windows environment and is disclosed under What was not tested.Regression Test Plan
src/agents/embedded-agent-runner/tool-result-truncation.test.tsRoot Cause
buildAggregateToolResultReplacementsused exact aggregate overflow (totalChars - aggregateBudgetChars) for live prompt projection and spent that exact amount on older tool results first. Because the newer tail grew between turns, the same old result received a different exact target and could be re-projected into different model-facing bytes.tool-result-truncation.ts. Rounding live aggregate overflow up to a 20% aggregate-budget quantum and taking each selected old result to the stable floor creates deterministic headroom on the first aggregate rewrite, so adjacent turns with newer tail output do not shave the same oldest result again. The persisted recovery estimate deliberately stays exact, matching persisted session/transcript recovery.Merge risk
tool-result-truncation.tsand its colocated test. No fallback path, no lint suppression, no.only, no@ts-ignore, no lockfile, and no unrelated file changes.Scope boundary
src/agents/embedded-agent-runner/tool-result-truncation.ts; callers continue invoking the same truncation APIs, and persisted session state recovery keeps exact aggregate shaving.