Skip to content

Experiment with agent worker runtime isolation - #78164

Closed
steipete wants to merge 8 commits into
mainfrom
node-worker
Closed

steipete wants to merge 8 commits into
mainfrom
node-worker

Conversation

@steipete

@steipete steipete commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add an experimental Node worker runtime path for Pi agent attempts, enabled through agents.defaults.experimental.runtimeIsolation.mode: "worker" or OPENCLAW_AGENT_RUNTIME_WORKER=1
  • move attempt execution into a worker entrypoint with filesystem permission plumbing and build output support
  • document the experimental setting and keep transcript persistence working by initializing context engines before parent-side CLI compaction
  • serialize session-store writes with a sessions.json.lock file lock so concurrent worker/process isolates do not lose updates
  • restore plugin runtime state inside worker attempts and resync parent-visible session-store state after worker attempts

Why

The branch explores running each agent attempt in a separate worker so multiple agents can run in parallel while gaining a cleaner boundary for per-agent filesystem isolation. The first version keeps the main runtime contract intact and gates the behavior behind an explicit experimental switch.

The branch also fixes issues found during verification and review:

  • the worker completed successfully, but parent-side transcript persistence resolved the default legacy context engine before the parent process had registered built-in engines
  • session-store writes were only serialized inside one JS isolate, so concurrent workers/processes could overwrite each other when mutating the same sessions.json
  • worker attempts started with fresh plugin globals, so plugin hooks and command prompt guidance were absent
  • worker-side session-store mutations could leave the parent with stale in-memory session state

Real behavior proof

Behavior addressed: Experimental worker runtime can run real local OpenClaw agent attempts successfully, parent-side transcript persistence no longer reports Context engine "legacy" is not registered, concurrent session-store updates preserve all writers, and the latest worker boundary fixes preserve plugin runtime restore plus parent session-store sync.

Real environment tested: Blacksmith Testbox via Crabbox, OpenAI auth from openclaw-testbox-env, provider/model openai/gpt-5.4, three worker-enabled agents (alpha, beta, gamma) launched in parallel.

Exact proof: Crabbox run https://github.com/openclaw/openclaw/actions/runs/25417924262 hydrated Testbox tbx_01kqxvq72qnz2v9av2gp5f7kft, built the branch, then launched all three agents concurrently with OPENCLAW_AGENT_RUNTIME_WORKER=1 node openclaw.mjs agent --local ... --json.

Exact steps or command run after this patch: Built the PR on Testbox, then launched three local agent commands in parallel with worker isolation enabled: OPENCLAW_AGENT_RUNTIME_WORKER=1 node openclaw.mjs agent --local --agent alpha --provider openai --model gpt-5.4 --json, repeated for beta and gamma, followed by a sessions.json verification script that checked all three persisted session entries.

Evidence after fix: The remote verifier printed:

MULTI_AGENT_WORKER_LIVE_OK
MULTI_AGENT_SESSION_STORE_OK

Observed result after fix: All three live OpenAI agent runs returned the exact expected payloads (ALPHA_WORKER_OK, BETA_WORKER_OK, GAMMA_WORKER_OK), each reported the embedded runner, and each persisted its session entry under the matching agent state directory. The latest local worker-thread regression run also passed src/agents/worker-runtime/agent-runtime.test.ts and src/agents/worker-runtime/plugin-runtime.test.ts, covering plugin runtime restore and parent session-store resync on worker success/error.

What was not tested: No GUI, mobile, or non-agent channel surfaces. For the latest review follow-up, a fresh pnpm check:changed Testbox run was attempted but the runner stayed queued, so it was stopped without result.

Remaining note: The parallel live run emitted two non-fatal [tasks/registry] Failed to restore task registry warnings, but the agent runs and session persistence completed. That looks like a separate task-registry startup/concurrency wart, not the worker runtime handoff fixed here.

