Skip to content

fix: keep recursive Code Mode cells recoverable - #141960

Merged
vincentkoc merged 1 commit into
mainfrom
fix/quickjs-stack-limit-20260908
Sep 8, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/quickjs-stack-limit-20260908

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where recursively authored Code Mode cells could trap the QuickJS WASM runtime with memory access out of bounds instead of returning a normal failed-cell result.

Why This Change Was Made

Pass the quickjs-wasi exported MAX_STACK_SIZE into the canonical VM options shared by fresh creation and snapshot restoration. This keeps both execution paths on the dependency's supported recursion bound.

User Impact

Recursive guest code now fails visibly with RangeError: Maximum call stack size exceeded, allowing the normal Code Mode recovery loop to continue instead of surfacing a low-level WASM trap.

Evidence

  • pre-fix fresh-exec and resumed-snapshot cases both failed with WebAssembly.RuntimeError: memory access out of bounds
  • post-fix lifecycle suite: 24/24 passed, including both recursion cases
  • changed-file lint, typecheck, dead-code, formatting, and repository guards passed on the implementation base
  • exact-head GitHub CI will rerun the clean checkout because the shared local worktree install currently has a stale Vitest 4/5 mismatch
  • production delta: +9/-1; regression tests: +50

Punchcard-Session: amber-brook-orchard-d1
@vincentkoc vincentkoc self-assigned this Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 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 the agents Agent runtime and tooling label Sep 8, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review September 8, 2026 07:10
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 8, 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 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 3:18 AM ET / 07:18 UTC.

ClawSweeper review

What this changes

Bounds recursive Code Mode execution so fresh and restored cells return a readable stack-overflow error instead of trapping the WebAssembly runtime.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a focused, useful repair that current main still lacks. No introduced correctness or security defect was found; the maintainer-authored PR is also protected from automatic closure.

Priority: P2
Reviewed head: be8fe4829f7f0f7a9059d3db3160c6f32f44fc1f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and a verified dependency contract; no blocking defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate, and no authority change triggers additional proof. Reported before/after worker results and the fresh/restored recursion tests support the repair; no live execution was performed in this review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate, and no authority change triggers additional proof. Reported before/after worker results and the fresh/restored recursion tests support the repair; no live execution was performed in this review.
Evidence reviewed 8 items Verified introduced repair: The pinned base-to-head diff adds MAX_STACK_SIZE to the existing shared VM options. Both QuickJS.create and QuickJS.restore consume those options; no dependency version, tool authorization, or persistent format changes.
Published dependency contract: npm metadata identifies vercel-labs/quickjs-wasi as the source repository. Inspection of the published 3.6.0 package found MAX_STACK_SIZE = 512 * 1024, documented headroom within the shipped binary’s 1 MiB stack, validation of the option, and application through qjs_set_max_stack_size. Both create and restore apply these limits. Package SHA-1: ffe3dc9ab5952b0a5e26e6356221639bfd56acd2.
Current main still lacks the bound: Fetched main’s canonical VM options omit maxStackSize. The direct quickjs-wasi import establishes the relevant dependency contract.
Findings None None.
Security None None.

How this fits together

OpenClaw Code Mode executes model-written JavaScript in an isolated QuickJS worker. The worker handles fresh cells and restored snapshots, returning results or errors to the host’s tool execution and recovery flow.

flowchart TD
  A[Model-written cell] --> C[Shared VM options]
  B[Suspended cell snapshot] --> C
  C --> D[QuickJS worker with stack bound]
  D --> E[Completed or suspended result]
  D --> F[Guest stack-overflow error]
  F --> G[Host failed-cell recovery]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +50. Total +58 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 1 50 0 +50
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 59 1 +58

Review metrics

None.

Technical review

Best possible solution:

Keep the dependency-supported stack bound in the canonical VM constructor so recursive cells fail through the existing guest-error and cleanup flow.

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

Yes: infinite recursion before or after yield_control provides a concrete worker-level reproduction path, supported by the missing main-branch stack bound and reported pre-fix failures; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: setting the dependency’s supported limit once covers fresh and restored VMs without adding a competing recovery mechanism or user configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 44b52287ff38.

Labels

