Repository navigation
fix(update): stop an uninspected predecessor Gateway before candidate Doctor - #156138
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: needs real behavior proof before merge. Reviewed September 23, 2026, 1:05 AM ET / 05:05 UTC (Revision 4). ClawSweeper reviewWhat this changesThe candidate updater stops a running predecessor Gateway before Doctor, records restoration information, and adjusts Linux service admission and stale-install draining. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked before merge - 9 items remain Keep open: the published-updater failure remains on current main, and this protected PR has useful work. Earlier fixes improved the patch, but recovery and service-identity defects remain. Priority: P1 Review scores
Verification
How this fits togetherThe installed updater delegates post-install maintenance to the candidate package. Candidate Doctor and finalization coordinate service shutdown, database maintenance, and restarting the updated Gateway. flowchart TD
A[Installed updater] --> B[Candidate Doctor]
B --> C[Check live authority and service ownership]
C --> D[Stop predecessor Gateway]
D --> E[Record stop in update ledger]
E --> F[Run Doctor maintenance]
F --> G[Candidate finalization]
G --> H[Restore matching Gateway service]
Before merge
Findings
Agent review detailsSecurityNeeds attention: The new delayed service handoff checks recorded identity after a reachable native stop. PR surfaceSource +370, Tests +441. Total +811 across 11 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep shutdown and restoration with the existing service owner, retain a durable matching-service receipt, and prove the published-driver handoff through successful recovery and rejected stale authority. Do we have a high-confidence way to reproduce the issue? Yes, source inspection establishes deterministic paths for inspected-parent restoration failure, mutation before identity comparison, and receipt eviction. Runtime reproduction was not executed in this read-only review. Is this the best way to solve the issue? The candidate-side repair is appropriate because the published updater cannot be changed, but the current implementation does not yet preserve recovery and service identity across the complete handoff. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2559458e2b4c. LabelsLabel changes: No label changes. Label justifications:
EvidenceSecurity concerns:
What 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)
|
… Doctor entrypoint
…store it under --no-restart, and admit activation past an unverifiable system probe
…nd admit past an unverifiable probe as a fallback
… and bound the delegated Doctor stop
…n-free identity match and keep its receipt through ledger compaction
|
Merged via squash.
|
… Doctor (openclaw#156138) ## What Problem This Solves Fixes: `openclaw update` from 2026.9.5 to the 2026.9.6 candidate fails at the post-install Doctor with `another OpenClaw process owns gateway-lifecycle` when the shipped 2026.9.5 updater could not inspect the managed Gateway service, and the package is rolled back. Release blocker for 2026.9.6 (Package Acceptance lane `update-first-hop-compat`, release-checks run 35803842673 attempts 1 and 2). ## User Impact User impact: operators on 2026.9.5 whose service manager cannot be inspected by the old updater can now update in place; the candidate stops the still-running predecessor Gateway before Doctor and the updated service is restarted afterwards. No change for updates where the old updater already inspected and stopped the service, or on Windows. Under `--no-restart` the shipped 2026.9.5 driver gives the delegated Doctor no restart consent, so a Gateway the candidate had to stop for Doctor is restarted on the updated installation with an advisory rather than left down. ## Why This Change Was Made - `src/infra/update-candidate-predecessor-stop.ts` (new): `stopSupervisedPredecessorGateway` runs in the candidate's `--doctor` entrypoint (`runDelegatedDoctor`), which is the step the immutable 2026.9.5 driver invokes as its post-verification Doctor and the step that fails in CI. When the current Gateway owner lease is `live` and `supervised`, it stops that predecessor through the candidate's service adapter (`maybeStopManagedServiceBeforeMutableUpdate`, phase `prepare`) under the composed executor + requester authority (`assertCurrent`, which throws `UpdateRequesterRevokedError` before any native mutation), then records `managed-service:candidate-stop` in the update-run ledger. A `foreground` owner keeps Doctor's existing wait. `adoptCandidateManagedServiceStop` runs in finalization: for a transferred uninspected `unavailable` verdict it re-inspects, adopts the ledger-recorded Doctor stop as `stopped`, and hands the state to `finishUpdate` so the existing restart path starts the updated service. Both paths are skipped on Windows so a candidate-created Scheduled Task suspension can never be dropped. The Doctor records a retained `finalize:predecessor-stop:<stoppedAtMs>:<managerUid>:<pid>:<fingerprint>` receipt in the `onStopped` callback (the native mutation boundary); the identity lives in the step key because published parents strip `detail` from retained steps under the ledger byte limit. Finalization processes that receipt independently of the legacy verdict: it inspects without mutating (`phase: "inspect"`), adopts the stop only when the current service reports the same fingerprint and manager uid, leaves a replaced service untouched with an `exitCode: 1` advisory step, does not stop again a same-identity service that was started after Doctor, and restores (force-restarts, with an advisory) when the run was `--no-restart`, including the case where the old updater had inspected an owned service. - `src/infra/update-migrated-finalize.worker.ts`: wires the two hooks above; the finalization hook revalidates the requester (`run.requesterAuthority.isCurrent()`) as well as the executor fence before native mutation. - `src/cli/update-cli/update-command-legacy-service-stop.ts`: the decision helper (`needsCandidateManagedServiceStop`). - `src/daemon/systemd-scope.ts` / `systemd-lifecycle.ts`: start and restart admission use the same rule (`assertNoSystemGatewayOwnershipForActivation`), so the updated service can start under exactly the condition that admitted the stop; a proven system owner still refuses. - `src/daemon/systemd-definition-mutation.ts`: when the system-scope ownership probe is unverifiable (`SERVICE_DEFINITION_UNKNOWN [system-ownership-unverified]`, seen in the CI log) and the caller requires a loaded unit, a loaded user unit whose artifacts this account owns keeps its `writable` capability. The refusal is unchanged without `requireLoaded`, for a system-owned unit, and when the user unit is not loaded or not owned. - `src/cli/update-cli/update-command-service-drain.ts`: a resident whose installation was already replaced closes every connection with `gateway install changed` (1011); the drain now warns and stops it directly instead of polling until the 30 min step deadline. The delegated Doctor stop is additionally bounded by the 330 s service stop budget. Found by the local lane rerun on the b2b8ada bytes, which reproduced the CI handoff (the 2026.9.5 updater skipped its own stop, the candidate `--doctor` hook fired) and then hung in the drain until the container timeout. - Hard-link retention (openclaw#155977) and the lane are untouched.
What Problem This Solves
Fixes:
openclaw updatefrom 2026.9.5 to the 2026.9.6 candidate fails at the post-install Doctor withanother OpenClaw process owns gateway-lifecyclewhen the shipped 2026.9.5 updater could not inspect the managed Gateway service, and the package is rolled back. Release blocker for 2026.9.6 (Package Acceptance laneupdate-first-hop-compat, release-checks run 35803842673 attempts 1 and 2).User Impact
User impact: operators on 2026.9.5 whose service manager cannot be inspected by the old updater can now update in place; the candidate stops the still-running predecessor Gateway before Doctor and the updated service is restarted afterwards. No change for updates where the old updater already inspected and stopped the service, or on Windows. Under
--no-restartthe shipped 2026.9.5 driver gives the delegated Doctor no restart consent, so a Gateway the candidate had to stop for Doctor is restarted on the updated installation with an advisory rather than left down.Why This Change Was Made
Root cause and why #155977 is not the cause
Release blocker for 2026.9.6: Package Acceptance lane
update-first-hop-compatfails on the 2026.9.5 → candidate positive hop (release-checks run 35803842673, attempts 1 and 2; FRV 35801740038; Code SHA 2e7d779). The post-swap stepupdate-migrated-finalize.worker.js --doctorexits 1 in 2.8 s withStateDatabaseCoordinatorContentionError: another OpenClaw process owns gateway-lifecycle, and the run recordsmanaged-service: Gateway service inspection is unavailable; automatic service restart was skipped.Root cause: the 2026.9.5 updater (immutable) inspects the managed Gateway service with its own adapter before delegating finalization to the candidate's worker. When that inspection reports
unavailable, it transfers an unstopped, still-running 2026.9.5 Gateway (preManagedServiceStop.serviceUpdateVerdict.kind === "unavailable"). The running predecessor holds thegateway-lifecyclecoordinator lock; a supervised owner never releases it on its own (2026.9.5 has no installation-replacement self-detection), and Doctor only waits on aforegroundlease owner, so maintenance admission is refused immediately. Baselines 2026.9.1–2026.9.4 pass because those Gateways do not hold the lifecycle coordinator. The lane's negative control (2026.9.1,ENOENT shared-DFJEouXv.js) is expected and unchanged.This is not caused by #155977: the hard-link retention only wraps the candidate's own
updateCommand, which never runs in the first hop. This targeted lane had not executed in Package Acceptance for the prior candidate (noupdate-first-hop-compatjob in runs 35782428117 / 35787498943 / 35802245917 / 35802312114 / 35797937836), so 35803842673 is its first run against a 2026.9.5 baseline.src/infra/update-candidate-predecessor-stop.ts(new):stopSupervisedPredecessorGatewayruns in the candidate's--doctorentrypoint (runDelegatedDoctor), which is the step the immutable 2026.9.5 driver invokes as its post-verification Doctor and the step that fails in CI. When the current Gateway owner lease isliveandsupervised, it stops that predecessor through the candidate's service adapter (maybeStopManagedServiceBeforeMutableUpdate, phaseprepare) under the composed executor + requester authority (assertCurrent, which throwsUpdateRequesterRevokedErrorbefore any native mutation), then recordsmanaged-service:candidate-stopin the update-run ledger. Aforegroundowner keeps Doctor's existing wait.adoptCandidateManagedServiceStopruns in finalization: for a transferred uninspectedunavailableverdict it re-inspects, adopts the ledger-recorded Doctor stop asstopped, and hands the state tofinishUpdateso the existing restart path starts the updated service. Both paths are skipped on Windows so a candidate-created Scheduled Task suspension can never be dropped. The ledger step is recorded in theonStoppedcallback (the native mutation boundary) with the stopped service's pid, verdict fingerprint and manager uid; finalization adopts it only when its own fresh inspection reports the same fingerprint and manager uid, and restores (force-restarts, with an advisory step) when the run was--no-restart.src/infra/update-migrated-finalize.worker.ts: wires the two hooks above; the finalization hook revalidates the requester (run.requesterAuthority.isCurrent()) as well as the executor fence before native mutation.src/cli/update-cli/update-command-legacy-service-stop.ts: the decision helper (needsCandidateManagedServiceStop).src/daemon/systemd-scope.ts/systemd-lifecycle.ts: start and restart admission use the same rule (assertNoSystemGatewayOwnershipForActivation), so the updated service can start under exactly the condition that admitted the stop; a proven system owner still refuses.src/daemon/systemd-definition-mutation.ts: when the system-scope ownership probe is unverifiable (SERVICE_DEFINITION_UNKNOWN [system-ownership-unverified], seen in the CI log) and the caller requires a loaded unit, a loaded user unit whose artifacts this account owns keeps itswritablecapability. The refusal is unchanged withoutrequireLoaded, for a system-owned unit, and when the user unit is not loaded or not owned.src/cli/update-cli/update-command-service-drain.ts: a resident whose installation was already replaced closes every connection withgateway install changed(1011); the drain now warns and stops it directly instead of polling until the 30 min step deadline. The delegated Doctor stop is additionally bounded by the 330 s service stop budget. Found by the local lane rerun on the b2b8ada bytes, which reproduced the CI handoff (the 2026.9.5 updater skipped its own stop, the candidate--doctorhook fired) and then hung in the drain until the container timeout.Hard-link retention (fix(update): retain the running updater by hard link instead of copying the package #155977) and the lane are untouched.
Evidence
/private/tmp/openclaw-frv-triage/fhc/targeted-update-first-hop-compat/update-first-hop-compat.loglines 277–470 (positive-firstdoctor-failed,service-inspection-unavailable, rollback). Doctor durationMs 2849 shows no owner wait.update-first-hop-compat-docker.shrestricted to the 2026.9.5 source (OPENCLAW_UPDATE_FIRST_HOP_SOURCE_PACKAGE_TGZ=openclaw-2026.9.5.tgz):Packaged updater first-hop compatibility E2E passed.Service PIDs 617 → 4372 → 9605 across the two hops;positive-systemctl.log.callersrecords{"action":"stop","roles":["update"]}before Doctor andrestartafter. Locally the 2026.9.5 adapter resolves the shim-managed service asowned, so the CI-onlyunavailableverdict cannot be reproduced here; the candidate-side stop covers it in CI.update-command-legacy-service-stop.test.ts(7),update-migrated-finalize.worker.test.ts(22: three--doctorcases proving the supervised owner is stopped and recorded beforerunDoctorHealthFlowruns, a foreground owner and no owner are left alone; finalization cases for stop, no-stop, adoption of the Doctor's ledger stop,--no-restartrestoration and reassigned-service refusal; the Doctor stop case has the native stop throw afteronStoppedand proves the ledger still records the identity),systemd-definition-loaded.test.ts(unverifiable-owner capability and activation admission: writable/admitted only for a loaded owned unit, refused withoutrequireLoaded, when not loaded, and for a proven system owner),systemd-system.test.ts,systemd-definition-mutation.test.ts,systemd-maintenance.test.ts,update-command-migrated.test.tsall pass.pnpm tsgo:coreclean.OPENCLAW_TESTBOX=1 pnpm check:changedpassed on 1e5af47 (exit 0, Blacksmith Testbox) and is rerunning on the final head; the only failures on intermediate heads were knip (unused export) and the assertion-SAFETY ratchet, both fixed by follow-up commits.Review follow-ups addressed: the hook now sits in the
--doctorentrypoint the 2026.9.5 driver calls (not only in migrated finalization); requester authority is revalidated before the native stop; Windows is excluded so no candidate-created autostart recovery can be lost; a stop that reports mutation and then throws leaves the ledger step unrecorded and Doctor fails as before, with the service manager's own state visible viaopenclaw gateway status --deep.Advisory, not addressed here:
cross_os_release_checks / Windows / packaged upgradein the same run fails withdirectory changed during durable directory operation: C:\Users\RUNNER~1\AppData\Local\Temp\openclaw2 s into the 2026.9.5 → candidate update.