Verification

  • pnpm docs:list
  • pnpm test src/config/sessions/store-writer.test.ts src/agents/worker-runtime/agent-runtime.test.ts
  • pnpm test src/agents/worker-runtime/agent-runtime.test.ts src/agents/worker-runtime/plugin-runtime.test.ts
  • pnpm exec oxfmt --check --threads=1 src/agents/worker-runtime/agent-runtime.ts src/agents/worker-runtime/agent-runtime.worker.ts src/agents/worker-runtime/agent-runtime.test.ts src/agents/worker-runtime/plugin-runtime.ts src/agents/worker-runtime/plugin-runtime.test.ts
  • pnpm exec oxfmt --check --threads=1 src/config/sessions/store-writer.ts src/config/sessions/store-writer.test.ts docs/reference/session-management-compaction.md docs/concepts/experimental-features.md
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/config/sessions/store-writer.ts src/config/sessions/store-writer.test.ts
  • pnpm tsgo:core
  • pnpm tsgo:core:test
  • Crabbox/Testbox: pnpm test src/config/sessions/store-writer.test.ts src/agents/worker-runtime/agent-runtime.test.ts passed in https://github.com/openclaw/openclaw/actions/runs/25417769087 before the live agent phase
  • Crabbox/Testbox live multi-agent proof passed in https://github.com/openclaw/openclaw/actions/runs/25417924262 with MULTI_AGENT_WORKER_LIVE_OK and MULTI_AGENT_SESSION_STORE_OK
  • post-commit git diff --check

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels May 6, 2026
@clawsweeper

clawsweeper Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 3, 2026, 11:45 PM ET / 03:45 UTC.

Summary
This PR adds opt-in worker-thread execution for agent command attempts, config/docs for the experiment, worker permission plumbing, cross-isolate session-store locking, and regression coverage.

PR surface: Source +789, Tests +690, Docs +56, Other +2. Total +1537 across 24 files.

Reproducibility: yes. for the review blockers: the shared worker gate, docs mismatch, current-main function-valued options, and Node DataCloneError behavior are visible from source and a focused worker_threads probe. I did not run the PR test suite in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Experimental Config/Env Surface: 1 config object added, 2 nested fields added, 4 env toggles accepted. The new worker mode and permission switch create operator-visible behavior that needs product and upgrade acceptance before merge.
  • Persistent Lock Sidecar: 1 lock-file path introduced. sessions.json.lock changes session-store write availability, stale-lock recovery, and cross-process behavior when worker mode is used.

Stored data model
Persistent data-model change detected: durable storage schema: src/agents/worker-runtime/agent-runtime.test.ts, durable storage schema: src/agents/worker-runtime/agent-runtime.ts, durable storage schema: src/agents/worker-runtime/agent-runtime.types.ts, durable storage schema: src/agents/worker-runtime/agent-runtime.worker.ts, durable storage schema: src/agents/worker-runtime/errors.ts, durable storage schema: src/agents/worker-runtime/permissions.test.ts, and 16 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: partial_overlap
Canonical: #42026
Summary: This PR is a narrow worker-thread runtime isolation experiment that partially overlaps the broader distributed agent runtime RFC but does not replace it.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Resolve the conflict against current main.
  • [P2] Limit worker mode to the documented local command surface or add the Gateway callback bridge.
  • Whitelist or proxy worker payload callbacks and get maintainer acceptance for the config, lock-file, and permission surfaces.

Risk before merge

  • [P1] The branch is draft and dirty/conflicting, so the exact merge result still needs rebase review against current main.
  • [P1] Worker mode is wired below both local and ingress entrypoints, while the docs promise Gateway ingress stays in-process until a callback bridge exists.
  • [P1] The worker payload is not clone-safe against current-main function-valued options, so enabling worker mode after rebase can fail before the attempt starts.
  • [P1] The new config/env surface, sessions.json.lock sidecar, and Node permission allowlist need explicit product, upgrade, and security acceptance before users rely on them.

