Repository navigation
fix(cli): meter base64 image payloads as stubs in Claude live session turns - #119486
licheer-zte wants to merge 1 commit into
Conversation
… turns Photo-heavy turns (e.g. reading a folder of photos) trip the per-turn stream-json raw-chars cap (maxTurnRawChars, default 8 MiB) because full base64 image payloads inside tool_result content blocks are counted against the cap even though nothing downstream reads image source.data: the CLI backend already sent the images to the model API, and openclaw only consumes assistant text, tool status/ids, session id, and usage. Strip image source.data at ingest and use the stubbed serialization for rawChars accounting, the rawLines buffer, and the streaming parser, so a 9 MB photo turn meters at ~1.3 MB instead of aborting with a spurious "Claude CLI turn output exceeded limit" error. Text events are untouched. Refs openclaw#119445
723d607 to
f1ce51e
Compare
|
Codex review: needs real behavior proof before merge. Reviewed August 5, 2026, 9:31 AM ET / 13:31 UTC. ClawSweeper reviewWhat this changesThe PR replaces echoed base64 image data with stubs before Claude live-session buffering, parsing, and per-turn output-limit accounting. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 7 items remain Keep open: the photo-heavy turn failure remains plausible, but this branch still has an unfixed P1 scope error and only mock-based proof. Priority: P1 Review scores
Verification
How this fits togetherClaude CLI emits stream-json records to OpenClaw’s reusable live-session process. OpenClaw uses those records for turn limits, tool approval, tool events, transcript buffering, and the final agent response. flowchart LR
A[Claude CLI stream-json] --> B[Live-session line ingest]
B --> C[Record classification]
C --> D[Tool-result image payloads]
C --> E[Tool approval inputs]
D --> F[Bounded turn buffer]
F --> G[Streaming event parser]
E --> H[Claude control response]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +43, Tests +304. Total +347 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Stub only base64 payloads inside recognized Claude tool-result envelopes, preserve every other record byte-for-byte, and prove both the control-input preservation and a real photo-bearing turn. Do we have a high-confidence way to reproduce the issue? No high-confidence end-to-end reproduction is available here. Current main proves the raw accounting path and the PR supplies mock stream fixtures, but no real Claude CLI after-fix artifact is present. Is this the best way to solve the issue? No. Ingest-time normalization is the right owner boundary, but the recursive implementation is too broad; it must be constrained to recognized result envelopes and base64 sources. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 29175dd11e90. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
@clawsweeper re-review — the previous review lease expired without a completed review (placeholder comment from the last cycle). Please re-review this PR. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Thanks for working on #119445! This is now fixed on current main by #119488 (1352332). The merged implementation handles both base64 images and PDFs in the shared Claude JSONL and managed-session paths, preserves bounded output accounting and approval/control-request inputs, and passed 313 focused regression tests. It resolves the same photo-heavy-turn failure, so this PR is superseded. Closing in favor of the landed fix; thank you for the contribution. |
* fix(cli): image-heavy Claude CLI turns abort after about fifteen screenshots The Claude CLI emits every image tool result twice in its stream-json output: once inside `message.content[].tool_result.content[]` and once in the `tool_use_result` field it echoes alongside the message. The normalizer added in #119486 only walks the message copy, so the echoed copy still counts against the 8 MiB per-turn raw-output budget and is still retained in the live-turn line buffer. Walk the whole parsed user record instead, so both copies are stubbed, and cover the `tool_use_result.file.base64` shape the built-in image read echoes. openclaw never reads `tool_use_result` (no references in src), so nothing downstream changes. [AI-assisted] * fix(cli): make echoed-payload normalization stack-safe Addresses the review finding on the recursive walker. The normalizer now lives in its own module as one canonical entry point, walks the record iteratively with an explicit stack, and falls back to raw accounting when a record is too deeply nested for `JSON.stringify` to re-serialize. Adds a 50,000-deep regression record, built as text because `JSON.stringify` itself cannot serialize one that deep. [AI-assisted] * fix(cli): normalize Agent SDK REPL binary echoes --------- Co-authored-by: Vincent Koc <[email protected]>
* fix(cli): image-heavy Claude CLI turns abort after about fifteen screenshots The Claude CLI emits every image tool result twice in its stream-json output: once inside `message.content[].tool_result.content[]` and once in the `tool_use_result` field it echoes alongside the message. The normalizer added in openclaw#119486 only walks the message copy, so the echoed copy still counts against the 8 MiB per-turn raw-output budget and is still retained in the live-turn line buffer. Walk the whole parsed user record instead, so both copies are stubbed, and cover the `tool_use_result.file.base64` shape the built-in image read echoes. openclaw never reads `tool_use_result` (no references in src), so nothing downstream changes. [AI-assisted] * fix(cli): make echoed-payload normalization stack-safe Addresses the review finding on the recursive walker. The normalizer now lives in its own module as one canonical entry point, walks the record iteratively with an explicit stack, and falls back to raw accounting when a record is too deeply nested for `JSON.stringify` to re-serialize. Adds a 50,000-deep regression record, built as text because `JSON.stringify` itself cannot serialize one that deep. [AI-assisted] * fix(cli): normalize Agent SDK REPL binary echoes --------- Co-authored-by: Vincent Koc <[email protected]>
Fixes #119445
[AI-assisted]
What Problem This Solves
Photo-heavy CLI-backend turns abort with a spurious
Claude CLI turn output exceeded limiterror. The per-turn stream-json output cap (maxTurnRawChars, default 8 MiB, from #75838) meters the raw JSONL lines the CLI writes to stdout, and those lines embed full base64 photo payloads insidetool_resultcontent blocks. A modest "read a folder of photos" task (14 JPEG/PNG photos of 0.3–2 MB each) produces ~8.48 MB of stream volume — ~7.2 MB of it base64 image data — while the assistant text for the whole turn is ~2.7 KB. The run is aborted and the user sees "Something went wrong".Why This Change Was Made
openclaw never consumes image
source.datafrom the CLI stream: the CLI backend already sent the images to the model API (vision behavior is unaffected), and the live-session consumer only reads assistant text deltas, tool start/complete status + ids, session id, and usage. Nothing persists the payloads either — verified in the report against the agent/state SQLite stores. The image bytes' only effect is incrementing the raw-chars counter that kills the turn. The ClawSweeper review of this issue calls for normalizing echoed image tool-result blocks before retained aggregate accounting and parser input while preserving block type, tool state, MIME metadata, and decoded byte count — this change does exactly that:stripClaudeLiveImagePayloadswalks the parsed record recursively (image blocks appear intool_resultcontent arrays insideusermessage lines) and replaces eachsource.datawith[image: N base64 chars omitted], keeping the block type and MIME metadata intact.rawCharsaccounting, therawLinesbuffer, and the streaming parser; non-image lines are passed through byte-identical.maxPendingLineChars) still applies to the raw line as before.User Impact
Photo-heavy turns complete instead of aborting mid-turn. The reported 8.48 MB turn drops to ~1.3 MB (6× under the default cap), so the default 8 MiB limit stops being a cliff for bounded photo tasks. Tool result events keep their block structure and MIME metadata with the payload replaced by a byte-count stub — no model-visible or persistence behavior changes.
Evidence
src/agents/cli-runner/claude-live-session.ts(+46/−3):stripClaudeLiveImagePayloadshelper +meteredLinesubstituted fortrimmedinrawCharsaccounting,rawLinesbuffering, andstreamingParser.push.src/agents/cli-runner/claude-live-session.image-payload.test.ts(2 tests):tool_resultlines carrying 3 MiB of base64 each (9 MiB total > 8 MiB cap) complete the turn successfully.onToolResultreceives[image: 1048576 base64 chars omitted]rather than the raw base64.2 failed); with it, both pass.claude-live-session.background-tasks,claude-live-session.capability,claude-live-tool-approval— 48/48 pass undervitest.agents-support.config.ts.oxlintandoxfmtclean on changed files;tsgotypecheck clean for both changed files (only pre-existing unrelatedrejectSymlinksdrift errors remain on this checkout).