Skip to content

fix: openclaw node worker never exits after a stop when stdin is held open or a plugin child pins the event loop - #135665

Merged
obviyus merged 7 commits into
openclaw:mainfrom
Colton-Harris:pr/node-worker-exit-after-stop
Sep 2, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
Colton-Harris:pr/node-worker-exit-after-stop

Conversation

@Colton-Harris

@Colton-Harris Colton-Harris commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #135661

Related: #135660 / #135663 (the separate macOS process-group fix)

What Problem This Solves

openclaw node worker acknowledged a stop but could remain alive forever. The normal macOS supervisor keeps the stdin writer open until the worker exits. A plugin-owned child can also keep referenced pipes open during shutdown.

Current main 4e36c68976a9474e6c7bf6dc55e2aedb4321d54d reproduced both failures through the built worker command. Each worker remained alive after 2.5 seconds and required cleanup.

Why This Change Was Made

runNodeHostWorker already closes the bridge, awaits runtime.close(), records the exit code, and removes its signal handlers. It then returned and relied on Node's event loop to drain. That cannot finish while the supervisor still owns the stdin writer.

The worker now requests the existing one-shot CLI finalizer after its shutdown promise settles. The request records terminal intent. The top-level CLI still completes shared resource and harness disposal before it drains stdout/stderr and exits, so plugin children are not hidden by an early process.exit().

This accepts the intentional availability tradeoff named by ClawSweeper: after owned cleanup completes, unrelated referenced handles no longer keep a stopped worker alive.

User Impact

Stopping the private node worker now ends the process promptly. Stop frames keep exit code 0. SIGTERM keeps exit code 143.

Evidence

Real built-process proof used the same isolated Linux Node 24 environment for current main and the reviewed candidate.

Case Current main Reviewed head
Stop frame; stdin kept open Alive after 2.5 s Exit 0 in 66 ms
Stop frame; declared plugin child Alive after 2.5 s Exit 0 in 24 ms; child exited
SIGTERM; declared plugin child Not needed for red Exit 143 in 21 ms; child exited

Regression coverage now drives openclaw.mjs node worker as a real child process. It waits for the worker's ready frame, sends a stop frame without closing stdin, and requires exit code 0. The test failed on exact main with worker stayed alive after stop while stdin remained open and passed on the reviewed head.

Focused validation:

  • Worker owner tests, the built-runtime process suite, and CI routing/planner contracts passed on the reviewed head.
  • oxfmt --check and targeted oxlint — passed.
  • Full candidate build — passed in the isolated Linux proof environment.
  • Production delta: +4 lines. Test delta: +70 lines. The +4 production lines reuse the canonical CLI finalizer and preserve the cleanup boundary.

Original fix by @Colton-Harris. Maintainer proof and regression repair by @obviyus.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@Colton-Harris
Colton-Harris marked this pull request as ready for review September 1, 2026 23:40
…les remain

runNodeHostWorker set process.exitCode after stop and relied on the event
loop draining. Its own stdin pipe keeps reading while the supervisor still
holds the writer, and a plugin-owned child (codex app-server) keeps ref'd
pipes past runtime.close(), so the worker never exited on its own.

Request the canonical one-shot CLI exit once the worker has stopped, after
runtime.close() finished, so the shared finalizer drains stdio and exits.
@Colton-Harris
Colton-Harris force-pushed the pr/node-worker-exit-after-stop branch from ec1ca5c to 69dc4ef Compare September 1, 2026 23:45
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 1:31 AM ET / 05:31 UTC.

ClawSweeper review

What this changes

This PR makes the private openclaw node worker request the shared CLI exit finalizer after handling a stop, with a built-process regression test for a supervisor that leaves stdin open.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open pending maintainer confirmation of the deliberate shutdown boundary: after successful node-host cleanup, the private worker exits even if unrelated referenced handles remain. The patch otherwise uses the existing CLI finalizer and has no concrete correctness finding.