Maintainer options:

  1. Rebase And Narrow Worker Scope (recommended)
    Refresh the branch against current main, preserve newer agent option callbacks, and gate worker mode only on the documented local command surface unless a Gateway callback bridge is added.
  2. Sponsor The Experimental Boundary
    Maintainers may accept the opt-in config, lock-file sidecar, and Node permission boundary after documenting unsupported callback, harness, and upgrade cases.
  3. Park Under Runtime Design Work
    If the broader runtime-isolation direction should settle first, keep this draft under the distributed-runtime tracker instead of landing a partial runtime boundary now.

Next step before merge

  • [P2] Human maintainer review is needed because the PR is draft/conflicting, protected by the maintainer label, and requires product/security decisions rather than a narrow automated repair.

Security
Needs attention: The diff adds an opt-in Node worker permission boundary and lock-file sidecar; no malicious supply-chain change was found, but the security semantics need maintainer approval.

Review findings

  • [P2] Keep Gateway ingress out of the worker gate — src/agents/agent-command.ts:1048-1049
  • [P2] Make worker opts clone-safe before posting — src/agents/worker-runtime/agent-runtime.ts:155-156
Review details

Best possible solution:

Rebase onto current main, keep Gateway ingress in-process unless a real callback bridge is added, define a clone-safe worker payload, and get maintainer acceptance for the experimental config, lock-file, and permission boundary.

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

Yes for the review blockers: the shared worker gate, docs mismatch, current-main function-valued options, and Node DataCloneError behavior are visible from source and a focused worker_threads probe. I did not run the PR test suite in this read-only review.

Is this the best way to solve the issue?

No, not yet: worker isolation is a plausible experiment, but this branch needs a clean rebase, a local-command-only gate or Gateway callback bridge, and a clone-safe payload contract before it is the best maintainable solution.

Full review comments:

  • [P2] Keep Gateway ingress out of the worker gate — src/agents/agent-command.ts:1048-1049
    The docs say normal inbound Gateway replies stay in-process until there is a dedicated callback bridge, but this gate runs inside shared agentCommandInternal, which agentCommandFromIngress also calls. With worker mode enabled in Gateway config, ingress runs can take the worker path anyway, so gate this at the local command entrypoint or add the promised bridge.
    Confidence: 0.86
  • [P2] Make worker opts clone-safe before posting — src/agents/worker-runtime/agent-runtime.ts:155-156
    worker.postMessage uses structured clone, but this path only removes opts.abortSignal before sending the rest of opts. Current main has function-valued agent options such as onActiveModelSelected and onSessionIdChanged, so a rebased worker mode can throw before the attempt starts unless opts are whitelisted or callback fields are proxied.
    Confidence: 0.89

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9d68f877ac3e.

Label changes

Label justifications:

  • P2: This is a normal-priority experimental agent runtime improvement with opt-in behavior but substantial compatibility, security, and availability review surface.
  • merge-risk: 🚨 compatibility: The PR adds config/env behavior, introduces a session-store lock sidecar, and must be rebased against current-main option callbacks before upgrade behavior is clear.
  • merge-risk: 🚨 security-boundary: The PR introduces a Node worker permission boundary that changes filesystem isolation expectations for agent execution.
  • merge-risk: 🚨 availability: Worker startup, structured-clone failures, stale locks, and cross-thread session-store synchronization can fail agent attempts when the experiment is enabled.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes live Crabbox/Testbox output markers for worker-enabled local agent attempts and session persistence, and the current head's Real behavior proof check succeeded.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes live Crabbox/Testbox output markers for worker-enabled local agent attempts and session persistence, and the current head's Real behavior proof check succeeded.
Evidence reviewed

PR surface:

Source +789, Tests +690, Docs +56, Other +2. Total +1537 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 15 798 9 +789
Tests 6 690 0 +690
Docs 2 62 6 +56
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 24 1552 15 +1537

