Repository navigation
fix(code-mode): keep truncation counts tied to original output - #132850
Conversation
Retain bounded original normalized JSON through worker legs and headless execution instead of truncating earlier markers. Preserve accepted output on later failures and share the output budget with terminal diagnostics. Fixes #132575.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 5:16 PM ET / 21:16 UTC. ClawSweeper reviewWhat this changesThe PR replaces repeated public truncation projections with retained normalized JSON source so Code Mode reports correct prefixes and omitted-byte counts across exec, wait, and headless runs. Regression provenancePossible regression — probable (reproduction; reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep open. This is a focused repair for a current Code Mode regression; the new single output-state owner preserves source provenance across worker legs without a blocking correctness or security finding. Priority: P1 Review scores
Verification
How this fits togetherCode Mode runs guest JavaScript in a QuickJS worker and returns incremental output through exec and wait controls. Worker-leg output is accumulated by the host before becoming model-visible tool results. flowchart LR
A[Guest Code Mode program] --> B[QuickJS worker]
B --> C[Bounded normalized output source]
C --> D[Cumulative output state]
D --> E[Exec or wait result]
E --> F[Model-visible output and value]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +32, Tests +343, Docs +6. Total +381 across 20 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. Technical reviewBest possible solution: Retain the single cumulative source-and-delivery owner, with the new interactive and headless regression cases guarding original-prefix accounting before normal exact-head merge gates complete. Do we have a high-confidence way to reproduce the issue? Yes, at source level: the linked issue supplies a concrete exec/wait and headless scenario, and the branch adds direct regression coverage, though this read-only review did not execute it. Is this the best way to solve the issue? Yes. Retaining normalized source at the worker boundary and projecting only at the cumulative delivery owner fixes the repeated-projection invariant rather than compensating after a marker is already emitted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d3c07b02e244. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Pre-merge verification for Exact-head CI run 33275339573, attempt 1, completed successfully. The earlier draft-skipped run is not counted as proof. The repository CI watcher finished The repair keeps original normalized JSON at the worker boundary and one cumulative source/delivery owner through exec, wait, and headless execution, rather than truncating an already-public marker. The existing byte cap and successful partial-result semantics remain. Production is +216/−217 (net −1); tests and test support are net +376, docs net +6. Verification already recorded in the PR's Evidence section: 1,009 tests across 37 files on Node 26.8.1; 171 focused tests passed again after exact candidate restoration; the preserved pre-fix corpus produced 12 intended failures. Candidate and controlled-baseline builds passed on Node 26.8.1. Changed gates, lint, and type graphs passed on Node 26.7.0, not relabeled as newer-runtime proof. Fresh post-proof Codex autoreview found no actionable P0 issues; its scope was P0-only and the reviewer did not run tests. Key local entrypoints (the PR body contains the full 37-file selection, isolated-wrapper conditions, and other exact commands): node scripts/run-vitest.mjs src/agents/code-mode.output.test.ts src/agents/code-mode.limits.test.ts src/agents/code-mode.rejections.test.ts src/agents/code-mode-runtime.test.ts src/agents/code-mode.test.tsnode scripts/run-vitest.mjs src/agents/code-mode.limits.test.ts src/agents/code-mode-headless.test.ts -t 'bounds cumulative original|preserves accepted inline|shares the output budget|bounds original output'The second command is the intentionally failing preserved pre-fix run, not a candidate failure. pnpm buildReal compiled Gateway/QuickJS and normal Control UI before/after proof establishes the original 1 KiB defect and its repair: before, the prefix was not original and reported 153 omitted bytes instead of 223; after, the prefix is original and reports exactly 197 omitted bytes. The additional default-dense after-case reaches the unchanged 65,536-byte shared cap and reports exactly 6,645 omitted bytes. Actual provider/history/full-message bytes agree, with one exec and one wait per measured case. This is deterministic AIMock proof, not an authenticated provider or uncoached model. Inspected screenshots and recordings are attached above. ClawSweeper's latest review identifies no actionable defect and asks for the normal exact-head checks. Those are green. Its stored-data-model heuristic does not identify a persistent migration here: The documented gaps remain: the original accented-character default case is still clipped by the separate generic 32,000-weighted-unit context guard; the Euro fixture does not claim to fix that composition. Large-case Gateway before-proof was blocked by startup/UI admission failures, with no guard bypass or indefinite retries. Complete real before/after proof is the original small case; default-limit owner regressions and large after-proof are separate evidence. The context-envelope contract is a named follow-up, not part of this repair. |
|
Merged via squash.
|
…law#132850) Retain bounded original normalized JSON through worker legs and headless execution instead of truncating earlier markers. Preserve accepted output on later failures and share the output budget with terminal diagnostics. Fixes openclaw#132575.
Closes #132575 — Code Mode truncation lost original output provenance.
AI-assisted maintainer repair. Maintainers can push to this organization-owned branch.
What Problem This Solves
Fixes an issue where Code Mode runs emitting large output across
exec/waitor headless bridge steps could receive a truncation of an earlier marker instead of their original output. The cell could complete successfully and respect its byte cap while returning the wrongprefixandomittedBytes. Final-value allocation had the same repeated-projection problem.The same output ownership also lost already-accepted output on later host failures and allowed abort/restart diagnostics to exceed the shared output budget.
Why This Change Was Made
The existing JSON owner now retains bounded original normalized JSON and its original byte size, with one cumulative output state and delivery receipt across worker legs. Workers transfer bounded source rather than public markers; interactive and headless paths append each disjoint leg once and project only when returning results, removing the destructive re-bounding and delivered-array reset/slice paths.
This preserves the successful-partial-result behavior of the earlier bounded-output repair, authored and merged by @steipete on 2026-08-13, while fixing its repeated-projection structure. Stable-release reachability was not established; the reproduction and comparison are source-checkout evidence.
User Impact
Code Mode's own truncation reports an actual prefix of the original normalized JSON and a matching omitted-byte count across waits, final-value allocation, and headless execution. Accepted output survives later failures; terminal diagnostics share the existing byte budget. Ordinary output remains incremental, identical cumulative summaries are suppressed, and changed totals or final reservations can produce replacement summaries rather than new guest executions.
Successful partial results stay successful. Cancellation, approval/replay authority, conversion semantics, existing byte caps, and generic model-context guards are unchanged. No new configuration, schema, storage, dependency, or compatibility path. Retained source is bounded to one byte budget per output/value channel; this is not a whole-message, snapshot, or process-RSS bound.
Evidence
Real Gateway and Control UI
The normal New Session → Start flow created the session through the UI's actual
sessions.create, then drove the compiled Gateway and real QuickJS worker. Actual provider-bound calls/results, exact arguments, oneexec/onewait, Responses ID normalization, publicchat.history, andchat.message.getwere checked independently. The normal tool-details panel was opened and its parsed result compared too.This uses deterministic AIMock, not an authenticated provider or an uncoached model. Node 26.8.1, QuickJS-WASI 3.5.0, AIMock 1.39.0, and Playwright 1.62.1. Each successful case has three target requests, one session-title request, and the observed number of embedding requests; final accounting happens after the Gateway, mock, and callbacks settle. No auth/SSRF bypass, generic-result-guard override, app-state injection, or operator service/state was used.
All three measured cells completed with
value: true. Provider, history, and full-message text matched byte for byte in each measured case. The default-dense case has no output-limit override: 9,000 lobster characters and 12,000 Euro symbols across a yield. Its full formatted result was 65,944 UTF-8 bytes / 28,372 UTF-16 units, fitting the unchanged general text guard. The original small program is unchanged from the issue.Before:
After:
Default byte budget, additional after-proof:
Inspected before/after recordings
Before:
code-mode-output-before.mp4
After:
code-mode-output-after.mp4
The final seconds show intentional teardown of the isolated Gateway. Every original screenshot and recording was inspected; the MP4 conversions were also inspected. A viewport is not proof of every output byte—the provider/public-API comparisons and independent arithmetic supply that proof.
Regression and source binding
The live candidate was built from
6b27585471a7c0133fbdb7b43830f0366e0e417bplus the uncommitted repair. All 20 committed file contents were verified byte-identical to that frozen candidate inf273b0a5f67fe34448e87a8d257affad42f61a54; build metadata is not relabeled. The controlled baseline restored only the ten production owners, retaining candidate tests/docs. All 12,129 archived candidate distribution files were checked during restoration. All runs recorded source/dependency identity and cleaned their owned processes and temporary state.Local validation commands
The repository entrypoints below ran through task-owned isolated HOME/state/config/temp wrappers, with an explicit Node pin,
CI=1, one Vitest worker, and disabled Vitest filesystem/tsx caches. Checks used pnpm's existing copy import mode for disposable tooling. No repository dependency/configuration was changed for this.Full selected family (Node 26.8.1, passed):
Restored candidate sanity (Node 26.8.1, passed):
Preserved pre-fix corpus (Node 26.8.1, expected 12 failures):
node scripts/run-vitest.mjs src/agents/code-mode.limits.test.ts src/agents/code-mode-headless.test.ts -t 'bounds cumulative original|preserves accepted inline|shares the output budget|bounds original output'Full changed gate (Node 26.7.0, passed):
Final targeted lint (Node 26.7.0, passed):
Final test type graph (Node 26.7.0, passed):
Candidate and controlled baseline builds (Node 26.8.1, passed):
Explicit limitations and follow-up
The issue's original default-budget accented-character input also crosses the existing 32,000 weighted-text-unit guard at 128k model context. Its provider-facing wait text was not JSON, so that fixture failed before certifying provenance. The new Euro-symbol default-dense case is additional byte-invariant isolation, not a pass for that original composition case. General text clipping remains enabled and unchanged. A separate follow-up assesses whether Code Mode needs a negotiated, parseable-envelope contract at that boundary; this PR does not claim to solve it or infer lost status/value from invalid JSON.
The large-case Gateway before measurement was not completed: one baseline attempt never reached listening, and the one fresh attempt hit the normal UI's Gateway-changed protection during the already-proven small case. Neither guard was bypassed. Thus complete real before/after proof is the original 1 KiB case; default-budget owner-level failing/passing regressions and large-case after-proof are reported separately. Earlier collector-assumption failures and both baseline failures were retained rather than presented as passes.
Test counts include moved coverage from the prior wait/headless suites. Proof media, generated builds, and local drivers are not committed. CI on the published head will be recorded before native prepare/merge.