Skip to content

fix(macos): node-host worker escapes the app's process group and outlives every worker restart - #135663

Merged
steipete merged 3 commits into
openclaw:mainfrom
Colton-Harris:pr/mac-app-worker-no-respawn
Sep 3, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Colton-Harris:pr/mac-app-worker-no-respawn

Conversation

@Colton-Harris

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

Copy link
Copy Markdown
Contributor

Closes #135660. Related worker-shutdown work: #135661.

What Problem This Solves

The macOS app owns its node-host worker through ManagedProcess and a process group. CLI startup can instead launch the actual worker in a separate session, leaving the app owning only the startup wrapper. When shutdown kills that wrapper, an unresponsive worker can survive and become orphaned.

The worker launch owner now sets the existing OPENCLAW_NO_RESPAWN=1 contract alongside its app execution settings. The packaged-worker verifier uses the same launch shape. This keeps the worker inside the process group already owned by the app and preserves the existing shutdown implementation.

Production: +3 app lines; verification tooling: +3 lines; tests: +2/-1, net +1. Each non-test site adds one existing-contract assignment and two lines explaining the process-group invariant. No new configuration option, supervisor or protocol is introduced. Colton Harris's original commits remain in the ancestry.

Evidence

Current integrated head: 1dd2887cb5ad9a2297598065dcccdc63c73f863c, tree b4eb41c93ac95d855457cf3ae83aa1a74e5c5338. Candidate packaged-process proof and exact-head GitHub CI passed.

The independent GitHub-hosted macOS baseline proof used the canonical staged package and actual Swift owner, with pinned Node 24.19.0. It observed a launcher and worker in separate process groups. In the unresponsive scenario, the same identified worker was stopped with SIGSTOP after readiness, survived owner.stop() after its launcher was reaped, and remained under PPID 1 until exact-process cleanup removed it. The normal worker exited eventually after stop returned; this is not immediate joined shutdown.

The permanent launch-environment regression failed as intended with exit 46; all 26 existing owner controls passed. Full frozen installation, package build/staging/native-first checks and Swift compilation passed. Source/lock/runtime receipts and raw index captures are retained. Only parsed index ctime/mtime fields changed; other index and packaged runtime bytes remained fixed.

The baseline's outer controller conservatively marks the expected failing test command as unconfirmed and retains its namespace. This is not a measured live-process result. The actual worker cleanup is independently established by exact PID, UID, birth, executable and group observations; whole-namespace deletion is not claimed for that baseline.

The exact candidate proof passed all 27 owner tests and both actual packaged-worker scenarios on GitHub-hosted macOS 26.5.2 / arm64, Xcode 26.6, Swift 6.3.3, and bundled Node 24.19.0. It performs a fresh full canonical build, package staging/native-first checks and Swift compilation on the integrated head.

Actual packaged scenario Observed before stop Observed when owner.stop() returned
Normal One direct worker PID/PGID 41912, parent 41910 No tracked worker after 0.494 seconds
Unresponsive Same identified worker PID/PGID 42194, UID 501, confirmed SIGSTOP status 4 No tracked worker after 0.124 seconds

PID, parent, process group, birth timestamp, UID and canonical executable were checked together; requested and canonical paths are recorded separately. Both later cleanup observations remain empty. There is no wrapper worker outside the app-owned group.

All 54 source bindings, tracked and installed locks, and 39,029 packaged runtime records remain unchanged. Independent parsing checked 20 raw-index captures across 36,821 entries; only five paths' ctime/mtime fields changed, with every other entry/extension byte fixed. The proof overlay was removed, source restoration succeeded, and the private namespace was removed with no unconfirmed failed command. The actual worker disappearance is measured separately from generic outer subprocess exit status.

Exact-head CI attempt 2 passed 120 jobs, with 14 skipped and zero failures. Every executed job used actual GitHub Actions runners: 115 Ubuntu, two macOS 26 and three macOS 15. All five Mac jobs, the package build and the aggregate gate passed.

The prior candidate attempt stopped at an unrelated shared UI startup budget failure before any owner tests or actual worker scenarios ran. After integrating canonical main507 build repairs, the fresh build above passed. No budget or unrelated product changes are introduced by this PR.

Independent product review is clean. The latest TLS review finding is inapplicable: entry.respawn explicitly calls the TLS planner with includeDarwinDefaults:false, and its Linux-only CA discovery returns undefined on Darwin. That unchanged startup path did not supply the proposed Darwin defaults before this PR; existing inherited/explicit CA settings remain preserved. The separate launchd service policy is not on this app-worker path. The detailed source/history disposition is posted with a re-review request. The proof covers direct app-owned worker containment, not separate provider-process shutdown or unrelated Accessibility behavior. The source-checkout compile-cache launcher remains a named separate follow-up.

