Repository navigation
fix(agents): keep image history stable during tool loops - #140651
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 11:35 PM ET / September 7, 2026, 03:35 UTC. ClawSweeper reviewWhat this changesThe PR keeps recent images and media references unchanged throughout assistant tool loops, advancing history cleanup only when the next user turn begins, with matching tests and documentation. Merge readiness✅ Ready for maintainer review The fix remains necessary on current main and v2026.9.2. The earlier Gateway fixture finding is resolved, and this review found no remaining actionable defect. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw prepares a replay view of conversation history before sending it to the model. Image cleanup removes older media from that view while preserving recent context and the original transcript. flowchart TD
A[Conversation history] --> B[Identify user turn boundaries]
B --> C[Keep three recent completed turns]
C --> D[Replace older media in replay]
D --> E[Prepare model context]
A --> F[Original transcript preserved]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -2, Tests +46, Docs +1. Total +45 across 4 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep the shared replay cutoff stable until the next user turn while preserving the existing retention window and original transcript. Do we have a high-confidence way to reproduce the issue? Yes, from source: retain an image through three answered turns, begin the fourth, then append an assistant tool call; current main advances the cutoff and replaces the older image. No runtime reproduction was executed in this read-only review. Is this the best way to solve the issue? Yes. Removing the trailing-turn count repairs the shared boundary directly, and the regression cases cover both stable replay bytes and cleanup at the next user turn. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 43210c2a3e72. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…0651) * fix(agents): keep image history stable during tool loops * test(gateway): prune media fixtures at user-turn boundaries
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where users continuing a conversation with image history would lose a stable prompt-cache prefix when the assistant entered a tool loop. With three completed turns and an image in turn 1, the first request of turn 4 preserved that image, but the next request replaced it after a tool-call assistant message appeared. Media-reference text had the same defect.
Why This Change Was Made
The shared history-cleanup owner now counts a prior answered turn only when a subsequent user message begins. Removing the end-of-history count keeps the active turn from advancing the cleanup window, including after its final assistant reply. The existing three-completed-turn retention window and replay-only cleanup remain intact.
The session-pruning documentation clarifies the user-turn boundary. Production code is +2/-4 lines; no new configuration, persistence, or provider-specific path is introduced.
User Impact
Recent image blocks and media references stay byte-identical throughout tool-loop requests. Cleanup still removes turn 1's processed media once turn 5 begins, preserving the documented retention window while avoiding this source of mid-turn cache invalidation.
Evidence
Before the fix, the new image and media-reference cases both failed at the retained-prefix byte comparison after a tool call/result; all 30 existing tests passed.
The regression also verifies retention after the final assistant reply, cleanup at the next user message, preservation of newer turns, and an unchanged source transcript. Existing cleanup fixtures now explicitly begin the next user turn; no assertions or snapshots were weakened.
Codex autoreview against the branch merge base, through P1:
scoped-clean, zero accepted/actionable findings. Final summary: "The change keeps the pruning cutoff stable throughout the active tool loop and advances it when a subsequent user turn begins. The updated tests cover this behavior for images and media references. No actionable P0 or P1 defects are evident in the supplied patch."Proof covers replay bytes and the setup boundary; live provider cache-hit metrics were not measured.
node scripts/check-changed.mjs: PASS (exit 0), including formatting, core and core-test typechecking, changed-file lint, dead-export scans, and all selected repository guards.git diff --check: PASS.The first CI run exposed two Gateway media-ownership fixtures that also needed the next user-turn boundary. Both now assert no pruning before that boundary and retain their original cleanup/ownership assertions afterward. The entire
src/gateway/server-methods/chat-send-user-turn.test.tsfile passed: 20 tests, 459.05s.That Gateway pass was the first phase of:
The redundant embedded phase then stalled before test execution (idle process, no worker/assertion output for ten minutes) and was terminated; the combined rerun exited 143. The earlier 51-test pass above covers the identical embedded source and tests. Fresh autoreview including the Gateway fixture changes is
scoped-clean, with zero accepted/actionable findings through P1.Final
node scripts/check-changed.mjsrerun including the Gateway fixture update: PASS (exit 0). Production LOC remains +2/-4; the additional Gateway proof is +4/-0.Final exact-head CI: GREEN, run 34079319344, head
90d6174cbacb698040dfd0aae940bbbaf3b745be. CI completed successfully with 108 successful jobs and 16 skipped jobs; the previously failingchecks-node-compact-large-3passed. The bounded PR watcher returnedGREENwith zero pending checks.