Priority: P1
Reviewed head: 1658cceaa9ec76542a0490a3759370aac0c6294c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with credible real-process proof; merge readiness depends only on confirming the intentional lifecycle boundary.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed owner is the private node-host worker; the PR body supplies a built-worker before/after process trace for the matching CLI entrypoint, including a held-stdin stop that changes from remaining alive after 2.5 seconds to exiting cleanly. The committed regression test independently drives that same entrypoint and scenario.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed owner is the private node-host worker; the PR body supplies a built-worker before/after process trace for the matching CLI entrypoint, including a held-stdin stop that changes from remaining alive after 2.5 seconds to exiting cleanly. The committed regression test independently drives that same entrypoint and scenario.
Evidence reviewed 6 items Current-main behavior: The fetched current-main worker waits for its stopped promise, removes signal handlers, and returns without requesting the one-shot exit finalizer; the reported held-stdin hang remains relevant to current main.
Introduced shutdown boundary: The PR adds the canonical finalizer request only after the worker's stopped promise settles and signal handlers are removed.
Canonical exit mechanism: The existing one-shot finalizer records the requested terminal outcome, drains stdout and stderr, and then calls the runtime exit function; it is therefore the shared owner for this process-exit behavior.
Findings None None.
Security None None.

How this fits together

The private node-host worker receives JSONL stop frames from the macOS app or another supervisor, closes its node-host runtime, and returns through the CLI entrypoint. The shared CLI finalizer drains output and terminates the process, preventing stdin or a child process from holding a stopped worker alive.

flowchart LR
  A[Supervisor] -->|Stop frame or signal| B[Private node worker]
  B --> C[Close node-host runtime]
  C --> D[Shared CLI finalizer]
  D --> E[Drain stdout and stderr]
  E --> F[Process exits]
  G[Open stdin or child handles] -.cannot pin stopped worker.-> F
Loading

Decision needed

Question Recommendation
Should successful node-host runtime cleanup be the terminal boundary for the private worker, allowing the shared finalizer to exit despite unrelated referenced handles? Confirm terminal shutdown boundary: Accept the existing one-shot finalizer after successful runtime cleanup so stopped private workers cannot remain alive behind supervisor-held stdin or unrelated handles.

Why: This is an intentional availability tradeoff rather than an accidental implementation detail: it prevents an indefinitely stuck worker but stops waiting for handles outside the runtime's cleanup ownership.

Before merge

  • Resolve merge risk (P1) - Merging intentionally makes successful node-host shutdown terminal after runtime-owned cleanup, so plugin-owned or unrelated referenced handles no longer prolong the private worker lifetime.
Agent review details

Security

None.

PR surface

Source +4, Tests +70. Total +74 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 0 +4
Tests 1 70 0 +70
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 74 0 +74

Review metrics

Metric Value Why it matters
Production versus regression coverage production +4, tests +70 The small production addition delegates to an existing finalizer; the added coverage exercises the built worker through its CLI entrypoint.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #135661
Summary: This PR is the candidate worker-lifecycle fix for the held-stdin shutdown hang reported in the canonical issue; the macOS process-group PR addresses a distinct companion failure.

Members:

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

Merge-risk options

Maintainer options:

  1. Confirm bounded worker shutdown (recommended)
    Accept the documented boundary that runtime-owned cleanup completes before the shared finalizer terminates the private worker.
  2. Pause for lifecycle redesign
    Keep drain-only behavior and address all possible external handle owners before changing worker termination semantics.

Technical review

Best possible solution:

Confirm successful runtime.close() as the private worker's terminal cleanup boundary, then retain this reuse of the shared CLI finalizer.

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

Yes: the supplied built-process before/after trace exercises a stop frame with stdin held open, and current-main source confirms the worker returns without requesting the finalizer.

Is this the best way to solve the issue?

