Repository navigation
fix: restore the Gateway after activation Doctor fails - #160671
Conversation
Keep requester checks inside retained maintenance custody and preserve read intent through borrowed ownership. Register Git rollback before activation Doctor, snapshot databases through the existing owner, and verify source safety before database restoration. Refs #159839. Reported by @hannesrudolph.
Reproduce cold maintenance admission and cached policy revocation, reject new work during scope closure, and exercise Git migration failure plus source-edit refusal through the existing database recovery fixture. Document candidate-side authority repair and installed-driver rollback behavior.
Resolve the execution overlap with current main by keeping its shared install options and transaction-based database capture. Git still retains the transaction before activation Doctor and routes snapshot failures through the same finalization owner.
Carry the already-landed fix da2efd8 so package activation tests typecheck against the integrated recovery owner. The assertion implementation and production runtime are unchanged.
Keep Doctor policy reads and nested migration cleanup inside held maintenance authority. Bind Doctor generation receipts to the pre-migration database backup so attributable writes can be restored and later writes are preserved. Restart and verify the appropriate Gateway after either recovery outcome.
|
🦞👀 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, 11:00 PM ET / September 29, 2026, 03:00 UTC (Revision 4). ClawSweeper reviewWhat this changesThe branch moves Git rollback and database snapshots before activation Doctor, keeps Doctor’s requester checks within held maintenance authority, and adds Gateway recovery, regression tests, and updater guidance. Merge readiness⛔ Blocked before merge - 6 items remain Keep open: current main still has the reported activation failure path. This branch addresses it, but database restoration can race an operator Git edit, and the measured recovery path kept the Gateway unavailable for over 35 minutes. Priority: P0 Review scores
Verification
How this fits togetherA managed Git update activates a candidate checkout and runs Doctor to repair configuration and SQLite state. If activation fails, the updater decides which state and runtime can safely serve, then records the result and checks Gateway readiness. flowchart LR
A[Chat update request] --> B[Update authority]
B --> C[Git activation and snapshot]
C --> D[Activation Doctor]
D --> E{Rollback safe?}
E -->|Yes| F[Restore previous state]
E -->|No| G[Preserve migrated state]
F --> H[Gateway readiness and report]
G --> H
Decision needed
Why: The outage is operator-visible in a path meant to restore service, and describing it as a follow-up does not establish acceptance of the release tradeoff. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +143, Tests +429, Docs +17. Total +589 across 33 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 rollback with the existing update owner, hold Git source safety through SQLite publication, and have the service owner recognize a verifiably stopped Gateway before restart. Do we have a high-confidence way to reproduce the issue? Yes for the reported failure: the linked report records a deterministic Doctor-authority refusal on the affected candidate, and current main still runs Doctor before retaining Git rollback. The newly identified source-edit interval is supported by code order but has not been executed as an interleaved reproduction. Is this the best way to solve the issue? Not yet. Early rollback retention and held-scope Doctor checks use the existing owners, but safe publication needs a continuous Git source guard and the stopped-service recovery path needs a prompt restart or an explicit acceptance decision. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4cb9d38e4baa. 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 (3 earlier review cycles)
|
Keep the extracted Doctor state owner and legacy-root transfer from main. Carry held maintenance authority through policy checks and preserve the reviewed recovery contract.
The database write receipt has carried `fromGenerations` since #160671; the NOCOW attribution case added in #160877 still asserted the two-field shape, so src/commands/doctor-maintenance.settlement.test.ts was red on main and on every PR merge ref. Assert the admitted baseline like the sibling cases do.
* fix(update): recover Git Gateways after activation Doctor failures Keep requester checks inside retained maintenance custody and preserve read intent through borrowed ownership. Register Git rollback before activation Doctor, snapshot databases through the existing owner, and verify source safety before database restoration. Refs openclaw#159839. Reported by @hannesrudolph. * test(update): cover maintenance authority and Git rollback Reproduce cold maintenance admission and cached policy revocation, reject new work during scope closure, and exercise Git migration failure plus source-edit refusal through the existing database recovery fixture. Document candidate-side authority repair and installed-driver rollback behavior. * fix(test): include upstream reliability assertion export Carry the already-landed fix 6a4ca60 so package activation tests typecheck against the integrated recovery owner. The assertion implementation and production runtime are unchanged. * fix: recover the Gateway after activation Doctor fails Keep Doctor policy reads and nested migration cleanup inside held maintenance authority. Bind Doctor generation receipts to the pre-migration database backup so attributable writes can be restored and later writes are preserved. Restart and verify the appropriate Gateway after either recovery outcome.
The database write receipt has carried `fromGenerations` since openclaw#160671; the NOCOW attribution case added in openclaw#160877 still asserted the two-field shape, so src/commands/doctor-maintenance.settlement.test.ts was red on main and on every PR merge ref. Assert the admitted baseline like the sibling cases do.
…164554) * fix(update): retain Doctor requester authority Backport the requester-authority portion of #160671 so candidate Doctor policy reads stay inside held maintenance custody. Preserve artifact fingerprints during authorization reads and keep revocation checks live through nested migration. Source: cd6c9c8 * test(update): execute held authority callback
* fix(update): retain Doctor requester authority Backport the requester-authority portion of #160671 so candidate Doctor policy reads stay inside held maintenance custody. Preserve artifact fingerprints during authorization reads and keep revocation checks live through nested migration. Source: cd6c9c8 * test(update): execute held authority callback * fix(update): restore Gateway after activation Doctor failure Backport the generic package, database, and service recovery portion of #160671 after the requester-authority fix moved to the parent stack layer. Source: cd6c9c8 * fix(update): settle Doctor writers before recovering migrated Gateways (#162614) Doctor left its child writers (spawn-broker process groups) without durable custody, so an update that found an unsettled writer could neither prove settlement nor safely start the migrated candidate, and an operator could be left with a down Gateway. The update command owner now reserves custody before spawning, binds native process identity before admitting input, retains its inventory through Doctor death, and admits migrated-candidate Gateway recovery only after proven writer settlement; unverified writers keep the data-at-risk refusal with PID guidance. Recovery snapshot capture drains SQLite writers first so a refused candidate start still rolls back. The immutable 2026.9.5 parent limitation is documented. Closes #162055 (cherry picked from commit 8f364a7) * fix(update): finish unfinished agent migrations at Gateway start and deliver update outcomes durably (#163803) A 2026.9.5 to 9.7 managed update whose activation Doctor failed left the candidate package active with the agent databases on the old schema; the new Gateway exited 78 and systemd parked on RestartPreventExitStatus=78, and the failure notice depended on the Gateway the update had just stopped, so the operator saw nothing for 3.5 hours (#163638). A Gateway that finds the updater own unfinished agent migration at start now runs the candidate Doctor before its recovery restart, reinspects schemas, and records explicit recovery guidance when a mismatch remains; managed-update outcomes are delivered durably from the next Gateway start. The pre-migration backup stays on disk for manual restore; a successful live migration remains the point of no return (repair forward, never roll databases back). Thanks @chffhc for the timeline. Closes #163638 (cherry picked from commit b379364) * fix(update): adapt recovery backport to 2026.9.9 * fix(update): remove unused recovery imports * style(update): normalize recovery import order * fix(process): separate command custody types from settlement 8f364a7 (#162614) made exec-spawn import custody types from a module that imports its cleanup constant back from exec-spawn. The runtime-only cycle check passed, but Madge rejected the type/value dependency cycle. Move the unchanged custody and identity types into a dependency-free leaf and migrate all type consumers. Preserve settlement behavior, timing, authority checks, and assertions. Also fix the touched Doctor fixture's existing shadowed parameter and inconsistent return syntax without changing its behavior. Validation: full check:architecture (zero cycles), source-contracts lane, deadcode export scans, check-changed, scoped and boundary lint, and P2 review. Static proof ran locally as authorized for this main repair. (cherry picked from commit 0f470ae) * test(process): backport fixture receipt helper * test(update): load Doctor delegation fixtures before the writer-readiness deadline (#163610) update-command-doctor-delegation flaked on main hourlies (3 cases, 37020939466): source loading exhausted the fixture deadline before the standalone Doctor writer reached readiness, so the settle-after-reject assertion observed a null record. Production already awaits custody settlement; the shared compiled-fixture owner now supplies every import up front. Test-support only. Refs #162614 (cherry picked from commit 8bb49fa) * fix(update): preserve child database identity boundary * fix(update): require doctor settlement before recovery * test(update): isolate fresh entrypoint fixtures * test(update): repair recovery fixtures * test(update): mock fresh Doctor transport * test(update): drop stale transport import * test(update): preserve Doctor process custody * test(update): isolate legacy Doctor exit * test(update): record legacy Doctor cleanup * test(update): align remaining Doctor fixtures * test(update): preserve state inspection transport * test(update): satisfy immutable sort lint * test(update): align finalizer Doctor fixtures * test(update): read finalizer transport calls * test(update): separate finalizer lint command * test(update): satisfy finalizer fixture lint --------- Co-authored-by: Peter Steinberger <[email protected]>
Resolve the physical .artifacts directory once before native Git database capture. This preserves the existing backup durability, identity, custody and rollback checks while supporting redirected artifact storage. The paired real-backup regression fails on the original caller and passes with the fix. Fresh-process replay verifies cross-volume storage, the physical returned path, SQLite integrity and the retained synthetic row. Existing redirected Git staging tests pass. Related: #160671, #153764
) Resolve the physical .artifacts directory once before native Git database capture. This preserves the existing backup durability, identity, custody and rollback checks while supporting redirected artifact storage. The paired real-backup regression fails on the original caller and passes with the fix. Fresh-process replay verifies cross-volume storage, the physical returned path, SQLite integrity and the retained synthetic row. Existing redirected Git staging tests pass. Related: openclaw#160671, openclaw#153764
Closes #159839
What Problem This Solves
Fixes managed Git updates leaving the Gateway offline when activation Doctor cannot finish after stopping it. Thanks @hannesrudolph for the macOS report.
User Impact
Doctor can promote its approved repairs under the update's held maintenance authority. If activation fails, the updater restores its database backup and previous Gateway when only Doctor changed state. If later writes make restoration unsafe, it preserves those writes, starts the compatible migrated Gateway, and reports the exact refusal with the next recovery command.
No new options, dependencies, database schemas, or state stores. A refused rollback remains a failed update with explicit recovery facts; serving health does not erase the failure.
Remaining lifecycle follow-up: the final ARM restore cell spent 1,822.245 seconds between database restoration and completion of runtime rollback. The managed-service owner reenters resident drain for a loaded but already-stopped Linux service and waits out its existing 30-minute budget on
ECONNREFUSED. Total recorded downtime was 35m37.701s, including Doctor and startup. The previous process started at 23:53:04Z and readiness was observed at 23:53:46Z. This real downtime remains a follow-up inupdate-command-service-maintenance.ts/update-command-service-drain.ts; no timeout or ownership guard was weakened. A separate 194.800s after readiness before ledger finalization remains an unattributed verifying/finalization follow-up. The final helper diagnostic was only 14.228s and did not account for that interval.Why This Change Was Made
Doctor's authorization reread escaped the maintenance scope it had just acquired. Nested migration cleanup also checked authority before reentering its held lock scope, which made a policy read try to acquire another effect. Both paths now enter the held scope before checking current authority, while keeping revocation checks active. Cold requester preparation also uses the existing artifact-preserving reader so an authorization read cannot change SQLite sidecar fingerprints.
Git exposed its retained rollback transaction only after Doctor succeeded. The transaction and database snapshot now precede activation Doctor. The existing Doctor receipt carries its admitted and settled generations, bound to the existing backup and recorded migration phase. Restoration accepts this attributable transition and still refuses later writes. Native recovery then starts and verifies the appropriate runtime; separate original-service compensation retains its own owner and refusal.
Evidence
Final head:
7ab07aabd20297314e65e6092259fa4f77c9ba84. After preserving main's source guards, rollback warning propagation and detached fallback, the required finalnode scripts/check-changed.mjspassed in 1,399.369s ontbx_01m3nfhskjx0hpxw3f9fnk0eb4. The seven affected suites passed 185 tests ×3 (188.508s, 153.215s, 159.546s); all 53 affected importer/startup files, 1,142 tests, passed in 559.156s ontbx_01m3nfhskxeaxzfc7pqjshn2vf. These include the existing native-entrypoint legacy-state guard and refusal of startup/Doctor repair for conflicting core-agent schema markers. All leases are stopped after proof.Fresh direct-route P1 review completed after the final integration. Its proposed blanket block after a Doctor data-at-risk refusal was rejected: the update owner only admits a native restart attempt, while the installed candidate's startup owner revalidates persisted database/session/workspace readiness before admission. Recovery is recorded healthy only after native readiness with the expected runtime identity. The existing startup-refusal tests above passed; no admission guard was bypassed or weakened. Prior review findings and their dispositions are retained below.
Both mandatory live cells passed on
47b2be04e2c5c44a60b4ce91cd8e781347d588ab, before the final Git source-guard conflict integration, using ARM Linux Blacksmith Testboxes, a real systemd user service, isolated named profiles/ports, the supported CLI and configured-ownerupdate.run, and normal full builds. Candidate validation passed before the managed stop; immutable synthetic config then forced the actual activation Doctor to returnconfig-lock-refused.rolled-back; database rollback exit 0 in 1.355sb2af48856d58restored; native PID 24612; readiness HTTP 200 /ready:true. Cell wall 3,145.234s, with the downtime/finalization follow-ups above.failed/state-migrated-no-rollback; restoration refused3a1919ccf8b4; native PID 22142; service healthy and readiness true. Doctor settled at 00:06:19.382Z, the SDK write committed at 00:06:20.072Z, and recovery passed at 00:07:29.801Z. Cell wall 899.953s.Cell A used
tbx_01m3n1nnqpjqc4x54dg23d9kdc(workflow); Cell B usedtbx_01m3n5hjtbq45579nydgzwmwjj(workflow). Normal A build wall was 956.87s, including the regular UI build; bootstrap command exit 0 in 1,163.185s. B's full build wall was 855.54s; its combined bootstrap and cell command exited 0 in 1,912.253s. Provider hydration, local source-capsule preparation, and builds are separate from the cell clocks.The second cell's native output, report, and ledger agree:
The original config bytes and immutable fault remained unchanged until each cell verified automatic recovery. No manual service start supplied readiness. Each pair of ordinary fixture commits has the same reviewed production tree and distinct normal build identities; these cells exercise native recovery and authority transfer. The earlier published-driver cell below covers its stated version boundary.
GitHub reported real conflicts, so this branch integrates main
47646aa21b9a6e18437c31fa225d057dfeb090ef. The held-policy checks now live in main's extracted Doctor maintenance-state owner and preserve its legacy-root relocation and projection transfer. A real policy read failed before the relocation correction and passes after it. Fresh direct-route P1 review of this integrated diff is clean. Validation at47b2be04…: the five affected Doctor/lock suites passed three times, 89 tests per run (281.030s, 285.836s, 271.184s). The additional 77 storage importer files passed, with 1,062 passing tests and one existing skipped case in 903.701s of command time ontbx_01m3mvx7dwc2yxp6gzsv4abw8a. The full47b2be04…check,node scripts/check-changed.mjs -- <all 32 PR paths>, passed in 3,843.323s ontbx_01m3mtpwpw1pm3ne29py81qwtq, including all 26 test-type graphs, production types, zero-warning lint, zero-entry dead-export scans, storage guards, and zero runtime import cycles. The 149 integration importer files passed ontbx_01m3mvqq97zzjq80zvy5wqgjfd: 3,603 reported passing tests, three existing platform/fixture skips, exit 0 in 4,998.056s. That command includes 25m42.4s of standard runtime preparation. All validation leases and both native proof leases are stopped. Both native cells passed on47b2be04…as recorded above.Prior scope proof and regression controls
v2026.9.5Git driver: supported CLI update to the initial authority fix exited 0 (873.247s), activation Doctor exited 0 (37.172s), and launchd restarted a Gateway with readiness true. A subsequent configured-ownerupdate.runRPC also completed promotion and readiness. These establish the earlier authority-fix scope; the final rollback changes are covered by the Linux cells above. This does not claim live Telegram transport coverage.node scripts/check-changed.mjs: exit 0 in 28m19s, including production/test types, lint, runtime build checks, dead exports, storage boundaries, and import-cycle checks.node scripts/run-vitest.mjs <files> --maxWorkers=1, on Testbox; the importer batches preserved the selected file order through the same wrapper.An earlier genuine conflict integrated main
80fd8670e37bfd66ca835fc1d90845afa22a3f7dat664de1b8725e0ab4414c3264ab3a0fdf99d2c135. The final integration uses main80864601bf9e6fba4d1cf34a9f1bfabe3516b6adand also retains its rollback warning propagation and detached no-reflog fallback. The single early transaction remains before Doctor and now passes its frozen activated source to main's shared rollback helper, preserving its nonforcing checkout and branch/reflog guards. Main's include-publication authority retention and runtime-restoration ordering are retained. The native cells above remain prior-head evidence; A's changed Git compensation commands are covered by merged-head real-Git and database-rollback tests, not relabeled as exact-head native proof.The seven affected suites passed 185 tests ×3 (156.610s, 150.803s, 148.515s). A new missing-Doctor case in the existing shared Git fixture fails with pristine main's Git owner because the retained transaction is absent, then passes on the candidate (374ms case time; 21.086s command wall). It verifies candidate source/runtime stay paired until the retained transaction restores both. The 45 affected importer files passed 944 tests in 291.678s on
tbx_01m3nc28cvfg8pajg78bcgdpm3, which is stopped. The final 33-pathnode scripts/check-changed.mjspassed in 1,413.691s ontbx_01m3nc27za4kcw8jp4ycdjdvj1, including production types, all 27 test-type graphs, lint, dead exports and storage guards.Fresh direct-route P1 review completed for this integration. Two reported findings were rejected after owner inspection: source and runtime restoration are inside one guarded
restoreRuntimeoperation, and the CLI captures its schema baseline before activation and stores the transaction before snapshot capture. A pre-Doctor snapshot failure therefore retains both the baseline and the transaction for unchanged-state rollback. A database snapshot is required only when recovery must restore changed state. Moving retention after the callback would create competing rollback owners. The real-Git missing-entry control above supports the first disposition; the existing CLI recovery owner and affected suites cover unchanged-state rollback. These are reviewed rejections, not a claim that the review tool returned a clean verdict.Importer proof exposed a portability defect in the convergence-authority test: its hard-coded
/usr/bin/nodefailed executable admission on Testbox. The fixture now usesprocess.execPath; its real capability refusal and source-completion assertions remain unchanged. Its targeted changed-file gate passed, followed by all 19 tests three times (31.58s, 29.94s, 23.57s command wall; 4.02s, 3.36s, 3.75s Vitest wall; about 0.7s test time each).Performance follow-ups, explicitly waived for this lane:
test/scripts/ci-changed-node-test-plan.test.tstook 456.085 seconds; one dependency-owner case took 64.178 seconds. Repeated real-repository dependency selection and canonical shard packing own this cost. Its GitHub/hybrid backend-comparison failures reproduce once on pristine merge-base main (2 failed, Blacksmith passed; 6.642s command wall; source unchanged) and are excluded as RV4-owned churn under maintainer direction.src/infra/update-managed-service-handoff-foreground.test.tsreported 175.091 seconds across 21 cases; retained as a process-fixture performance follow-up under the no-further-slow-stop ruling.The original two
ci-node-test-plan.test.tshybrid-fallback failures reproduce on pristine merge-base main (ff8c752d852f5d01da5a8a5e6abb7546c1328e83) and remain RV4-owned churn.Additional ARM timing follow-ups (waived; no retries or relaxed assertions)
These are sums of reported case times and the slowest case, not command wall time. The update/Doctor and handoff fixture owners retain the follow-ups; the existing Node 26 snapshot guard stays intact.
src/infra/update-managed-service-handoff-foreground.test.tssrc/cli/update-cli/update-command-original-service.test.tssrc/flows/doctor-health.test.tssrc/cli/update-cli/update-command-lease.test.tssrc/cli/update-cli/update-command-database-rollback.test.tssrc/cli/update-cli/update-command-rollback.test.tssrc/cli/update-cli/update-command-service.integration.test.tssrc/commands/doctor-config-flow.billing-route.test.tssrc/commands/doctor-maintenance.admission-activation.test.tssrc/infra/state-migrations.test.tssrc/commands/doctor-maintenance.requester-authority.test.tssrc/flows/doctor-health.legacy-update.test.tssrc/infra/update-repair-agent.handoff.test.tsThe retained early native install failures were setup guard refusals before service effects: a noncanonical fixture state/config path, then an owned
~/.configancestor with mode0777. The fixture moved to the supported named-profile path under its real account home and changed only its owned config directory to0755. Both refusals left the unit absent and MainPID zero; the same built candidate then installed successfully. An older generic install failure has no retained structured error, so no exact cause is claimed for it.Both native proof services were removed, all update writers settled, and their leases were stopped. All proof uses local isolated fixtures or Blacksmith Testboxes. No PR CI jobs were dispatched or rerun for proof. Auto-merge is off.
Pre-integration Testbox leases:
tbx_01m3mewvzrsrw067h9awt4s05cfor full changed checks and touched suites;tbx_01m3mjmv6smrx1m88e05qnbh80for remaining importers. The Testbox command receipts are authoritative; lease workflows may show cancellation during cleanup. A planner file accidentally selected through a text reference was excluded from the importer inventory, and completed proof was retained. A runner-construction error failed before any tests; corrected argument handling completed the run. No product guard was bypassed. The old isolated macOS fixture was recovered and uninstalled; PID 91956, listener 60244, and its launchd label are absent.