Skip to content

fix(code-mode): preserve file pages and handled error details - #140689

Merged
roboclaw-bot merged 6 commits into
mainfrom
openclaw/quickjs-code-mode-status
Sep 7, 2026
Merged

roboclaw-bot merged 6 commits into
mainfrom
openclaw/quickjs-code-mode-status

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Resolves a problem where agents using Code Mode could not reliably parse paginated files or inspect handled tool failures. File text was mixed with display-only notices, some partial reads looked complete, and caught Error values lost their actionable messages.

Why This Change Was Made

Keep structured file data separate from human-readable display text, carry continuation metadata through explicit limits and tighter read budgets, and normalize handled Errors before output serialization. Blank pages use the same page owner. Both displayed and structured content remain budgeted, and existing .env redaction is preserved on both channels.

This changes OpenClaw’s implementation, not model-specific prompts or provider policies. It adds no configuration, dependencies, storage schema, or permission changes.

User Impact

  • Reassemble file pages without stripping human-readable notices with regex.
  • Follow machine-readable continuations rather than treating a partial requested slice as EOF.
  • See Error names/messages and JSON-compatible custom fields in emitted and returned results, including Promise.allSettled reasons; Error-specific toJSON methods cannot hide the diagnostic.
  • Retain existing display guidance, image behavior, redaction, and execution limits.

Evidence

  • 151 original focused cases passed, plus three explicit-limit cases added for the ClawSweeper follow-up (0, -1, and the fractional control 0.5). The 0/-1 cases failed before the fix; all 110 read/contract/wrapper cases rerun for that fix passed.
  • Actual filesystem → Code Mode → QuickJS coverage for line/cursor pagination, explicit limits, blank pages, and continuation preservation under tighter budgets.
  • Handled-error coverage through exec, wait, and headless execution, including a custom toJSON case.
  • Targeted lint, MDX validation, whitespace checks, and production bundle build.
  • Live acceptance used K3 and GLM 5.2 as test clients with isolated state and the candidate core plus installed provider plugins. Tasks parse a large JSON file, compute its record count and sum, write/read back a result, and recover from a missing file. Written results are checked against an independently generated oracle.

Live acceptance for the main Code Mode repair (before the small normalized-limit follow-up):

Model route Result Assistant turns Failed tool calls Independent file oracle
kimi/k3 Passed, Code Mode engaged 4 0 Exact match; source data unchanged
zai/glm-5.2 Passed, Code Mode engaged 4 0 Exact match; source data unchanged

These are bounded functional trials, not a general model benchmark. Fresh independent review was scoped-clean at P0–P2 after all actionable findings were repaired.

Focused reproduction commands:

node scripts/run-vitest.mjs src/agents/code-mode.rejections.test.ts src/agents/code-mode.guest.test.ts src/agents/filesystem-tools-output-contract.test.ts src/agents/sessions/tools/read.test.ts
node scripts/run-vitest.mjs src/agents/agent-tools.create-openclaw-coding-tools.test.ts -t read

Hosted validation and resolved review findings

Final head 9294da3f54abc15ad64597f361deb6e84f6c2946 passed full hosted CI, including production/test typechecks and the required openclaw/ci-gate: https://github.com/openclaw/openclaw/actions/runs/34082597388. ClawSweeper reviewed this exact head, confirmed both previous findings resolved, and reported no actionable defects: #140689 (comment).

  • Explicit numeric limits use the native normalization helper; real-file cases cover 0, -1, and 0.5.
  • The integration preserves main’s allocation-free reader scan. Both bounded output channels are detached independently of EOF so small partial-file results do not retain large decoded source backing.
  • Three real-reader GC cases (line/range/cursor, including lone-surrogate content) failed before the retention fix with 16,777,256 external bytes retained. All pass after; a separate fixed line measurement reports 72,880 heap bytes and 40 external bytes of growth. All 85 retention-follow-up cases, targeted lint, and fresh P0–P2 autoreview passed. A type-only fixture correction resolved the intermediate TS7022 CI failure.

Live model trials predate the small follow-ups; those follow-ups have direct regression proof plus final-head CI. Local full typechecking was blocked by pnpm bootstrap age policy and the shared-dependency guard; hosted CI supplied that proof without weakening either guard.

Worked on by:


View the OpenClaw team session

Worked on by:
- @Takhoffman

Co-authored-by: Takhoffman <[email protected]>
OpenClaw-Publication: 8a1fbeb6-e538-4431-b9f2-e0d6470f3069
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 12:24 AM ET / 04:24 UTC.

ClawSweeper review

What this changes