Contributor: Colton Harris (@Colton-Harris).

MacNodeHostWorker launches `openclaw node worker` under ManagedProcess, which
owns the child by process group (SIGTERM -pgid, 250 ms, SIGKILL -pgid). The
CLI startup respawn re-executes the real worker with detached: true (setsid),
so the app only ever owned the respawn wrapper. When the worker did not exit
on the forwarded SIGTERM, the app's SIGKILL escalation killed the wrapper and
orphaned the worker together with its codex app-server child.

Set OPENCLAW_NO_RESPAWN=1 on the worker launch, matching the gateway's own
node-worker supervisor, so the worker stays in the owned group. The package
proof harness uses the same launch shape so requireProcessTreeExit proves
the real worker exited, not only the wrapper.
@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.

@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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 3, 2026, 12:35 AM ET / 04:35 UTC.

ClawSweeper review

What this changes

The PR sets the existing no-respawn launch contract for the macOS node-host worker and mirrors it in its owner test and packaged-worker verifier.

Regression provenance

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

Merge readiness

✅ Ready for maintainer review

Keep this PR open as the focused fix for the linked macOS worker-containment bug. The prior TLS finding is disproved by the existing startup path, and the current patch correctly prevents the detached respawn at the lifecycle owner.

Priority: P1
Reviewed head: 1dd2887cb5ad9a2297598065dcccdc63c73f863c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow owner-boundary repair with strong packaged macOS behavior evidence and focused contract coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed production owner is the macOS worker launch environment. The supplied exact-head GitHub-hosted packaged-worker evidence runs normal and SIGSTOP worker scenarios with the new value and reports the tracked worker absent when owner stop returns.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed production owner is the macOS worker launch environment. The supplied exact-head GitHub-hosted packaged-worker evidence runs normal and SIGSTOP worker scenarios with the new value and reports the tracked worker absent when owner stop returns.
Evidence reviewed 6 items Current main lacks containment: Current main sets the app execution-host values but does not set the existing no-respawn contract at the macOS worker launch owner.
Respawn contract: The CLI skips startup respawn when OPENCLAW_NO_RESPAWN is truthy; otherwise a noninteractive respawn requests detached process-tree handling.
Lifecycle owner: ManagedProcess creates a session and terminates its process group, so retaining the actual worker in that group is the correct ownership boundary.
Findings None None.
Security None None.

How this fits together

The macOS app launches a private Node worker and terminates its managed process group on restart or shutdown. CLI startup decides whether the real worker remains in that group or moves into a detached session the app cannot kill.

flowchart LR
  A[macOS app] --> B[Managed process group]
  B --> C[Node worker launch]
  C --> D{CLI respawn enabled?}
  D -->|yes| E[Detached worker session]
  D -->|no| F[App-owned worker]
  F --> G[Shutdown removes worker tree]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other +7. Total +7 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 8 1 +7
Total 3 8 1 +7

Review metrics

Metric Value Why it matters
Production and test delta production +3, verification tooling +3, tests +1 net The production addition is one existing supervisor contract at the worker owner; tooling and test coverage mirror that exact launch shape.

Technical review

Best possible solution:

Land the lifecycle-owner assignment with its existing focused coverage and packaged-worker verification, leaving any separate launchd TLS-policy discussion outside this containment repair.

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

Yes: current source shows that the macOS app owns one process group while noninteractive CLI respawn can detach the real worker, and the supplied packaged baseline and candidate traces exercise that exact shutdown boundary.

Is this the best way to solve the issue?

Yes: applying the established no-respawn contract at the launch owner prevents the process-group escape instead of adding downstream orphan cleanup.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed production owner is the macOS worker launch environment. The supplied exact-head GitHub-hosted packaged-worker evidence runs normal and SIGSTOP worker scenarios with the new value and reports the tracked worker absent when owner stop returns.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The fix addresses a macOS worker-lifecycle defect that can leave orphaned processes after app-managed restarts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 changed production owner is the macOS worker launch environment. The supplied exact-head GitHub-hosted packaged-worker evidence runs normal and SIGSTOP worker scenarios with the new value and reports the tracked worker absent when owner stop returns.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the macOS worker launch environment. The supplied exact-head GitHub-hosted packaged-worker evidence runs normal and SIGSTOP worker scenarios with the new value and reports the tracked worker absent when owner stop returns.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: 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 (5 earlier review cycles)
  • reviewed 2026-09-01T23:51:05.241Z sha be2afb9 :: needs real behavior proof before merge. :: [P1] Contain the detached Codex app-server during worker shutdown
  • reviewed 2026-09-02T00:10:17.729Z sha be2afb9 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-03T02:18:57.511Z sha e740e49 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-03T03:08:51.855Z sha e740e49 :: blocked before merge. :: [P1] Preserve macOS TLS defaults before disabling respawn
  • reviewed 2026-09-03T03:42:00.574Z sha 1dd2887 :: blocked before merge. :: [P1] Preserve macOS TLS defaults before disabling respawn

@Colton-Harris Colton-Harris changed the title fix(macos): node-host worker and its codex app-server outlive every worker restart fix(macos): node-host worker escapes the app's process group and outlives every worker restart Sep 2, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 2, 2026
@steipete steipete self-assigned this Sep 3, 2026
Preserve the contributor's no-respawn repair at the MacNodeHostWorker launch
owner and the packaged verifier. ManagedProcess owns the direct process group;
CLI startup respawn otherwise puts the actual worker in a separate session.
The existing OPENCLAW_NO_RESPAWN contract keeps the packaged worker in-process.

GitHub macOS baseline proof reproduced a SIGSTOP worker surviving after its
launcher was reaped. The launch-environment regression failed with exit46,
26 controls passed, and exact worker cleanup succeeded. The outer expected-RED
command's closure receipt remains unconfirmed; its namespace was retained.
Fresh candidate build, package and native lifecycle proof run on GitHub CI.

Non-test growth is six lines: one existing-contract assignment and two invariant
comment lines at each launch site. No new option or process supervisor is added.
The permanent test is net+1. Contributor ancestry is preserved.

Co-authored-by: Colton Harris <[email protected]>
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 3, 2026
Preserve the reviewed worker containment repair and contributor ancestry while integrating current main build fixes for exact-head verification.
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 3, 2026
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

The latest TLS finding has a false premise at the exact reviewed head. buildCliRespawnPlan calls resolveNodeStartupTlsEnvironment with includeDarwinDefaults: false and reads only NODE_EXTRA_CA_CERTS (entry.respawn.ts:126–132). Its fallback CA discovery explicitly returns undefined on Darwin (node-extra-ca-certs.ts:47–50). The entrypoint passes no override into this plan. That path did not supply either Darwin default before this PR.

The existing bootstrap test explicitly expects both values to be undefined when that option is false (node-startup-env.test.ts). This opt-out was preserved deliberately during the TLS planner refactor; its predecessor also used Linux-only discovery. These startup files are unchanged between the tested baseline, integrated main, this candidate, and the review's cited main.

The launchd service owner separately opts into the Darwin defaults. It is not on the app-owned worker's launch path. The app retains inherited and explicit environment values, including CA settings, before assigning no-respawn (MacNodeHostWorker.swift:403–414). Adding service defaults here would introduce a separate policy change, not preserve a default lost by this patch. That app-versus-service policy difference remains a named follow-up; this PR makes no new private-CA connectivity claim.

Disposition: skip the requested TLS assignments because they would change pre-existing behavior without the claimed regression. Keep the single process-group ownership repair. Its +3 app lines are one existing-contract assignment and two invariant comments; tooling mirrors that assignment, with +1 net test line.

The refreshed packaged macOS proof passed all 27 owner tests and both actual worker scenarios. Both normal and SIGSTOP workers were absent when stop returned, with exact process identity, source/runtime integrity and cleanup verified. Exact-head GitHub CI passed 120 jobs, including all five Mac jobs. The PR body contains the full before/after evidence and its limits.

@clawsweeper

clawsweeper Bot commented Sep 3, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 3, 2026
@steipete
steipete merged commit 8a92657 into openclaw:main Sep 3, 2026
205 of 324 checks passed
@steipete

steipete commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
…up (openclaw#135663)

MacNodeHostWorker launches `openclaw node worker` under ManagedProcess, which
owns the child by process group (SIGTERM -pgid, 250 ms, SIGKILL -pgid). The
CLI startup respawn re-executes the real worker with detached: true (setsid),
so the app only ever owned the respawn wrapper. When the worker did not exit
on the forwarded SIGTERM, the app's SIGKILL escalation killed the wrapper and
orphaned the worker together with its codex app-server child.

Set OPENCLAW_NO_RESPAWN=1 on the worker launch, matching the gateway's own
node-worker supervisor, so the worker stays in the owned group. The package
proof harness uses the same launch shape so requireProcessTreeExit proves
the real worker exited, not only the wrapper.

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

Labels

app: macos App: macos 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. scripts Repository scripts size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants