Skip to content

fix: restore the Gateway after activation Doctor fails - #160671

Merged
steipete merged 8 commits into
mainfrom
upd/upd-activation-doctor-authority
Sep 29, 2026
Merged

steipete merged 8 commits into
mainfrom
upd/upd-activation-doctor-authority

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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 in update-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 final node scripts/check-changed.mjs passed in 1,399.369s on tbx_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 on tbx_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-owner update.run, and normal full builds. Candidate validation passed before the managed stop; immutable synthetic config then forced the actual activation Doctor to return config-lock-refused.

Cell Recorded outcome Native proof
Doctor-owned generation advance only rolled-back; database rollback exit 0 in 1.355s Both snapshot hashes verified; displaced migrated files retained; previous source/build b2af48856d58 restored; native PID 24612; readiness HTTP 200 / ready:true. Cell wall 3,145.234s, with the downtime/finalization follow-ups above.
Genuine SDK write after Doctor settled failed / state-migrated-no-rollback; restoration refused SDK marker preserved; candidate source/build 3a1919ccf8b4; 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 used tbx_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:

Rollback refused: Databases changed after openclaw doctor: ~/.openclaw-l1313-94a4f07327b2/state/openclaw.sqlite; restoring the backup would discard later writes. The Gateway is running on the preserved migrated state. Keep the recovery snapshots and run openclaw --profile l1313-94a4f07327b2 doctor to inspect the remaining repair.

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 at 47b2be04…: 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 on tbx_01m3mvx7dwc2yxp6gzsv4abw8a. The full 47b2be04… check, node scripts/check-changed.mjs -- <all 32 PR paths>, passed in 3,843.323s on tbx_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 on tbx_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 on 47b2be04… as recorded above.

Prior scope proof and regression controls
  • Earlier isolated macOS proof used the unmodified published v2026.9.5 Git 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-owner update.run RPC 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.
  • Real pre-fix controls fail for maintenance-authority reads, early Git recovery, later-write recovery, separate-service ownership, and recovered Windows autostart. The native cell also exposed nested migration-lock release; the expanded configured-owner and profile cases both failed with the exact live refusal before the final scope-entry correction and passed afterward.
  • Pre-integration 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.
  • Touched suites: 207 tests across 10 files ×3, all passing (405.192s, 334.702s, 356.694s command wall). Cross-lane inventory: 346 non-planner files have passing coverage; two planner files are waived after pristine-baseline reproduction. After the final scope-entry correction, all 78 affected non-planner importers passed: the remaining 77 files / 2,090 tests exited 0 in 640.011s, plus one completed 29-test file.
  • Focused repetitions used the repository wrapper, node scripts/run-vitest.mjs <files> --maxWorkers=1, on Testbox; the importer batches preserved the selected file order through the same wrapper.
  • Fresh independent Codex P1 review: clean.
  • Diff against the integrated main parent: production +289/−146 (+143 net); tests/support +745/−316 (+429 net, including the shared test-process helper and missing-Doctor transaction case); docs +17.

An earlier genuine conflict integrated main 80fd8670e37bfd66ca835fc1d90845afa22a3f7d at 664de1b8725e0ab4414c3264ab3a0fdf99d2c135. The final integration uses main 80864601bf9e6fba4d1cf34a9f1bfabe3516b6ad and 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-path node scripts/check-changed.mjs passed in 1,413.691s on tbx_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 restoreRuntime operation, 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/node failed executable admission on Testbox. The fixture now uses process.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:

  • RV4: test/scripts/ci-changed-node-test-plan.test.ts took 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.
  • Original-service recovery fixture: 55 cases took 117.095, 106.267, and 148.213 seconds in successive passes; the later importer run reported 207.860 seconds. Repeated one-shot SQLite backup children are required by the existing Node 26 persistent-IPC stall guard, which remains intact. The extended regression itself took 0.8–1.7 seconds. Follow-up belongs to the recovery fixture and SQLite snapshot process owner.
  • Foreground handoff: src/infra/update-managed-service-handoff-foreground.test.ts reported 175.091 seconds across 21 cases; retained as a process-fixture performance follow-up under the no-further-slow-stop ruling.
  • Doctor-health: the pre-existing 123-second test-file cost remains a follow-up. The unrelated worker-sharing change was discarded.
  • Nested-authority fixture: the configured-owner case took 31.932 seconds in the first final pass. It retains the suite-level SQLite worker fixture and now exercises the real nested migration-lock release before promotion and revocation; the final ARM repetitions measured 88.3–88.7s for the configured-owner case and 53.9–55.5s for the profile case; cold read/snapshot cost remains a fixture performance follow-up under the no-further-slow-stop ruling.

The original two ci-node-test-plan.test.ts hybrid-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.

Test file Sum of case time Slowest case
src/infra/update-managed-service-handoff-foreground.test.ts 483.754s 35.340s
src/cli/update-cli/update-command-original-service.test.ts 360.896s 22.230s
src/flows/doctor-health.test.ts 307.348s 10.668s
src/cli/update-cli/update-command-lease.test.ts 306.177s 10.617s
src/cli/update-cli/update-command-database-rollback.test.ts 288.374s 32.545s
src/cli/update-cli/update-command-rollback.test.ts 262.178s 10.706s
src/cli/update-cli/update-command-service.integration.test.ts 234.409s 6.712s
src/commands/doctor-config-flow.billing-route.test.ts 186.179s 49.717s
src/commands/doctor-maintenance.admission-activation.test.ts 166.485s 59.077s
src/infra/state-migrations.test.ts 160.836s 6.796s
src/commands/doctor-maintenance.requester-authority.test.ts 144.908s 92.037s
src/flows/doctor-health.legacy-update.test.ts 42.388s 35.634s
src/infra/update-repair-agent.handoff.test.ts 34.983s 34.983s

The retained early native install failures were setup guard refusals before service effects: a noncanonical fixture state/config path, then an owned ~/.config ancestor with mode 0777. The fixture moved to the supported named-profile path under its real account home and changed only its owned config directory to 0755. 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_01m3mewvzrsrw067h9awt4s05c for full changed checks and touched suites; tbx_01m3mjmv6smrx1m88e05qnbh80 for 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.

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.
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes scripts Repository scripts commands Command implementations size: XL labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 28, 2026, 11:00 PM ET / September 29, 2026, 03:00 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: 7ab07aabd20297314e65e6092259fa4f77c9ba84
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has substantial real-path proof, but a SQLite publication race and a measured prolonged recovery outage prevent merge readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Earlier-head real systemd cells exercised activation Doctor failure through supported update entrypoints and observed both restored-previous-Gateway and preserved-migrated-state recovery; a published-driver macOS cell exercised the candidate-side authority repair. Current-head focused checks cover the later Git integration, but no exact-head native cell or interleaved source-edit observation is shown. Existing-state compatibility remains insufficient because source can drift while older SQLite data is published.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Earlier-head real systemd cells exercised activation Doctor failure through supported update entrypoints and observed both restored-previous-Gateway and preserved-migrated-state recovery; a published-driver macOS cell exercised the candidate-side authority repair. Current-head focused checks cover the later Git integration, but no exact-head native cell or interleaved source-edit observation is shown. Existing-state compatibility remains insufficient because source can drift while older SQLite data is published.
Evidence reviewed 11 items Current main still needs the change: Current main runs activation Doctor before registering the retained Git transaction, so it lacks this branch’s early recovery path.
Early transaction introduction: The introduced change registers and awaits the Git rollback transaction before activation Doctor, making database rollback reachable on Doctor failure.
Source check precedes asynchronous restore: The new Git safety assertion runs once before calling database restoration.
Findings 2 actionable findings [P1] Hold Git source safety through database publication
[P1] Skip resident drain for a verified stopped Gateway
Security None None.

How this fits together

A 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
Loading

Decision needed

Question Recommendation
Must the already-stopped systemd drain be repaired in this branch before the new rollback path ships, or is its measured 35-minute outage acceptable for this release? Repair before merge: Short-circuit resident drain only after the service owner verifies that the managed Gateway is already stopped, while preserving identity and custody checks.

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

  • Hold Git source safety through database publication (P1) - The new pre-restore Git check runs before asynchronous generation checks, snapshot verification, and SQLite publication. An operator edit in that interval can publish older databases; the later Git check then refuses runtime rollback, leaving source and state mismatched. Guard the publication interval and cover an interleaved edit. This remains the previously raised blocker.
  • Skip resident drain for a verified stopped Gateway (P1) - Registering rollback before Doctor makes its failed-activation recovery enter the managed stop path. The supplied systemd cell found the service already stopped, yet resident drain waited 1,822.245 seconds on refused connections and kept the Gateway unavailable for 35m37.701s. Let the service owner verify stopped identity and proceed without that drain.
  • Resolve merge risk (P0) - The PR’s live rollback kept a systemd Gateway unavailable for 35m37.701s because an already-stopped service entered the resident drain. The body records this as follow-up work, but no explicit decision accepting that outage for this recovery path is established.
  • Complete next step (P2) - Guard Git source through SQLite publication, then repair or explicitly accept the measured already-stopped service drain before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] Hold Git source safety through database publication — src/cli/update-cli/update-command-database-backup.ts:161
  • [P1] Skip resident drain for a verified stopped Gateway — src/infra/update-runner-git.ts:505
Agent review details

Security

None.

PR surface

Source +143, Tests +429, Docs +17. Total +589 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 21 289 146 +143
Tests 11 745 316 +429
Docs 1 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 1051 462 +589

Review metrics

Metric Value Why it matters
Production and test lines production +289/−146; tests +745/−316 The net production growth supports the stated recovery work, but the publication guard and stopped-service path still need resolution.
Observed restore outage 35m37.701s; 1,822.245s spent after database restoration The new recovery path eventually served again, but its service drain dominated user-visible downtime.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/cli/update-cli/update-command-database-receipts.ts, migration/backfill/repair: src/cli/update-cli/update-command-fresh-doctor.ts, migration/backfill/repair: src/cli/update-cli/update-recovery-guidance.ts, migration/backfill/repair: src/commands/doctor-maintenance-state.ts, migration/backfill/repair: src/infra/update-database-backup.ts, migration/backfill/repair: src/infra/update-database-restore.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159839
Summary: This PR is the open candidate fix for the linked, still-open activation Doctor and Gateway recovery report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Fix the stopped-service path (recommended)
    Verify stopped service identity and bypass resident RPC drain before the rollback restart.
  2. Own the recovery delay
    Explicitly accept the measured outage as a release tradeoff and track its service-owner repair.

Technical review

Best 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:

  • [P1] Hold Git source safety through database publication — src/cli/update-cli/update-command-database-backup.ts:161
    The new pre-restore Git check runs before asynchronous generation checks, snapshot verification, and SQLite publication. An operator edit in that interval can publish older databases; the later Git check then refuses runtime rollback, leaving source and state mismatched. Guard the publication interval and cover an interleaved edit. This remains the previously raised blocker.
    Confidence: 0.91
  • [P1] Skip resident drain for a verified stopped Gateway — src/infra/update-runner-git.ts:505
    Registering rollback before Doctor makes its failed-activation recovery enter the managed stop path. The supplied systemd cell found the service already stopped, yet resident drain waited 1,822.245 seconds on refused connections and kept the Gateway unavailable for 35m37.701s. Let the service owner verify stopped identity and proceed without that drain.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.89

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4cb9d38e4baa.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The source-edit race can publish an older SQLite state image before Git rollback refuses the edited checkout.
  • remove proof: telegram-e2e: Current Telegram visible-proof status is not_needed.

Label justifications:

  • P0: The affected update can leave the core Gateway unavailable, and the proposed recovery still has a measured prolonged outage.
  • merge-risk: 🚨 compatibility: A source edit during restoration can leave an edited candidate checkout paired with older restored databases.
  • merge-risk: 🚨 session-state: The source-edit race can publish an older SQLite state image before Git rollback refuses the edited checkout.
  • merge-risk: 🚨 availability: The live systemd restore cell spent over 35 minutes without a serving Gateway.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): Earlier-head real systemd cells exercised activation Doctor failure through supported update entrypoints and observed both restored-previous-Gateway and preserved-migrated-state recovery; a published-driver macOS cell exercised the candidate-side authority repair. Current-head focused checks cover the later Git integration, but no exact-head native cell or interleaved source-edit observation is shown. Existing-state compatibility remains insufficient because source can drift while older SQLite data is published.
  • proof: sufficient: Contributor real behavior proof is sufficient. Earlier-head real systemd cells exercised activation Doctor failure through supported update entrypoints and observed both restored-previous-Gateway and preserved-migrated-state recovery; a published-driver macOS cell exercised the candidate-side authority repair. Current-head focused checks cover the later Git integration, but no exact-head native cell or interleaved source-edit observation is shown. Existing-state compatibility remains insufficient because source can drift while older SQLite data is published.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Guard Git source throughout SQLite restoration and prove an interleaved operator edit cannot publish incompatible state.
  • Repair the already-stopped drain or obtain explicit owner acceptance of its measured outage.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-28T19:30:18.961Z sha 5c58a1b :: blocked before merge. :: none
  • reviewed 2026-09-29T00:26:03.812Z sha 47b2be0 :: blocked before merge. :: [P1] Preserve operator edits throughout retained Git rollback
  • reviewed 2026-09-29T02:00:56.715Z sha 664de1b :: blocked before merge. :: [P1] Revalidate Git source before publishing restored databases

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.
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Sep 29, 2026
@steipete steipete changed the title fix: recover the Gateway after activation Doctor fails fix: restore the Gateway after activation Doctor fails Sep 29, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 29, 2026
@steipete
steipete marked this pull request as ready for review September 29, 2026 02:52
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. labels Sep 29, 2026
steipete added a commit that referenced this pull request Sep 29, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
* 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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
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.
RomneyDa added a commit that referenced this pull request Oct 3, 2026
Backport the generic package, database, and service recovery portion of #160671 after the requester-authority fix moved to the parent stack layer.

Source: cd6c9c8
RomneyDa added a commit that referenced this pull request Oct 4, 2026
…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
RomneyDa added a commit that referenced this pull request Oct 4, 2026
* 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]>
steipete added a commit that referenced this pull request Oct 27, 2026
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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram update leaves macOS Gateway offline when activation Doctor config promotion hits maintenance authority refusal

1 participant