Yes, conditionally: the patch reuses the canonical CLI exit mechanism at the worker lifecycle owner; only acceptance of the stated terminal-boundary tradeoff remains.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A stopped private worker can remain alive indefinitely, consuming resources and preventing reliable supervisor shutdown.
  • merge-risk: 🚨 availability: The PR deliberately changes process-lifetime behavior after runtime cleanup, which requires accepting the bounded shutdown tradeoff.
  • 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 (terminal): The changed owner is the private node-host worker; the PR body supplies a built-worker before/after process trace for the matching CLI entrypoint, including a held-stdin stop that changes from remaining alive after 2.5 seconds to exiting cleanly. The committed regression test independently drives that same entrypoint and scenario.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed owner is the private node-host worker; the PR body supplies a built-worker before/after process trace for the matching CLI entrypoint, including a held-stdin stop that changes from remaining alive after 2.5 seconds to exiting cleanly. The committed regression test independently drives that same entrypoint and scenario.

Evidence

What I checked:

  • Current-main behavior: The fetched current-main worker waits for its stopped promise, removes signal handlers, and returns without requesting the one-shot exit finalizer; the reported held-stdin hang remains relevant to current main. (src/node-host/worker.ts:134, bc4fc0142a1f)
  • Introduced shutdown boundary: The PR adds the canonical finalizer request only after the worker's stopped promise settles and signal handlers are removed. (src/node-host/worker.ts:141, 1658cceaa9ec)
  • Canonical exit mechanism: The existing one-shot finalizer records the requested terminal outcome, drains stdout and stderr, and then calls the runtime exit function; it is therefore the shared owner for this process-exit behavior. (src/cli/one-shot-exit.ts:127, 1658cceaa9ec)
  • Real-process regression coverage: The new test starts the built CLI worker, waits for its ready frame, sends a stop frame while retaining the stdin writer, and requires a clean exit within 2.5 seconds. (src/cli/update-dry-run-state.process.test.ts:289, 1658cceaa9ec)
  • Codex app-server contract inspected: The sibling Codex checkout's app-server loop exits single-client mode when its stdio connection closes; its cache-mirror remote did not independently establish repository ownership, so this is not attributed to a verified dependency repository. (codex-rs/app-server/src/lib.rs:1024, 78c290807ce710180111df227df3b7a4fe845452)
  • Feature-history routing: The node-host worker originated in the macOS node-session feature commit, while the shared finalizer was most recently maintained by a CLI exit-code fix from the same contributor. (src/node-host/worker.ts:135, d65e712b286b)

Likely related people:

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

Rank-up moves

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

  • Obtain confirmation that successful runtime cleanup is the private worker's terminal cleanup boundary.

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-01T23:54:55.777Z sha 69dc4ef :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T04:42:28.008Z sha 74e472d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T05:06:36.211Z sha ce0a79e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T05:20:28.643Z sha 6a7f839 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Sep 2, 2026
@obviyus
obviyus merged commit 64bcb0c into openclaw:main Sep 2, 2026
114 checks passed
@obviyus

obviyus commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Colton-Harris!

Proof: The built openclaw node worker process now exits after owned cleanup when stdin stays open or a declared plugin child pins the event loop.

  • Bug: A stop completed internally, but the worker stayed alive because Node waited for referenced handles.
  • Fix: The worker requests the canonical CLI finalizer after runtime cleanup; the outer CLI still disposes harnesses and drains output before exit.
Before After
Stop frame left the worker alive after 2.5 seconds. Stop frame exited 0 in 66 ms; the plugin child also exited.

Landed: 64bcb0c

Source: 1658cce

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
A stopped private node worker now requests the canonical CLI finalizer after runtime cleanup. A supervisor-held stdin writer or plugin child can no longer keep the completed worker alive.

The regression runs the built `openclaw.mjs node worker` path, keeps stdin open after the stop frame, and requires a clean exit.

Closes openclaw#135661

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

Labels

cli CLI command changes merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: openclaw node worker never exits after a stop while its stdin writer is held open or a plugin child pins the event loop

2 participants