Security concerns:

  • [medium] Clarify the Node worker permission boundary — src/agents/worker-runtime/permissions.ts:94
    The permission allowlist changes filesystem and process-isolation expectations for agent execution, so maintainers need to accept the child-process, CLI harness, runtime read, and lock-file write semantics before users rely on it.
    Confidence: 0.78

What I checked:

  • Repository policy applied: Root and scoped AGENTS.md were read fully; runtime isolation, config/default additions, session storage, docs, and security-boundary guidance affected the review. (AGENTS.md:28, 9d68f877ac3e)
  • Live PR state: GitHub reports this PR open, draft, protected by the maintainer label, and not mergeable because the branch is dirty/conflicting at head 883eed2. (883eed2e95c2)
  • Current main does not already implement the worker runtime: A source search on current main found no runtimeIsolation, OPENCLAW_AGENT_RUNTIME_WORKER, worker-runtime, or sessions.json.lock implementation, so the central feature is not already implemented on main. (9d68f877ac3e)
  • Worker gate is below shared local and ingress command entrypoints: PR head chooses runAgentAttemptInWorker inside shared agentCommandInternal, while the same file also routes agentCommandFromIngress through that shared internal command path. (src/agents/agent-command.ts:1048, 883eed2e95c2)
  • Docs promise Gateway ingress remains in-process: The PR docs say normal inbound Gateway replies remain on the in-process embedded runner until a dedicated callback bridge exists. Public docs: docs/concepts/experimental-features.md. (docs/concepts/experimental-features.md:38, 883eed2e95c2)
  • Worker payload is not clone-safe against current main callbacks: PR head strips only top-level callbacks and opts.abortSignal before posting opts to a Worker, while current main AgentCommandOpts includes function-valued callbacks such as onActiveModelSelected and onSessionIdChanged. (src/agents/worker-runtime/agent-runtime.ts:155, 883eed2e95c2)

Likely related people:

  • steipete: Authored this worker-runtime PR and has the heaviest sampled history in agent command and runtime files, including agent runtime movement and command execution refactors. (role: feature author and adjacent runtime contributor; confidence: high; commits: 883eed2e95c2, 310b5e4f6a22, 046a950877f6; files: src/agents/worker-runtime/agent-runtime.ts, src/agents/agent-command.ts, src/agents/command/attempt-execution.ts)
  • vincentkoc: Recent current-main history touches agent command performance, attempt execution/runtime type surfaces, and the experimental-features docs this branch extends. (role: recent area contributor; confidence: high; commits: e085fa1a3ffd, f126088761b7, dbcc574e1fc5; files: src/agents/agent-command.ts, src/agents/command/attempt-execution.ts, docs/concepts/experimental-features.md)
  • Ayaan Zaidi: Recent commits changed CLI transcript persistence and session metadata around the same attempt-execution and parent-side transcript surfaces affected by this branch. (role: recent adjacent CLI/session contributor; confidence: medium; commits: 898fd0482a40, b8ef507cc082, 3a3fae0eac0f; files: src/agents/agent-command.ts, src/agents/command/attempt-execution.ts)
  • jalehman: Introduced the context-engine registry and initialization surface that this PR adjusts for parent-side CLI compaction. (role: context-engine feature contributor; confidence: medium; commits: fee91fefceb4; files: src/context-engine/init.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 14, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Jun 24, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 24, 2026
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing this experimental worker-runtime branch. The current agent option surface contains function callbacks, while this branch posts nearly all opts through structured clone after removing only abortSignal, so a current-main replay can fail before an attempt starts and cannot preserve Gateway callback semantics. It also adds sessions.json lock-file state and a broad new runtime/config boundary without a concrete production contract. A future isolation design needs an explicit clone-safe protocol, callback bridge, and current SQLite/session ownership model.

@steipete steipete closed this Jul 7, 2026
@shakkernerd
shakkernerd deleted the node-worker branch October 19, 2026 23:21
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant