Repository navigation
feat(exec): keep durable background commands running across Gateway restarts on macOS - #197474
Conversation
… 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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
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.
|
Codex review: blocked before merge. What this changesAdds 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.
Review scores
ProductKind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete 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 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +464, Tests +174, Docs +19, Other +2. Total +659 across 17 files. Added test files: 1. View PR surface stats
Preflight sourceSource 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
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (4 earlier review cycles)
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).
|
macOS runtime and stored-data checks passed at
The latest-stable data check used npm 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 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
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.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…rom-sbxd6n # Conflicts: # docs/gateway/background-process.md
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
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).
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…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).
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: trueand 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):
launchctl list; the run settles as outcome unknown once the group ends.Evidence
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).efb41c8in 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.