Skip to content

feat(node-host): supervise durable worker launches - #122829

Merged
steipete merged 7 commits into
mainfrom
steipete/node-worker-supervisor
Aug 12, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/node-worker-supervisor

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The node runner design needs worker turns to survive node control-WebSocket reconnects while remaining bounded by the node-host process lifetime. The existing node.invoke lifecycle cannot own that: it cancels request work on control disconnect, has no durable launch identity, and cannot safely recover or reap a worker process tree after a node-host restart.

Why This Change Was Made

This adds one node-host-owned worker supervision boundary:

  • a lazy same-v6 node_worker_launches SQLite journal records exact launch, supervisor, and worker identities without persisting the worker credential;
  • exact-plan launch IDs are idempotent, while changed replay fails closed;
  • workers start inert behind private Node child-process IPC until their PID/start identity is durable;
  • the IPC channel binds worker lifetime to the node-host process, while each POSIX worker owns a separately signalable process group and Windows retains tree termination through taskkill /T;
  • recovery adopts or interrupts work only after PID-reuse-safe owner checks and confirmed worker-tree death;
  • terminal outcomes stay under active ownership until their SQLite CAS commits;
  • worker stdout/stderr and durable diagnostics are bounded and credential-redacted, including credentials crossing the stderr cutoff;
  • supervised workers inherit only explicit runtime/trust essentials, not ambient provider, channel, Gateway, proxy, config, or state credentials.

This is private node-host process control. It adds no Gateway protocol, public API, config option, advertised node command, runner inventory, provider dispatch, or SQLite schema-version bump. Private launch/status/cancel command wiring remains the next slice.

User Impact

No user-facing runner capability is enabled by this PR alone. It establishes the durable lifecycle owner required for a paired device to host complete session turns safely in the next milestone-6 slices.

Evidence

  • macOS focused lifecycle proof: 40 unit + 30 real-process tests passed; post-rebase sanity: 31 unit + 30 process tests passed.
  • Linux AWS Crabbox run run_5a44cee8ad58 / lease cbx_9363e5c12dc2: 23 unit + 29 process tests passed, including:
    • foreign live pending/running replay remains unchanged;
    • owner SIGKILL closes IPC and kills the worker plus grandchild before restart reconciliation;
    • cancel and close terminate worker-spawned descendants.
  • Canonical changed gate passed on the final source: formatting, Plugin SDK API closure, dead exports, core/test types, full core lint, schema v6, database-first storage, runtime sidecars, and zero runtime import cycles.
  • Full pnpm build passed on the final source.
  • Fresh structured autoreview and TruffleHog: clean.

LOC classification:

  • handwritten production/schema: +1,481 net;
  • generated Kysely types: +22 net;
  • tests/test support: +1,303 net;
  • generated Plugin SDK closure records: 17 hash-only updates, net zero lines.

The production growth is the durable capability itself: journal ownership, PID-reuse-safe recovery, private IPC lifetime fencing, owned process-tree teardown, bounded result capture, and credential/environment isolation. It does not add a compatibility path or second launcher.

Known proof gap: native Windows execution of IPC disconnect, CIM process-start identity, and taskkill /F /T descendant teardown was not available. The implementation reuses the existing Windows identity and tree-kill primitives; macOS and Linux behavior were executed end to end.

AI-assisted; the final stack was independently reviewed and revised through multiple lifecycle/security audits before publication.

@clawsweeper

clawsweeper Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: XL labels Aug 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 12, 2026
@steipete
steipete marked this pull request as ready for review August 12, 2026 21:56
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 12, 2026
@clawsweeper

clawsweeper Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 12, 2026, 6:18 PM ET / 22:18 UTC.

ClawSweeper review

What this changes

Adds node-host-owned durable worker launch supervision using a lazy SQLite journal, IPC-gated startup, and process-tree recovery.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the prior P1 teardown finding remains unchanged at the current head, so a restarted node host can mark a launch interrupted while a detached worker group still runs.

Priority: P1
Reviewed head: 41658e5b1d80ba98599a5cc9133eeffa7f8f540a

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has substantial focused coverage and a coherent owner boundary, but the unresolved P1 recovery defect prevents a stronger rating.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied context identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its stated macOS/Linux real-process evidence is supplemental.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied context identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its stated macOS/Linux real-process evidence is supplemental.
Evidence reviewed 7 items Current recovery defect: The recovery owner treats a reused worker-leader PID as a dead tree before checking its POSIX process group; the matching termination helper also returns without signaling in that state.
Prior blocker remains at current head: The only change after the prior ClawSweeper-reviewed SHA is a node-host shutdown test; the supervisor and recovery test files containing the P1 path were not changed.
Recovery test gap: The real-process recovery test proves group termination while the recorded leader is still the worker root, but does not cover leader exit plus PID reuse while descendants retain the original group.
Findings 1 actionable finding [P1] Keep the worker group alive when its leader PID is reused
Security Needs attention Recovery abandons a live detached worker group: A reused leader PID is treated as a dead worker tree before group liveness is checked, so descendants can survive restart recovery while the journal records a terminal state.

How this fits together

The node host runs device-local worker processes for session turns. The supervisor persists launch ownership, starts a worker only after journaling its identity, and must safely terminate or reconcile that worker after host shutdown or restart.

flowchart LR
A[Worker launch request] --> B[Node host runtime]
B --> C[Worker supervisor]
C --> D[SQLite launch journal]
C --> E[Detached worker group]
E --> F[Terminal receipt]
Loading

Before merge

  • Keep the worker group alive when its leader PID is reused (P1) - This repeats the prior P1 blocker: a detached leader can exit while its descendants retain the original group. Treating reused as dead here, and returning before teardown, lets recoverRunning persist interrupted without killing those descendants. Preserve group liveness and add a leader-reuse real-process regression before terminalizing the receipt.
  • Resolve security concern: Recovery abandons a live detached worker group - A reused leader PID is treated as a dead worker tree before group liveness is checked, so descendants can survive restart recovery while the journal records a terminal state.
  • Resolve merge risk (P1) - A host restart can persist interrupted after a reused worker-leader PID is classified as dead, leaving descendants from the original detached worker group executing without their lifecycle owner.
  • Complete next step (P2) - The existing P1 is a narrow, source-proven repair at the supervisor recovery boundary and the current head did not address it.

Findings

  • [P1] Keep the worker group alive when its leader PID is reused — src/node-host/node-worker-supervisor.ts:186-187
  • [high] Recovery abandons a live detached worker group — src/node-host/node-worker-supervisor.ts:186
Agent review details

Security

Needs attention: The recovery path can leave an authority-bearing worker process tree alive after its node-host owner has ended.

PR surface

Source +1665, Tests +1121, Docs 0, Generated +22. Total +2808 across 38 files.

View PR surface stats
Area Files Added Removed Net
Source 12 1687 22 +1665
Tests 7 1154 33 +1121
Docs 1 16 16 0
Config 0 0 0 0
Generated 18 39 17 +22
Other 0 0 0 0
Total 38 2896 88 +2808

Review metrics

Metric Value Why it matters
Production versus test LOC production +1,481; tests/test support +1,305; generated types +22; docs/baselines net 0 The production growth is foundational lifecycle and persistence behavior, so the recovery invariant needs direct process-level coverage before merge.
Durable storage surface 1 lazy additive SQLite table The new launch journal is same-version and first-use only, making its restart and older-reader behavior a merge-critical lifecycle contract.

Stored data model

Persistent data-model change detected: database schema: src/node-host/node-worker-launch-store.ts, database schema: src/state/openclaw-database-maintenance.test.ts, database schema: src/state/openclaw-state-schema.sql, durable storage schema: src/cli/worker-cli.ts, durable storage schema: src/worker/worker-command.runtime.test.ts, durable storage schema: src/worker/worker-command.runtime.ts, and 10 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair stale-group recovery (recommended)
    Keep the journal running until the original detached worker group is proved dead or has been safely terminated, then add the missing leader-reuse process test.