The PR separates structured file contents from display notices, preserves pagination continuations and handled error details, and prevents small read results from retaining large file buffers.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still mixes pagination notices into structured file results and loses handled error details. Both previous findings are resolved in the reviewed head, and no remaining blocking defect was found.

Priority: P2
Reviewed head: 9294da3f54abc15ad64597f361deb6e84f6c2946

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful behavior evidence and regression coverage; both prior blockers are resolved.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body records isolated agent runs through the candidate Code Mode file-reading path with exact independent-oracle matches and missing-file recovery; subsequent normalization and retention fixes have focused before/after regression evidence. These observations were supplied by the contributor and were not rerun by this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body records isolated agent runs through the candidate Code Mode file-reading path with exact independent-oracle matches and missing-file recovery; subsequent normalization and retention fixes have focused before/after regression evidence. These observations were supplied by the contributor and were not rerun by this reviewer.
Evidence reviewed 9 items Current main still needs the repair: At the fetched main revision, complete selected pages return kind=text with the pagination notice embedded in content; the guest serializer also leaves ordinary Error objects unprojected. These are the central behaviors repaired by this branch.
Latest release retains the older page contract: Inspection of the supplied latest release revision, v2026.9.2, shows the same text result containing the pagination notice. The requested file-page repair is not already supplied by that release.
Prior retention finding resolved: Both display text and structured file content are now copied as UTF-16 whenever text details exist, independently of whether the page is complete or truncated. The three new retention cases measure memory before inspecting strings and independently check line, range, cursor, and lone-surrogate content.
Findings None None.
Security None None.

How this fits together

OpenClaw Code Mode runs agent-written JavaScript in QuickJS and exposes existing tools through structured results. The file reader supplies bounded pages, while the guest output serializer returns values and diagnostics to the agent.

flowchart LR
  A[Agent JavaScript] --> B[Code Mode guest]
  B --> C[File read tool]
  C --> D[Bounded file page]
  D --> E[File content and continuation]
  D --> F[Human-readable display]
  E --> B
  B --> G[Serialized values and errors]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +81, Tests +307, Docs +18. Total +406 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 5 178 97 +81
Tests 6 310 3 +307
Docs 1 18 0 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 506 100 +406

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +81 lines; tests and support net +307 lines Production growth supports separate bounded output channels and error projection; regression coverage exercises pagination, normalization, redaction, and retained memory.

Technical review

Best possible solution:

Keep file-page ownership in the native reader and handled-error projection in the guest serializer, preserving explicit limits, bounded memory, and redaction.

Do we have a high-confidence way to reproduce the issue?

Yes, source inspection establishes the failure paths: current-main file pages embed display notices in structured content, and JSON serialization loses ordinary Error messages. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes. The patch repairs the existing page and serialization owners, and the latest changes address both previously identified regressions without adding configuration or a competing implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 608b9ba2437d.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body records isolated agent runs through the candidate Code Mode file-reading path with exact independent-oracle matches and missing-file recovery; subsequent normalization and retention fixes have focused before/after regression evidence. These observations were supplied by the contributor and were not rerun by this reviewer.

Label justifications:

  • P2: This repairs bounded file-processing and diagnostic failures in Code Mode without evidence of an urgent widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body records isolated agent runs through the candidate Code Mode file-reading path with exact independent-oracle matches and missing-file recovery; subsequent normalization and retention fixes have focused before/after regression evidence. These observations were supplied by the contributor and were not rerun by this reviewer.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body records isolated agent runs through the candidate Code Mode file-reading path with exact independent-oracle matches and missing-file recovery; subsequent normalization and retention fixes have focused before/after regression evidence. These observations were supplied by the contributor and were not rerun by this reviewer.

Evidence

What I checked:

  • Current main still needs the repair: At the fetched main revision, complete selected pages return kind=text with the pagination notice embedded in content; the guest serializer also leaves ordinary Error objects unprojected. These are the central behaviors repaired by this branch. (src/agents/sessions/tools/read-page.ts:61, 608b9ba2437d)
  • Latest release retains the older page contract: Inspection of the supplied latest release revision, v2026.9.2, shows the same text result containing the pagination notice. The requested file-page repair is not already supplied by that release. (src/agents/sessions/tools/read-page.ts:61, 3928bad9badf)
  • Prior retention finding resolved: Both display text and structured file content are now copied as UTF-16 whenever text details exist, independently of whether the page is complete or truncated. The three new retention cases measure memory before inspecting strings and independently check line, range, cursor, and lone-surrogate content. (src/agents/sessions/tools/read.ts:603, 9294da3f54ab)
  • Earlier explicit-limit finding remains resolved: The adaptive wrapper treats numeric limit presence as explicit and uses the native normalization helper. Added real-file cases cover limits 0, -1, and 0.5 without automatic paging. (src/agents/agent-tools.read.ts:326, 9294da3f54ab)
  • Error projection and redaction: The guest projects Error names, messages, and enumerable fields before serialization, omitting Error-specific toJSON methods. The read wrapper redacts the complete result so structured file content receives the existing .env protection too. (src/agents/code-mode-controller-source.ts:271, 9294da3f54ab)
  • Independent implementation boundary: The documentation identifies OpenClaw Code Mode as its own QuickJS-WASI implementation. The changed controller and reader do not depend on the Codex harness contract, so sibling Codex inspection is not applicable. Public docs: docs/tools/code-mode.md. (docs/tools/code-mode.md:25, 9294da3f54ab)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-07T03:07:35.120Z sha 124be94 :: blocked before merge. :: none
  • reviewed 2026-09-07T03:27:22.240Z sha ba3dba8 :: needs changes before merge. :: [P2] Honor normalized explicit limits before following continuations
  • reviewed 2026-09-07T03:53:59.625Z sha a5c24bf :: needs maintainer review before merge. :: none
  • reviewed 2026-09-07T04:02:01.459Z sha 039131f :: blocked before merge. :: [P2] [P2] Detach full-fit partial-file pages before returning them

Restore the pre-publication Android wrapper blob so this PR remains scoped to Code Mode file and error handling.

Co-authored-by: Tak Hoffman <[email protected]>
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 7, 2026 03:20
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed app: android App: android size: L labels Sep 7, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
Use the native reader limit normalization in the adaptive wrapper so zero and negative limits remain one-line reads instead of permitting automatic pagination.

Worked on by:
- @Takhoffman

Co-authored-by: Takhoffman <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Addressed the normalized explicit-limit finding in a5c24bf. The wrapper now uses the native reader’s normalization before deciding whether to auto-page. The limit: 0 and limit: -1 regressions failed before the fix; both and the fractional control now pass. All 110 affected read/contract/wrapper cases and targeted lint pass; fresh P0–P2 autoreview is scoped-clean.

The previous head’s full CI/typechecks passed in https://github.com/openclaw/openclaw/actions/runs/34079303018. I will not use that run as proof for the new head; fresh CI is running. The PR body now records the fix and validation accurately.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 7, 2026
Preserve main's allocation-free line scanning and bounded UTF-16 copies while keeping structured file data separate from display notices and retaining partial-page continuation metadata.

Worked on by:
- @Takhoffman

Co-authored-by: Takhoffman <[email protected]>
Detach both bounded text channels independently of EOF classification so small explicit pages cannot retain the decoded source file. Preserve UTF-16 code units and continuation metadata. Add real-reader GC regressions for line, range, and cursor selections.

Worked on by:
- @Takhoffman

Co-authored-by: Takhoffman <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Fixed the integrated reader retention finding in 634061a3850f5e960b275cf91ebad825b9ed40ae. Both bounded output channels are now detached independently of EOF/truncated classification, preserving exact UTF-16 code units.

Added real-reader GC regression cases for explicit line, multi-line range, and cursor selections. All three failed before the fix: eight small retained results kept 16,777,256 bytes of external backing. After the fix all three pass; a separate line measurement reports 72,880 bytes heap growth and 40 bytes external growth. Assertions run only after GC so inspecting returned strings cannot hide retention. Content (including lone surrogates) and continuation metadata are also verified.

Current proof: 3 retained-memory cases + 55 native reader + 27 filesystem/Code Mode contract tests passed; targeted lint and fresh P0–P2 autoreview are clean. The preceding integration head passed full CI run 34081289327; new exact-head CI is required for this fix.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Annotate the independently constructed string expectation so the production typecheck does not encounter circular assertion inference. Runtime behavior and memory assertions are unchanged.

Worked on by:
- @Takhoffman

Co-authored-by: Takhoffman <[email protected]>
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 7, 2026
@roboclaw-bot
roboclaw-bot merged commit 4394672 into main Sep 7, 2026
187 of 188 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/quickjs-code-mode-status branch September 7, 2026 04:35
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…aw#140689)

Preserve structured file pages and continuation metadata for Code Mode, independently bound file data and display output, retain actionable handled-error diagnostics before serialization, and honor normalized explicit read limits. Preserve existing redaction and execution controls.

Worked on by:
- @Takhoffman

Co-authored-by: Takhoffman <[email protected]>
Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant