Repository navigation
fix: restore macOS Gateways after Doctor shutdown contention - #153167
Conversation
|
🦞👀 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 21, 2026, 11:19 PM ET / September 22, 2026, 03:19 UTC (Revision 12). ClawSweeper reviewWhat this changesDoctor waits for stopped Gateways to release state ownership and restores canceled repairs under retained service custody, while macOS activation recovers absent LaunchAgents after ambiguous failures. Merge readiness⛔ Blocked before merge - 4 items remain This remains a useful, protected repair. The previous cleanup-uncertainty finding is resolved, and no new blocking code defect was found; native restoration and upgrade coverage still need a scoped disposition. Priority: P1 Review scores
Verification
How this fits togetherDoctor coordinates offline repairs with the running Gateway and its operating-system service manager. Its maintenance owner stops the service, acquires exclusive state access, and restores and verifies the Gateway afterward. flowchart TD
A[Doctor repair request] --> B[Inspect service ownership]
B --> C[Stop under native custody]
C --> D[Wait for state ownership]
D --> E{Repair admitted?}
E -->|Yes| F[Repair state]
E -->|No| G[Restore unchanged service]
F --> G
G --> H[Verify Gateway readiness]
Decision needed
Why: Repository policy requires platform and published-driver proof for this lifecycle change; the supplied evidence names those gaps but contains no acceptance covering this PR. Before merge
Agent review detailsSecurityNone. PR surfaceSource +194, Tests +348, Docs +15. Total +557 across 12 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep restoration in the existing maintenance and native-service owners, with verified recovery for installed Gateways and an explicit disposition of the remaining platform and upgrade coverage. Do we have a high-confidence way to reproduce the issue? Yes, from source: an ambiguous kickstart failure followed by successful registration recovery still throws on current main, and the reporter supplied a concrete shutdown timing trace. This read-only review did not execute the scenario. Is this the best way to solve the issue? Yes at the code level: the patch extends the existing maintenance, lock, and launchd owners while preserving ordinary post-repair admission; native and upgrade validation remain incomplete. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e078c04a72bf. LabelsLabel 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 (11 earlier review cycles; latest 8 shown)
|
4a2ebec to
abca18a
Compare
abca18a to
5af2013
Compare
5af2013 to
d2425d1
Compare
Revalidate repair admission with both coordinators held and retain native stop custody through pre-repair compensation, including captured Windows recovery assertions and handle settlement. Probe ambiguous launchd kickstart failures so verified absent-job recovery completes while loaded-job errors retain their original detail. Thanks to @sasan1200 for the source review in #153173 and #153172 identifying these cases. Implemented independently with deterministic boundary regressions.
Complete the standalone repair-policy mock used by the native scratch-job proof after main added the deferred-repair predicate. Reserve a suite-owned free port for the mocked Gateway so a listener on port 18789 cannot trigger host-dependent owner-lease reads against the legacy fixture database. Retain the native job protections and database artifact assertions. Validation: both native scratch cases and all 50 maintenance revalidation cases pass independently; the complete requested selection passes 544 tests across 22 files. Production is unchanged from the previous PR patch replayed onto main.
06cb554 to
84f5002
Compare
…ock kill (#155278) Reuse the compiled cron fixture and join scheduler children before store cleanup. Preserve cross-process receipt/recovery assertions and expose exit signals. Related: #153167 Evidence: CI run 35659161173 / job 106530444451; five contended full-shard replays plus a 61-second completion-delay probe; check:changed and P1 review.
…ock kill (openclaw#155278) Reuse the compiled cron fixture and join scheduler children before store cleanup. Preserve cross-process receipt/recovery assertions and expose exit signals. Related: openclaw#153167 Evidence: CI run 35659161173 / job 106530444451; five contended full-shard replays plus a 61-second completion-delay probe; check:changed and P1 review.
…w#153167) * fix(doctor): restore Gateways after shutdown contention Wait for the stopped Gateway to release lifecycle ownership within the shared stop budget before state repair or recovery. Preserve partial-acquisition cleanup and route launchd activation failures through bootstrap recovery with explicit loaded-state diagnostics and live authority checks. Thanks @sagebhardt for the shutdown timing table. Fixes openclaw#153155. * fix(doctor): complete recovery after admission and kickstart failures Revalidate repair admission with both coordinators held and retain native stop custody through pre-repair compensation, including captured Windows recovery assertions and handle settlement. Probe ambiguous launchd kickstart failures so verified absent-job recovery completes while loaded-job errors retain their original detail. Thanks to @sasan1200 for the source review in openclaw#153173 and openclaw#153172 identifying these cases. Implemented independently with deterministic boundary regressions. * test(launchd): preserve policy through activation recovery * refactor(doctor): extract maintenance restoration owner * test(doctor): isolate launchd maintenance fixtures Complete the standalone repair-policy mock used by the native scratch-job proof after main added the deferred-repair predicate. Reserve a suite-owned free port for the mocked Gateway so a listener on port 18789 cannot trigger host-dependent owner-lease reads against the legacy fixture database. Retain the native job protections and database artifact assertions. Validation: both native scratch cases and all 50 maintenance revalidation cases pass independently; the complete requested selection passes 544 tests across 22 files. Production is unchanged from the previous PR patch replayed onto main. * style(doctor): order imports after maintenance rebase * fix(doctor): preserve restoration custody and shared stop deadline --------- Co-authored-by: Jason (Json) <[email protected]>
Fixes #153155
What Problem This Solves
Fixes Doctor repair stopping a healthy macOS Gateway and racing its shutdown, leaving the LaunchAgent unloaded or reporting failure after successful recovery. Thanks @sagebhardt for the timing table that identified restoration before the old process finished shutting down.
Thanks to @sasan1200 for the source review in #153173 and #153172 identifying admission loss during lifecycle drain and successful recovery from ambiguous launchd kickstart failures.
User Impact
Doctor waits for the stopped Gateway's lifecycle ownership within the existing shared service-stop budget. If a writer still owns state at the deadline, Doctor warns, restores the service, and refuses unsafe state repair. If repair admission changes before repair begins, Doctor reverses its own stop while its original native service custody remains valid.
On macOS, an ambiguous kickstart failure followed by a definite absent-job probe uses bootstrap recovery and completes normally when activation succeeds. A failure for a job that remains loaded stays visible. Failed activation attempts retain bootstrap compensation and explain the resulting loaded state and any manual recovery needed.
Why This Change Was Made
Port release does not prove lifecycle-coordinator release. The shared Doctor maintenance owner now drains ownership before rechecking repair admission with both coordinators held. It retains the original native service operation across stop, admission, and pre-repair compensation, reusing the existing restoration hook. Partial acquisitions are released; revoked native authority, changed service identity, and uncertain process cleanup remain refusals. Captured Windows recovery callbacks use the same pre-repair native assertion, and recovery handles are completed even when activation is refused. Normal post-repair finish still requires current update admission.
The launchd owner uses its existing typed presence probe to distinguish absent jobs from genuine loaded-job failures. Both start and restart share that decision. The shared 330-second stop deadline remains authoritative; no independent 20-second drain timer was added.
Systemd keeps its unit installed/enabled during stop; Scheduled Tasks retains registration and uses Doctor's existing autostart recovery. Both receive the shared ownership wait. Inconclusive restoration inspection from #153017 retains the selected restoration-admission assertion. The launchd stop handoff-authority change in #153020 is unchanged. Related: #152879, #146142.
The maintenance restoration-owner extraction is a pure move to satisfy the line-cap ratchet after the semantic merge.
Evidence
3d4033fbe0aca10c9eec45a7c088540607181d79; candidate84f5002de05a1949199953b660fafbf573619444. The 4,750-byte base-relative production interdiff versus06cb554f58ais confined tosrc/commands/doctor-maintenance.ts: preserve main's asynchronous foreground acquisition and post-await authority check, typed agent-lease admission, budget-refresh warnings, and unsafe-stop guidance within this PR's recovery flow. Both sets of settlement regressions remain. This is a semantic rebase requiring fresh maintainer review.tbx_01m32sky8wr5xtrswhg1czqj7y: 537 tests passed across 21 runnable Doctor-maintenance/launchd files; 32 native macOS cases in two files skipped on Linux. Test runner 144.07s; remote command including preparation 217.308s. Longest test 5.828s; largest file 33.408s summed test time. The merged settlement suite ran 26 tests in 0.121s summed test time; finish-revalidation ran 50 in 33.408s. Source treed1a31f9f553645a11097fd65ba919c2ba4b96975matches the final commit. Testbox workflow.check:changedpassed all selected steps on that Testbox in 30m43s, including production types, all 25 core test-type shards, lint (zero warnings/errors), and structural guards. A provider portal-sync timeout was reported after successful command completion; wrapper exit code remained 0. No failures were retried.Earlier evidence, before this semantic rebase:
Earlier rebase validation: all 544 tests across the 22
launchd*.test.tsanddoctor-maintenance*.test.tsfiles passed with--maxWorkers=1(1092.24s including shared preparation). Main's stop-verification and ancestry cases and this PR's activation-restoration cases are retained. Replaying the previous non-test patch onto the new base produces byte-identical production and docs files (empty interdiff).Fixed two fixture defects found by that run: the native scratch-job proof omitted
isServiceRepairDeferredfrom its standalone policy mock; the maintenance fixture hardcoded port 18789, so a built checkout could inspect an existing host listener and create WAL/SHM files in the legacy fixture before stop. The fixture now holds one free-port claim for the suite and uses it in commands and lease records. Existing assertions remain intact. Standalone proof: both native cases passed in 113.19s wall (0.91s test time), and all 50 revalidation cases passed in 115.98s wall. CI timing remains pending.Earlier branch proof: 285 selected tests passed: 197 launchd, 51 Doctor maintenance/revalidation/plugin-preflight, 33 managed-service handoff tests, and 4 Windows recovery-owner tests. The final Doctor/Windows rerun passed all 54 tests. Final reruns passed all 13 settlement tests and all 14 activation-table cases after test cleanup and fixture extraction. Coordinator drain and admission-loss tests use synthetic ticks, without wall-clock sleeps.
Nine independently authored comparison regressions failed on the prior head
370b97ab77b: three admission cases and six ambiguous-kickstart recovery cases. No contributor branch or tests were executed, and no contributor code was copied; the source-review credit above reflects adopted behavior.Earlier formatting and
git diff --checkpass. The prior production P1 review is preserved by the empty non-test interdiff.Earlier diff versus the rebase base: production +531/-372 lines (net +159); tests and test support +274/-67 (net +207); docs +15/-0.
Live Doctor-through-launchd and published-driver × candidate execution were not run. Doctor's
isDefaultInstallIdentitydeliberately skips native management for a relocated state directory or HOME, so a worktree-contained isolated state cannot exercise that CLI flow. No operator Gateway, canonical LaunchAgent, or real state was touched. Boundary proof is used for this gap; the affected launchd fallback also exists in the published v2026.9.5 source.Update behavior: candidate-side Doctor uses the existing repair and parent-activation contracts, with no new marker or driver requirement. Parent-owned activation remains with the installed updater; this change restores only a service Doctor itself stopped. Existing backup and rollback ownership is unchanged.