Repository navigation
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. What this changesThe Claude CLI output parser excludes duplicated Edit and Write file contents from its turn budget so repeated large-file edits can continue. Example: Claude edits a 109,890-character file.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful: current main still charges unused file echoes, and the merged partial-message fix does not address them. No actionable patch defect was found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherOpenClaw receives newline-separated JSON records from Claude Code and converts them into tool progress and agent replies. Its parser bounds individual records and cumulative turn output before delivering those events. flowchart LR
A[Claude Code output] --> B[Raw line limit]
B --> C[Remove duplicated file contents]
C --> D[Turn output budget]
D --> E[Tool progress and replies]
B --> F[Output limit error]
D --> F
Technical reviewBest possible solution: Keep the existing parser-owned normalization boundary and exclude unused file echoes while preserving tool delivery and raw line limits. Do we have a high-confidence way to reproduce the issue? Yes, source establishes a focused reproduction: repeated Edit/Write records carrying whole-file echoes exhaust main's 8 MiB cumulative budget. The contributor reports the added parser regression failing on main; this review did not execute it. Is this the best way to solve the issue? Yes. Extending the existing normalization owner removes unused duplicate contents without increasing global limits or changing the delivered tool result. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4ad94b56c5b1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +34, Tests +110. Total +144 across 2 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 HistoryReview history (1 earlier review cycle)
Reviewed October 9, 2026, 4:24 AM ET / 08:24 UTC (Revision 2). |
…CLI output budget Claude Code's Edit and Write tool results carry the whole pre-edit file (tool_use_result.originalFile), a structuredPatch that can span all of it, and Write's new content. The model only sees the short message tool_result and nothing in OpenClaw reads these echoes, but the stream-json parser charged them in full, so a few edits of a large file exhausted the 8 MiB per-turn budget. Drop them in the Claude record normalizer, like echoed image bytes. The raw per-line cap still applies before normalization.
f85b75d to
f5056d3
Compare
|
Thanks @Terwox for the precise diagnosis and the captured Claude Code shapes. Current main already fixes this budget problem: #166127 (8828c59, "keep Claude CLI replies after many large tool results") changed |
Closes #159929
Related: #150132, #153545, #159931, #119445
What Problem This Solves
Fixes: Claude CLI (
claude-cli) turns fail withCLI JSONL output exceeded 8388608 characters; refusing to parse output.when the agent edits large files a handful of times in one turn.User Impact
User impact: agents on the Claude CLI backend can edit and rewrite large files (hundreds of KB) repeatedly in one turn without spending the per-turn stream-json output budget on copies of those files.
Why This Change Was Made
For every Edit and Write, Claude Code's
userrecord carries the model-facingtool_resultmessage (a one-line "has been updated successfully" string) and atool_use_resultobject meant for SDK consumers. For Edit and Write, that object holds:originalFile: the whole file as it was before the edit.structuredPatch: a diff that can span the whole file.content: the new file.OpenClaw never reads
tool_use_result; the only reference is the existing normalizer that strips echoed image and PDF bytes (#119486, #128699). The stream-json parser still charged these copies in full against the 8 MiB turn budget. Editing an 800 KB file three times used roughly 2.4 MiB of budget on text the model never sees.This change drops those three fields in
normalizeClaudeCliStreamJsonRecord, in the same way that function already omits echoed binary data. Details:tool_use_result.originalFile,.structuredPatchand.content.tool_use_resulthas a stringfilePathand anoriginalFilekey; Edit, Write-update and Write-create all carry both. Othertool_use_resultshapes keep full accounting. That includes Read, whosefile.contentalso duplicates the tool_result; it is left for a separate change.filePath,oldString,newString,type,userModifiedand the model-facingmessage.contenttool_result. The tool result OpenClaw emits is unchanged.frameBoundedCliJsonlChunkchecks each raw line against 8 MiB before any parsing, so a single echo over 8 MiB still fails withCLI JSONL line exceeded …. Only the per-turn total stops counting the echoes.Overlap with #153545: none at the file level. #153545 changes partial-message delta accounting in
cli-output-stream.tsandcli-output-stream-limits.ts. This PR touches onlycli-output-echoed-binary.tsand adds tests incli-output-framing.test.ts. The two fixes are complementary: #153545 makes streamed text cheaper, and this PR makes Edit and Write results cheaper. The residualMath.max(normalized.line.length, rawLine.length - omittedRawChars)accounting in the parser is unchanged.Evidence
Real capture from Claude Code 2.1.281 (
claude -p … --output-format stream-json --verbose --permission-mode acceptEdits, working on a 109,890-character file). The numbers are characters charged by the parser before and after this change:On a Write update,
structuredPatchheld one hunk covering all 3,001 old lines, so a Write costs about twice the file size. The rest of the post-fix session total is Read results and ordinary output.Production failures. OpenClaw 2026.9.5, claude-cli backend, Opus, WSL2, overnight scheduled turns:
By the per-record sizes above, those edits alone charged about 4.8 MB and 4.2 MB of the 8 MiB budget. The rest of the budget went to
--include-partial-messagesdeltas, which #153545 addresses: about 6 MB and 11k lines by minute 130 in the Sep 27 turn.Both turns then stopped showing progress, and stuck-session recovery ended them about 15 minutes later (after 45.8 and 147.8 minutes) as
CLI run aborted, without logging the limit error. That silent stall is the failure mode in #143396, which #159931 addresses.Tests (
src/agents/cli-output-framing.test.ts, three new cases):CLI JSONL output exceeded 8388608 characters.tool_use_resultpayloads that are not file echoes (afilePathwith nooriginalFile) are still charged and still trip the budget.originalFileecho still trips the raw per-line cap.Commands run:
pnpm test src/agents/cli-output-framing.test.ts --maxWorkers=1: 24/24 pass in about 2.3 s wall time. The new cases take 122, 7 and 13 ms, so CI cost is well under 1 s in the existing shard.node scripts/check-changed.mjs(core and core-test lanes) passed: format, the ratchets,tsgo:core, the changed core-test typecheck shards, oxlint on the changed files, and the repo guards.Not captured: MultiEdit and NotebookEdit results. If their
tool_use_resulthas nooriginalFile, it keeps full accounting, which is today's behavior, so there is no regression either way.