Repository navigation
Conversation
Advance historical image cleanup eight completed turns at a time after the initial cut, preserving recent turns and deterministic restart replay. The live synthetic replay raises cache-read share from 47.35% to 88.66% and reduces cache-read drops from 25 to 4. Retained image context is bounded to 3-10 completed turns; compaction and overflow recovery still own capacity. Regression, 206 sibling files / 2621 tests, and independent review pass. Changed checks pass except four dead exports reproduced on clean main.
|
🦞👀 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. What this changesThe branch batches historical image cleanup every eight completed turns after the initial cut, preserving replay prefixes between batches. Example: The user continues an image conversation through 28 completed turns.
Review scores
ProductKind: Performance · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains useful: current main still advances image cleanup every completed turn, and the proposed batching has measured cache benefits with no concrete blocking defect found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe agent prepares a replay view of conversation history before sending it to the model. Image cleanup replaces older image payloads and attachment references in that view while preserving the original transcript. flowchart TD
A[Original conversation history] --> B[Count completed turns]
B --> C[Determine batched cleanup boundary]
C --> D[Replace older images and references]
D --> E[Hydrate retained media]
E --> F[Model request]
F --> G[Compaction and overflow recovery]
Technical reviewBest possible solution: Keep deterministic batching in the shared replay owner, preserve canonical transcripts, and leave total context capacity to existing compaction and overflow recovery. Do we have a high-confidence way to reproduce the issue? Not applicable as a performance proposal; source establishes the existing per-turn cutoff, and supplied before/after provider usage demonstrates its cache impact. Is this the best way to solve the issue? Yes. The change adjusts the existing shared owner without adding configuration or persisted state, and the area owner explicitly accepts the measured context-retention tradeoff. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fd2fa6b904a2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -10, Tests +28, Docs 0. Total +18 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 9, 2026, 12:49 AM ET / 04:49 UTC. |
…penclaw#167613) Advance historical image cleanup eight completed turns at a time after the initial cut, preserving recent turns and deterministic restart replay. The live synthetic replay raises cache-read share from 47.35% to 88.66% and reduces cache-read drops from 25 to 4. Retained image context is bounded to 3-10 completed turns; compaction and overflow recovery still own capacity. Regression, 206 sibling files / 2621 tests, and independent review pass. Changed checks pass except four dead exports reproduced on clean main.
What Problem This Solves
Historical image cleanup changes a previously sent tool result or user message on every completed follow-up turn, breaking reuse of the later prompt prefix.
User Impact
Long image/tool sessions preserve prior request bytes between cleanup batches. The newest three completed turns remain intact; up to ten completed turns are retained between cuts. This trades a bounded increase in retained image context for fewer cache invalidations. Image-heavy sessions can reach compaction pressure sooner. Normal compaction and provider-overflow recovery continue to own the total context limit.
Why This Change Was Made
The existing image-projection owner now derives one cutoff from completed canonical turns: the initial cleanup stays at four completed turns, and subsequent cutoffs advance eight turns at a time. Tool loops never advance it. Restart derives the same bytes without another cache, stored shape, or configuration option. Original transcript images remain untouched. Aggregate tool-result projections and cache-TTL soft/hard pruning already persist their decisions on current main; their owners remain in place and their regression suites were included in this lane.
Production LOC: +18/-28, net -10 (
git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*').Evidence
Blacksmith Testbox (
blacksmith-testbox, profileopenclaw-check), leasetbx_01m4fc2h6fp3dqsmm902rvea3z:node scripts/run-vitest.mjs … --maxWorkers=1, 48.03 seconds across three Vitest shards). Neighboring projection persistence, context guards, preflight, overflow recovery, and Gateway attachment ownership: five files / 64 tests pass, 42.19 seconds.The changed gate passed its production and all 27 test typecheck graphs, format checks, and structural guards. Its only failure was the dead-export scan. A clean checkout of main
62355575c041dee0491658d4d1bc024d9fb3fc6breproduced the same four production findings (bindCliQuestionAnswerAuthority,prepareSessionEventTargetForHost,readSessionEntryCreationTransition, andRESTART_CONTINUATION_CONTEXT_PREFIX), with the same latter two full-tree findings. These exports are outside this diff. Candidate gate: 23m13s; clean-main baseline scan workflow: 1m30s. No skip or baseline exception was added.Full sibling directory:
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run— 206 files / 2621 tests pass, 332.53s wrapper wall time (338.11s remote command). The lease was stopped after proof.Independent review: scoped-clean at P0–P2. Live provider replay:
gpt-5.6-luna, Responses SSE, identical synthetic histories, distinct stable cache series, 1,024-token response budget, 57 requests before + 57 after, zero failures. Provider-reported cache reads 377,664 → 705,747 tokens (1.87×); cache-read share 47.35% → 88.66%; cache writes 419,605 → 90,010 tokens; cache-read drops 25 → 4, summing 368,525 → 58,775 dropped cached tokens. Peak provider-reported prompt size was 27,458 tokens. The initial 32-token-budget probe was discarded after missing usage on an incomplete response; the complete comparison used a fresh cache series. Wall time was 83.2 → 138.3 seconds; the candidate includes one 61.0s request (median request time 1.355 → 1.213s), so this PR claims cache reuse/cost improvement, not lower live latency.pnpm test src/agents/embedded-agent-runner/run/history-image-prune.behavior.test.ts --maxWorkers=1: 10 tests pass; 7.54s wrapper wall time / 5.97s Vitest wall time; new regression body 11ms. No new test file, worker pin, timer, process fixture, or production export was introduced.Provider-reported cache reads for every replay request
Remote proof commands (same Testbox lease)
Replay fixture: 28 user turns, each invoking one synthetic diagnostic tool with 5,000 characters of text and a tiny PNG, followed by one tool-free turn. The real Agent dispatch uses the production image transform, tool-result context guard, and final truncation projection; per-result cap 8,000 chars, aggregate cap 80,000 chars, context window 128,000 tokens and reserve 8,000 tokens. Original transcript messages are preserved. Cache-TTL restart/soft/hard behavior is covered separately by the existing owner tests.