Skip to content

feat(exec): keep durable background commands running across Gateway restarts on macOS - #197474

Merged
hannesrudolph merged 9 commits into
openclaw:mainfrom
daniel-lxs:move-dan-s-workflow-from-sbxd6n
Nov 14, 2026
Merged

hannesrudolph merged 9 commits into
openclaw:mainfrom
daniel-lxs:move-dan-s-workflow-from-sbxd6n

Conversation

@daniel-lxs

@daniel-lxs daniel-lxs commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #197443

What Problem This Solves

Durable background commands are unavailable on macOS, preventing sessions from keeping work running across Gateway restarts.

User Impact

macOS users can run Gateway-host background commands with durable: true and resume observing their output and completion after a Gateway restart. This requires a logged-in GUI session; logout and reboot still end the jobs. Descendants that leave the command's process group are outside its timeout and stop handling.

Why This Change Was Made

Use transient launchd jobs behind the existing durable-process registry. A wrapper tracks the command's process group, enforces its timeout, and records its outcome and duration. Failed job observations remain unknown and are retried. The launch environment is stored in a private spec file and removed before command execution. Doctor excludes these jobs from its stray-service scan.

Accepted edge cases, kept simple on purpose (named in code comments):

  • If the wrapper is killed from outside while its command runs, OpenClaw does not signal the orphaned process group itself. Stop reports "not confirmed" and points at launchctl list; the run settles as outcome unknown once the group ends.
  • If the wrapper cannot write its status file after starting the command (for example, a full disk), the wrapper exits and the command runs on without supervision. OpenClaw reports the outcome as unknown and asks to check output and side effects before repeating work.
  • The existing completion-notification crash window remains: a Gateway crash immediately after recording notification settlement can lose the completion wake.

Evidence

  • Targeted tests at this head: src/agents/bash-process-launchd.test.ts, 4 passed. The file no longer sleeps in the test process; the wrapper case still starts real subprocesses (a 0.2 s background child and a 0.3 s timeout).
  • The PR adds 154 net test lines, under the 400-line allowance, so no test-lines allocation record is needed.
  • Live macOS run, recorded at efb41c8 in a logged-in GUI LaunchAgent on macOS 26.6.2: run summary and durable-evidence.json. A durable command survives a Gateway restart and delivers its completion wake; a command completes while the Gateway is down; the wrapper enforces the timeout while the Gateway is down and keeps the measured duration; killing the wrapper leaves the command running and later reports an unknown outcome; another session cannot stop the job, the owning session can.
  • Not run live at this head: the stop loop was simplified and the two edge-case branches above were removed after that run. Broad CI, Linux live execution, logout/reboot behavior, and macOS privacy-permission behavior were not checked here.

… macOS

Durable exec ran only under Linux systemd. On macOS each durable command now
runs as a transient launchd job in the user's gui domain, behind the same five
supervisor operations the systemd backend provides; the registry, ownership
store, adoption and owning-session wake are unchanged.

- A small dependency-free wrapper started by launchd runs the command in its
  own process group, records that group, waits for it to empty, enforces the
  timeout and writes the outcome (with its measured duration) to a status file.
  launchd's own last-exit status is only fully exposed by `launchctl print`,
  which Apple documents as not an API, so the outcome comes from the wrapper.
- Job state is read from bare `launchctl list` columns. A failed or unparsable
  listing is unknown and retried, never missing or exited. Loaded without a
  PID or status file means starting.
- If the wrapper dies, the recorded group is checked (EPERM counts as alive)
  before an unknown outcome is recorded; kill signals that group directly.
- Durable exec is refused unless `launchctl managername` reports Aqua.
- The job's environment goes to a 0600 spec file the wrapper deletes before
  starting the command; the plist (mode 0644) carries no command or env.
- Doctor's stray launchd job scan skips durable job labels.
- The reconciler uses a supervisor-measured duration when one exists.