Technical review

Best possible solution:

Preserve and verify detached-group liveness across leader loss, terminate that owned group before terminal persistence when safe, and add a real-process regression covering leader exit, retained descendants, and PID reuse.

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

Yes, source-reproducible: the current reused-PID branch classifies the tree as dead and skips termination, while the recovery path then persists an interrupted terminal receipt.

Is this the best way to solve the issue?

No: the supervisor is the right lifecycle owner, but its reused-leader branch violates the owned-process-group invariant; repair that boundary rather than adding downstream cleanup.

Full review comments:

  • [P1] Keep the worker group alive when its leader PID is reused — src/node-host/node-worker-supervisor.ts:186-187
    This repeats the prior P1 blocker: a detached leader can exit while its descendants retain the original group. Treating reused as dead here, and returning before teardown, lets recoverRunning persist interrupted without killing those descendants. Preserve group liveness and add a leader-reuse real-process regression before terminalizing the receipt.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 87b503675a37.

Labels

Label justifications:

  • P1: The current recovery defect can leave active device-hosted work running after its owning node host has stopped.
  • merge-risk: 🚨 session-state: The durable launch receipt can become terminal while the corresponding worker descendants remain live.
  • merge-risk: 🚨 security-boundary: A worker carrying turn authority can outlive the node-host ownership boundary after restart recovery.
  • merge-risk: 🚨 availability: Orphaned worker descendants can continue consuming host resources and interfere with later lifecycle recovery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The supplied context identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its stated macOS/Linux real-process evidence is supplemental.

Evidence

Security concerns:

  • [high] Recovery abandons a live detached worker group — src/node-host/node-worker-supervisor.ts:186
    A reused leader PID is treated as a dead worker tree before group liveness is checked, so descendants can survive restart recovery while the journal records a terminal state.
    Confidence: 0.98

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/node-host/node-worker-supervisor.recovery.test.ts src/node-host/node-worker-supervisor.test.ts src/process/supervisor/adapters/child.test.ts.
  • [P1] node scripts/check-changed.mjs -- src/node-host/node-worker-supervisor.ts src/node-host/node-worker-supervisor.recovery.test.ts src/process/supervisor/adapters/child.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Authored the node-worker supervisor, its lifecycle hardening commits, the runtime integration, and the runner-plan milestone update. (role: feature owner and recent area contributor; confidence: high; commits: e7f3a65d451e, 6d9ec2929eb5, 41658e5b1d80; files: src/node-host/node-worker-supervisor.ts, src/node-host/runtime.ts, docs/plan/runners.md)
  • hcl: Authored the established detached-process group safety work that the changed child adapter and recovery logic build upon. (role: adjacent process-tree contributor; confidence: medium; commits: 4a72e1b99017; files: src/process/supervisor/adapters/child.ts, packages/agent-core/src/harness/env/kill-tree.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Repair the reused-leader process-group path.
  • Add a real-process regression that proves descendants are terminated before the durable receipt becomes terminal.

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 (1 earlier review cycle)
  • reviewed 2026-08-12T22:03:50.755Z sha 1651408 :: needs changes before merge. :: [P1] Preserve the worker group when its leader PID is reused

@steipete
steipete merged commit 6b9bea8 into main Aug 12, 2026
120 checks passed
@steipete
steipete deleted the steipete/node-worker-supervisor branch August 12, 2026 22:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 13, 2026
* feat(node-host): add worker launch supervision

* fix(node-host): harden worker lifecycle ownership

* fix(node-host): harden worker execution boundary

* fix(node-host): preserve worker trust settings

* chore(plugin-sdk): refresh worker lifecycle baselines

* docs(plan): track runner implementation slices

* test(node-host): await runtime shutdown owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes 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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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