Repository navigation
fix(macos): app restarts a slow-starting gateway in a loop after reboot - #158954
Conversation
A launchd PID the app did not install (started at login after a reboot, or by a repair) had no fresh-install evidence, so its readiness never extended past the first 6s window. The timeout armed a forced LaunchAgent repair, and the reinstall SIGTERMed the gateway mid-startup; every slow cold start hit the same path, looping until the app was quit. Let an unchanged launchd PID that still owns the port use the same bounded startupMigrationTolerance budget as a fresh install. A PID that changes or loses the port keeps today's behavior, and a PID still unready after the budget is still repaired. Fixes openclaw#158936
|
🦞👀 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. |
|
Codex review: blocked before merge. Reviewed September 28, 2026, 6:57 PM ET / 22:57 UTC (Revision 4). ClawSweeper reviewWhat this changesThe macOS app gives an unchanged launchd Gateway process up to 300 seconds to become ready after a cold start, with tests for recovery, timeout, and PID replacement. Regression provenancePossible regression — suspected (failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 3 items remain This PR remains necessary: current main still denies extended readiness to a reused launchd Gateway. The latest commit addresses the prior 120-second finding. The remaining choice is whether delaying repair of a same-PID but wedged Gateway for up to 300 seconds is acceptable. Priority: P0 Review scores
Verification
How this fits togetherThe macOS app checks the health of a Gateway started by launchd. Its readiness result determines whether the app attaches to that process or records a failure that can lead to LaunchAgent repair. flowchart LR
A[App starts or reconnects] --> B[Inspect launchd Gateway]
B --> C[Probe Gateway health]
C --> D{Ready?}
D -->|Yes| E[Use running Gateway]
D -->|No| F{Same launchd PID within budget?}
F -->|Yes| C
F -->|No| G[Record failure for repair]
Decision needed
Why: The real reboot took about 139 seconds, while the new 300-second bound also changes recovery time for an unhealthy process; choosing that operator tradeoff requires macOS lifecycle ownership. Before merge
Agent review detailsSecurityNone. PR surfaceOther +251. Total +251 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep bounded grace for the same launchd PID, recheck it throughout the wait, and surface a clear recovery state when the budget expires. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main denies extended readiness to a reused launchd PID, and the linked issue supplies a matching reboot and SIGTERM trace. This read-only review did not run the native app. Is this the best way to solve the issue? Yes, the patch changes the macOS readiness owner and preserves a bounded repair path. The 300-second recovery tradeoff still needs owner acceptance. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0ce096721a54. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
Address review on openclaw#158954: a reused PID's startup grace no longer becomes standing grace after the first extension, so a PID replaced during the wait stops extending at the next deadline. Fresh installs and responsive progress keep their existing standing grace. Gate the cold-start regression test on the first launchd inspection instead of a wall-clock sleep, add coverage for a PID replaced after its first extension, and drop the unused setProjectRoot/projectRootPath wrappers the dead-code scan flags on this file.
A real reboot on this branch took about 139s to reach ready, past the 120s first-run budget the reused-PID path shared. The timeout left repair evidence for a gateway that was still starting. Reused launchd PIDs now probe through their own 300s budget; the PID is still re-proven against launchd at every deadline, so a replaced or dead PID loses it at once.
|
@steipete since you've been in Where it stands:
The one open item is an owner call: a same-PID gateway whose health RPC is wedged now waits up to 300s before repair, instead of being repaired after the first 6s window. A PID that exits, gets replaced, or loses the port still fails at the next deadline, so the longer wait only covers a process that is alive and still holding the port. If you'd prefer a different bound or a progress-based signal instead, I'm happy to change it. |
The cold-start tests introduced in 418f22b (#158954) still referenced setTestingLastFailureReason and the bundlePath argument. Those were intentionally removed by 6cc8e7f (#163372) and 669db5d (#160710). Use the same direct property writes and port-only calls as the sibling tests, preserving all assertions.
…ot (#158954) * fix(macos): give reused launchd gateways the cold-start readiness budget A launchd PID the app did not install (started at login after a reboot, or by a repair) had no fresh-install evidence, so its readiness never extended past the first 6s window. The timeout armed a forced LaunchAgent repair, and the reinstall SIGTERMed the gateway mid-startup; every slow cold start hit the same path, looping until the app was quit. Let an unchanged launchd PID that still owns the port use the same bounded startupMigrationTolerance budget as a fresh install. A PID that changes or loses the port keeps today's behavior, and a PID still unready after the budget is still repaired. Fixes #158936 * fix(macos): re-prove a reused launchd PID at every readiness extension Address review on #158954: a reused PID's startup grace no longer becomes standing grace after the first extension, so a PID replaced during the wait stops extending at the next deadline. Fresh installs and responsive progress keep their existing standing grace. Gate the cold-start regression test on the first launchd inspection instead of a wall-clock sleep, add coverage for a PID replaced after its first extension, and drop the unused setProjectRoot/projectRootPath wrappers the dead-code scan flags on this file. * fix(macos): give reused launchd gateways a reboot-sized readiness budget A real reboot on this branch took about 139s to reach ready, past the 120s first-run budget the reused-PID path shared. The timeout left repair evidence for a gateway that was still starting. Reused launchd PIDs now probe through their own 300s budget; the PID is still re-proven against launchd at every deadline, so a replaced or dead PID loses it at once. (cherry picked from commit 418f22b) Backport adaptations: preserve release child readiness grace, use the current port-only launch-agent API, and assign the writable failure field. (cherry picked from commit a094425f4b96b6013cd0cb029df96123b5472c61)
…ot (openclaw#158954) * fix(macos): give reused launchd gateways the cold-start readiness budget A launchd PID the app did not install (started at login after a reboot, or by a repair) had no fresh-install evidence, so its readiness never extended past the first 6s window. The timeout armed a forced LaunchAgent repair, and the reinstall SIGTERMed the gateway mid-startup; every slow cold start hit the same path, looping until the app was quit. Let an unchanged launchd PID that still owns the port use the same bounded startupMigrationTolerance budget as a fresh install. A PID that changes or loses the port keeps today's behavior, and a PID still unready after the budget is still repaired. Fixes openclaw#158936 * fix(macos): re-prove a reused launchd PID at every readiness extension Address review on openclaw#158954: a reused PID's startup grace no longer becomes standing grace after the first extension, so a PID replaced during the wait stops extending at the next deadline. Fresh installs and responsive progress keep their existing standing grace. Gate the cold-start regression test on the first launchd inspection instead of a wall-clock sleep, add coverage for a PID replaced after its first extension, and drop the unused setProjectRoot/projectRootPath wrappers the dead-code scan flags on this file. * fix(macos): give reused launchd gateways a reboot-sized readiness budget A real reboot on this branch took about 139s to reach ready, past the 120s first-run budget the reused-PID path shared. The timeout left repair evidence for a gateway that was still starting. Reused launchd PIDs now probe through their own 300s budget; the PID is still re-proven against launchd at every deadline, so a replaced or dead PID loses it at once.
Complete the readiness authorization tuple introduced by bac884e (openclaw#158954). App-owned children retain their existing standing grace, while every extension still checks the current generation and child PID. Reused launchd PIDs keep the new per-deadline proof requirement.
The cold-start tests introduced in bac884e (openclaw#158954) still referenced setTestingLastFailureReason and the bundlePath argument. Those were intentionally removed by 9c6018f (openclaw#163372) and 4e79f38 (openclaw#160710). Use the same direct property writes and port-only calls as the sibling tests, preserving all assertions.
Backport openclaw#158954 with branch-local readiness coverage. Co-authored-by: RomneyDa <[email protected]>
Backport the released follow-up to the openclaw#158954 readiness repair. Co-authored-by: RomneyDa <[email protected]>
Closes #158936
What Problem This Solves
Fixes: OpenClaw.app kills and reinstalls a gateway that is still legitimately starting whenever a cold start (for example after a reboot) takes longer than the app's 6-second readiness window, looping until the app is quit.
User Impact
User impact: a slow-starting gateway that launchd started on its own is left to finish starting (up to 300s, while the same PID keeps owning the port) instead of being SIGTERMed and reinstalled every cycle. A gateway that is still unready after that budget is still repaired.
Tradeoff: an unchanged launchd PID that owns the port but has a wedged health RPC is now repaired after up to 300s instead of right after the first window. A PID that exits, is replaced, or loses the port still fails at the next 6s deadline, so the longer wait only applies to a process that is still alive and still holding the port.
Why This Change Was Made
The readiness deadline could only be extended past the first window with fresh-install evidence (or a responsive "still starting" reply). A PID launchd starts at login, or one started by a repair, never has install evidence, so the first window timed out, recorded that PID as failed, and the next enable request force-reinstalled it. The new process hit the same path, which produced the loop in the report.
The extension authorization now also accepts an unchanged launchd PID that still owns the port (or while nothing is listening yet), bounded by a new
reusedLaunchdColdStartTolerance(300s). Fresh installs keepstartupMigrationTolerance(120s). The reused budget started out shared with the fresh-install one; the reboot trace below measured a ~139s cold start that ran past 120s, so it now has its own, sized with about 2x headroom over that measurement for slower hardware. Unlike fresh-install grace, this grace is not standing: the PID is re-proven against launchd at every deadline, so a PID that exits or is replaced mid-wait stops extending at the next deadline. A PID that changed or lost the port gets no grace and keeps today's behavior.Evidence
New
GatewayProcessManagerTestscases, driving the launchd readiness path without install evidence:reused launchd gateway gets the cold-start budget before repair: the first health probe stalls past the window and a later probe succeeds. Onmainthis fails withGateway did not start in timeand arms repair. With this change it ends.running, records no failure, and the next enable request does not reinstall.reused launchd gateway outlasting the first-run budget is not repaired: every health probe hangs; the test releases them only after the sixth launchd inspection, which is past the fresh-install budget passed to the hook (0.2s) but inside the reused budget (5s). It ends.runningwith no repair evidence and no reinstall. With a shared budget (the previous head), the attempt fails before that point, which is the case the reboot trace hit.reused launchd gateway still repairs after its bounded budget: a never-ready reused PID still fails after the budget, and the next enable request still installs once.changed launchd PID does not inherit the cold-start budget: launchd now reports a different PID and nothing owns the port, so there is no extension and no repair evidence.reused launchd PID replaced during its grace loses the grace: 4242 earns the first extension, then launchd reports 4243; the next deadline re-checks and stops (3 launchd inspections instead of probing 4242 until the budget).The cold-start case releases the first health response only after the first launchd inspection, which happens only once the first window has timed out, so it cannot pass without exercising an extension.
Existing fresh-install, repair, and deadline tests are unchanged.
macos-swift (tests)on the first head (5f722d3):Test run with 2294 tests in 263 suites passed. The follow-up commit also removes the two unusedsetProjectRoot/projectRootPathwrappers thatScan macOS dead codeflags on this file.Real behavior proof (macOS reboot, reporter's host)
The reporter of #158936 (@cjn119-ui) built this branch at
f03c992f1ceon their Mac, ran it as the Local-mode app against the same LaunchAgent, and rebooted (comment). The cold start was slow again (~2m19s, slow SQLite validation, same as the original report), and the gateway was left to finish.gateway.log: one continuous run, a single PID, no SIGTERM in between:App unified log (
log show --last 15m --predicate 'process == "OpenClaw"') over the same window:There are no
repairingorenabling launchdlines anywhere in that window. The app kept probing the same reused PID instead of killing and reinstalling it, which is what it did on every cycle before this change.That trace ran on
f03c992f1ce, where the reused-PID path still shared the 120s budget: the17:31:22 … did not start in timeline shows it ran out about 8s beforeready. The gateway got there before the next enable request acted on that failure, but a slower start could have been reinstalled.3d7e30e8ba7addresses exactly that by giving this path its own 300s budget (see above); the trace otherwise shows the intended behavior (one PID, no repair).The tests still run only in the
macos-swiftCI lane (I don't have a macOS host); the runtime proof above is the reporter's, on the previous head.