Known gap, not changed here: a completion wake can be lost if the Gateway
crashes right after notificationSettled is recorded.
- Treat a recorded process group from before the last boot as gone, so a
  reused id never reads as this job or receives its kill.
- Only declare the wrapper lost when it was already seen running; one that
  first appears between the two reads may just have finished.
- Stop waits through the starting window instead of signalling nothing.
- The wrapper kills the command and fails visibly when it cannot record the
  process group, and writes the start error to the job log.
@clawsweeper

clawsweeper Bot commented Nov 12, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: 1744c32669242179f4c1e6a2ba14245bdb3004d3

These sensitive security changes were made:

  • src/agents/exec-tool-target-pinning.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

The systemd and launchd backends exported the same six function names,
which the export-name collision guard rejects. Each backend now exports a
single DurableProcessSupervisor object; the operations are members of that
one contract, which bash-process-durable selects by platform.
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Adds launchd supervision so macOS durable background commands retain output, process controls, and completion notifications across Gateway restarts.

Example: A logged-in macOS user starts an eight-second command with background:true and durable:true.

  • Before: Durable execution is rejected because the host is not Linux.
  • After: The command survives a Gateway restart, and its saved output and completion return to the owning session.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The native behavior is well evidenced and the patch has no actionable findings, but product acceptance of macOS support remains undecided.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The inspected linked artifact exercises the built Gateway and real launchd on macOS 26.6.2 with a scripted model transport, recording restart survival, downtime completion, timeout enforcement, scoped stopping, and wrapper-loss recovery; the relevant production code is unchanged at the reviewed head.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Mac users cannot keep session-owned commands running through a Gateway restart while retaining process controls and automatic completion.
Reason: The implementation has clear user value and fits existing ownership, but supporting a new host platform and its different lifecycle guarantees requires an owner decision.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR supplies a distinct macOS capability with sufficient runtime evidence and no actionable introduced findings; product direction and current-head security approval remain unresolved.

Priority: P2
Reviewed head: 4af9f2b5a696246db4bb7a059f5fd24c93b0d1de
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Gateway-hosted macOS durable exec be supported with GUI-session lifetime, process-group containment, and separate macOS privacy permissions?
  • Recommendation: Accept the scoped macOS backend: Support the existing durable exec contract through launchd with the documented logout, reboot, descendant, and privacy-permission limits.
  • Why: This expands an intentional Linux-only capability, and no written owner approval of this platform contract appears in this PR or its linked issue.

Before merge

  • Await maintainer action - An authorized maintainer must review the sensitive change and approve revision 4af9f2b through the repository's security approval command.

Findings

None.

Agent review details

How this fits together

The exec tool prepares authorized commands, the existing durable registry retains ownership and outcomes, and a platform supervisor runs the physical process independently of the Gateway.

flowchart LR
  A[Session exec request] --> B[Exec policy and launch authority]
  B --> C[Durable process registry]
  C --> D[SQLite ownership and outcomes]
  C --> E[Platform supervisor]
  E --> F[launchd wrapper and command group]
  F --> G[Saved output and status]
  G --> C
  C --> H[Owning session completion]
Loading

Technical review

Best possible solution:

Extend the existing durable process owner with the proposed native macOS backend if its documented supervision limits are accepted.

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

Current main explicitly rejects Darwin durable execution; the supplied native Gateway artifact demonstrates the requested behavior after the change, and no target code was executed during this review.

Is this the best way to solve the issue?

The implementation follows the smallest coherent extension: one platform supervisor contract, a launchd adapter and necessary wrapper, with existing persistence, ownership, and completion semantics preserved.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 05b455331de7.

