fix(agents): keep long-context tool-result prompts cache-stable - #95624
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 21, 2026, 9:44 PM ET / 01:44 UTC. Summary PR surface: Source +217, Tests +119. Total +336 across 4 files. Reproducibility: yes. at source level: current main rebuilds aggregate tool-result projections from the evolving message set and spends reductions on older entries first. I did not run a live provider cache trace in this read-only review. Review metrics: 2 noteworthy metrics.
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 reviewed stable live prompt-projection policy for #95219 with focused regression coverage and accurate PR evidence, then close the issue after the chosen fix reaches main. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main rebuilds aggregate tool-result projections from the evolving message set and spends reductions on older entries first. I did not run a live provider cache trace in this read-only review. Is this the best way to solve the issue? Unclear as the final landing path: the PR touches the right owner boundary with per-attempt projection state, but maintainers need to choose this policy over the related open candidate fixes and accept the retained-context tradeoff. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against adb9abe7215e. Label changesLabel justifications:
Evidence reviewedPR surface: Source +217, Tests +119. Total +336 across 4 files. View PR surface stats
Acceptance criteria:
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
|
What Problem This Solves
Fixes an issue where long-running agent sessions on large-context models would lose the cached conversation prefix and rewrite hundreds of thousands of tokens on every turn once accumulated tool-result text crossed the aggregate prompt cap. The system prompt cache survived, but the conversation cache thrashed during active source-gather phases.
Why This Change Was Made
Prompt assembly now keeps a per-attempt, byte-stable projection of cacheable tool-result history instead of repeatedly truncating already-projected results. Aggregate accounting includes frozen projected bytes, reductions apply only to new eligible results, and the fallback clears new result text when the aggregate budget cannot otherwise be met. Projection reuse is occurrence-safe for duplicate identities and refuses to overwrite content transformed by history/media filters. The operator-configurable
agents.defaults.contextLimits.toolResultMaxCharsceiling is raised to1,000,000as an additional mitigation for 1M-context models, with matching docs.User Impact
Long-context sessions retain incremental prompt caching as tool results accumulate, reducing cache-write thrash and avoidable latency/cost. Existing session data is not rewritten by the prompt-only projection path, and transformed or filtered history remains authoritative.
Evidence
98focused agent regression tests pass, including repeated-build cache stability, provider-boundary behavior, duplicate identity handling, image/media-filter preservation, aggregate fallback, and context-engine integration.35config regression tests pass, including acceptance oftoolResultMaxChars: 1_000_000.node scripts/check-database-first-legacy-stores.mjspasses.git diff --checkpasses.autoreview clean: no accepted/actionable findings reported.OPENCLAW_TESTBOX=1 pnpm check:changedattempt completed core typecheck/lint lanes but the remote Testbox stopped during the database-first guard; the same guard passes locally. This is an environment/runner limitation, not a reported test failure.This PR was prepared with AI assistance and reviewed against the repository maintainer workflow.