Label changes:

  • add P2: Repairs a bounded Code Mode failure triggered by recursive guest code, with no evidence of a wider runtime outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate, and no authority change triggers additional proof. Reported before/after worker results and the fresh/restored recursion tests support the repair; no live execution was performed in this review.

Label justifications:

  • P2: Repairs a bounded Code Mode failure triggered by recursive guest code, with no evidence of a wider runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from the external contributor proof gate, and no authority change triggers additional proof. Reported before/after worker results and the fresh/restored recursion tests support the repair; no live execution was performed in this review.

Evidence

What I checked:

  • Verified introduced repair: The pinned base-to-head diff adds MAX_STACK_SIZE to the existing shared VM options. Both QuickJS.create and QuickJS.restore consume those options; no dependency version, tool authorization, or persistent format changes. (src/agents/code-mode.worker.ts:207, be8fe4829f7f)
  • Published dependency contract: npm metadata identifies vercel-labs/quickjs-wasi as the source repository. Inspection of the published 3.6.0 package found MAX_STACK_SIZE = 512 * 1024, documented headroom within the shipped binary’s 1 MiB stack, validation of the option, and application through qjs_set_max_stack_size. Both create and restore apply these limits. Package SHA-1: ffe3dc9ab5952b0a5e26e6356221639bfd56acd2.
  • Current main still lacks the bound: Fetched main’s canonical VM options omit maxStackSize. The direct quickjs-wasi import establishes the relevant dependency contract. (src/agents/code-mode.worker.ts:194, 44b52287ff38)
  • Latest release comparison: The supplied latest release, v2026.9.2, also omits maxStackSize from the options used for fresh and restored VMs; no shipped equivalent was established. (src/agents/code-mode.worker.ts:176, 3928bad9badf)
  • Regression coverage and reported validation: The added parameterized test runs infinite recursion through the production worker for fresh execution and snapshot restoration, requiring a guest RangeError rather than a WASM trap. The captured PR body reports both pre-fix failures and 24/24 lifecycle tests passing afterward. This review inspected the tests but did not execute them. (src/agents/code-mode-worker-lifecycle.test.ts:340, be8fe4829f7f)
  • Existing failure and cleanup path: The worker preserves guest error names and messages, disposes the VM, and returns a failed result. Host settlement cancels pending bridge work and exposes that error through the existing result flow. (src/agents/code-mode-execution.ts:561, be8fe4829f7f)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: 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.

@vincentkoc
vincentkoc merged commit 9a5ba67 into main Sep 8, 2026
216 checks passed
@vincentkoc
vincentkoc deleted the fix/quickjs-stack-limit-20260908 branch September 8, 2026 07:23
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
Punchcard-Session: amber-brook-orchard-d1
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 16, 2026
Punchcard-Session: amber-brook-orchard-d1
(cherry picked from commit 9a5ba67)
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 16, 2026
배치 A 체리픽이 이 포크에 없는 중간 리팩터링에 걸린 지점을 포크 코드에 맞춰 정리했다.

- 문자열 이스케이프 복구: attempt-prompt-build.ts, attempt-prompt-context.test.ts
- openclaw#140859: session-accessor.entry-mutation.ts 의 transcript 헤더 import 복원
- openclaw#141247: runs.ts 에서 포크에 없는 projectSessionActive 조건 제거
- openclaw#141471: execute-plugin.test-support.js 가 없어 native-bash 테스트 파일 제거
- openclaw#141960: quickjs-wasi 3.6.0 의 MAX_STACK_SIZE 를 쓸 수 없어 되돌림(포크는 3.5.0 핀)
- openclaw#142130: agents.ts 의 assertCurrent 호출 제거, cleanup-utils 는 선택 인자로 유지
- openclaw#142158: manifest-planner.ts 의 remoteModelIds·manifestModelsById 복원
- openclaw#143308: simple-completion-runtime.ts 에 acquireSimpleCompletionModelForAgent 래퍼 추가
- openclaw#143899: src/infra/file-descriptor.ts 의 fingerprint 비교 헬퍼 이식, backup-shared 의 configCapture 참조 제거

Co-Authored-By: Claude Fable 5.1 <[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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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