Provenance checked

  • Durable execution platform boundary and registry integration changes intended behavior with a stated reason (20c1a15: The Linux foundation deliberately used systemd supervision and rejected unsupported hosts rather than silently degrading durability.)
  • Systemd control transport and resource limits keeps the original intent (feat(exec): keep durable session processes across Gateway restarts #188465: Service-manager calls use the ordinary process supervisor and launch authority; subsequent shared-memory accounting and zero core limits protect host execution.)
  • Foreign launchd job diagnostics and repair keeps the original intent (cd98a01: Doctor diagnoses verified stray Gateway lifecycle jobs while preserving managed services and unrelated jobs; excluding registry-owned durable jobs maintains that separation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 20c1a15 adds src/agents/bash-process-durable.ts:161 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 20c1a15bb56d; files: src/agents/bash-process-durable.ts)

PR surface

Source +464, Tests +174, Docs +19, Other +2. Total +659 across 17 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 11 546 82 +464
Tests 3 200 26 +174
Docs 2 35 16 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 17 783 124 +659

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test growth Production +464 net lines; tests +174 net lines The growth supplies a native launchd adapter and standalone lifetime wrapper while reusing existing registry, storage, and notification owners.

Labels

Label changes:

  • add status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.

Label justifications:

  • P2: This is a useful, opt-in platform extension for long-running commands, with no demonstrated urgent regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (4 earlier review cycles)
  • reviewed 2026-11-12T02:59:35.851Z sha 72f06a1 :: needs real behavior proof before merge. :: [P2] Account for the added tests in the test-line budget
  • reviewed 2026-11-12T21:53:35.769Z sha efb41c8 :: blocked before merge. :: none
  • reviewed 2026-11-12T22:01:45.053Z sha efb41c8 :: blocked before merge. :: [P3] Update the remaining Linux-only durable-exec guidance
  • reviewed 2026-11-13T02:25:23.535Z sha 9823890 :: blocked before merge. :: none

Reviewed November 12, 2026, 9:33 PM ET / November 13, 2026, 02:33 UTC (Revision 5).

Keep the stable timeout assertion (SIGTERM or SIGKILL) and allocate the
remaining 176 test lines for the macOS launchd supervisor: observation
states, wrapper exit, process-group and timeout handling, and the three
regressions found in review.
The mock-export ratchet requires first-party mock factories to spread the
real module. Restore the importOriginal spread dropped while compacting,
and match the test-line allocation to the file's growth (174).
@daniel-lxs

Copy link
Copy Markdown
Member Author

macOS runtime and stored-data checks passed at efb41c8ce66969b0fead8f2190c8dc6984db50eb, using the built Gateway runtime in a logged-in GUI LaunchAgent on macOS 26.6.2 / Node 24.21.0.

  • An authorized durable command launched and consumed its private launch spec. Another session’s stop request was rejected while the job remained alive; the owning session could stop it.
  • A command survived a Gateway PID change (5756 → 5875) and delivered its completion output to the owning session.
  • A command completed while the Gateway was stopped, and its completion/output were recovered on return.
  • The wrapper enforced an eight-second timeout while the Gateway was stopped, recording overall-timeout, SIGTERM, and an 8,006 ms duration.
  • Killing the wrapper left the command’s process group alive. Its eventual output was retained and the outcome was reported as unknown.

The latest-stable data check used npm 2026.11.3 (847611d) to create a card with notes, comment, proof, and artifact, plus a stored conversation. After a manual cutover with the same state/config and the candidate’s native Doctor, the card compared equal and the conversation remained readable. Automatic updater execution was not tested.

Still open: final-effect launch-authority revocation proof. A calibrated native syscall trace observed bootstrap and the command marker in all three Stop attempts. An accepted chat.abort does not establish revocation of the retained launch authority: background exec is documented to survive request Stop. This probe therefore establishes neither rejection after true revocation nor a product defect. No delay shim or modified production code was substituted for that proof.

The focused launchd, systemd, and exec-target suites passed: 47 tests across three files. The model transport was a local scripted stand-in. Broad CI, a live external model, Linux runtime, and logout/reboot behavior were not checked. Maintainer security approval remains separate and unchanged.

durable-evidence.json

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Nov 12, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 12, 2026
The page introduction, durable parameter row, restart and shutdown notes
still named only Linux/systemd. Name both supervisors, and mark the
systemd-only timeout and memory details as Linux.
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 13, 2026
…rom-sbxd6n

# Conflicts:
#	docs/gateway/background-process.md
@clawsweeper clawsweeper Bot removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 13, 2026
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 13, 2026
Stop no longer signals an orphaned process group from the Gateway, and the
wrapper no longer kills its command when it cannot record the group. Both
are accepted edge cases named in comments and docs; the run settles as
outcome unknown. Removes the sleeping test and the now-unneeded test-lines
allocation (the PR is under the 400-line allowance).
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 14, 2026
@hannesrudolph
hannesrudolph merged commit fafac70 into openclaw:main Nov 14, 2026
54 of 59 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…estarts on macOS (openclaw#197474)

* feat(exec): keep durable session processes across Gateway restarts on macOS

Durable exec ran only under Linux systemd. On macOS each durable command now
runs as a transient launchd job in the user's gui domain, behind the same five
supervisor operations the systemd backend provides; the registry, ownership
store, adoption and owning-session wake are unchanged.

- A small dependency-free wrapper started by launchd runs the command in its
  own process group, records that group, waits for it to empty, enforces the
  timeout and writes the outcome (with its measured duration) to a status file.
  launchd's own last-exit status is only fully exposed by `launchctl print`,
  which Apple documents as not an API, so the outcome comes from the wrapper.
- Job state is read from bare `launchctl list` columns. A failed or unparsable
  listing is unknown and retried, never missing or exited. Loaded without a
  PID or status file means starting.
- If the wrapper dies, the recorded group is checked (EPERM counts as alive)
  before an unknown outcome is recorded; kill signals that group directly.
- Durable exec is refused unless `launchctl managername` reports Aqua.
- The job's environment goes to a 0600 spec file the wrapper deletes before
  starting the command; the plist (mode 0644) carries no command or env.
- Doctor's stray launchd job scan skips durable job labels.
- The reconciler uses a supervisor-measured duration when one exists.

Known gap, not changed here: a completion wake can be lost if the Gateway
crashes right after notificationSettled is recorded.

* fix(exec): harden macOS durable job observation and stop

- Treat a recorded process group from before the last boot as gone, so a
  reused id never reads as this job or receives its kill.
- Only declare the wrapper lost when it was already seen running; one that
  first appears between the two reads may just have finished.
- Stop waits through the starting window instead of signalling nothing.
- The wrapper kills the command and fails visibly when it cannot record the
  process group, and writes the start error to the job log.

* refactor(exec): give durable supervisors one shared contract

The systemd and launchd backends exported the same six function names,
which the export-name collision guard rejects. Each backend now exports a
single DurableProcessSupervisor object; the operations are members of that
one contract, which bash-process-durable selects by platform.

* test(exec): compact macOS durable supervisor tests

* test(exec): allocate macOS durable supervisor test lines

Keep the stable timeout assertion (SIGTERM or SIGKILL) and allocate the
remaining 176 test lines for the macOS launchd supervisor: observation
states, wrapper exit, process-group and timeout handling, and the three
regressions found in review.

* test(exec): preserve real executable-path exports in launchd test mock

The mock-export ratchet requires first-party mock factories to spread the
real module. Restore the importOriginal spread dropped while compacting,
and match the test-line allocation to the file's growth (174).

* docs(exec): describe durable processes on both Linux and macOS

The page introduction, durable parameter row, restart and shutdown notes
still named only Linux/systemd. Name both supervisors, and mark the
systemd-only timeout and memory details as Linux.

* refactor(exec): drop rare-race hardening from macOS durable supervisor

Stop no longer signals an orphaned process group from the Gateway, and the
wrapper no longer kills its command when it cannot record the group. Both
are accepted edge cases named in comments and docs; the run settles as
outcome unknown. Removes the sleeping test and the now-unneeded test-lines
allocation (the PR is under the 400-line allowance).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime 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. security-review-required security-sensitive-changed size: L status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support restart-surviving durable exec and owning-session completion wakeups on macOS

2 participants