Skip to content

fix(update): recover Gateway after failed activation - #164497

Merged
RomneyDa merged 27 commits into
release/2026.9.9from
fix/release-2026-9-9-update-recovery
Oct 4, 2026
Merged

RomneyDa merged 27 commits into
release/2026.9.9from
fix/release-2026-9-9-update-recovery

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Related: #164066

Parent #164554 merged to release/2026.9.9 as d7e86e66e447.

What Problem This Solves

Fixes: a genuine activation Doctor or unfinished-migration failure can leave the managed Gateway offline after an update.

User Impact

After the parent PR prevents the known false refusal, failed activation can restore the appropriate runtime, settle Doctor-owned writers, finish pending migrations when safe, and durably deliver the recovery outcome.

Why This Change Was Made

This is the second layer of the release backport. It carries the remaining recovery portion of #160671, then the writer-custody prerequisite from #162614 and pending-migration/outcome repair from #163803. The release-specific adaptation preserves the 2026.9.9 branch's synchronous display-progress contract instead of importing adjacent main-only refactors.

The merged parent PR owns the narrow requester-authority false-refusal fix. This layer remains large because generic recovery must keep package source, database generations, Doctor process groups, and the restarted Gateway runtime mutually compatible.

Evidence

  • Exact head: d73af7ce9cf27e6278c9e26aa970633475b86ddb.
  • The fixture repairs supply the recovery module's current optional dependencies, keep config validation on runExec, and drive Doctor failures and observations through the UTF-8 process-custody transport. Unrelated UTF-8 subprocesses retain the real transport.
  • Focused Doctor failure proof: env OPENCLAW_VITEST_WORKER_CACHE=0 OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-pr164497-followup-cache node scripts/run-vitest.mjs src/cli/update-cli.fresh-doctor.test.ts --maxWorkers=1 -t 'records diagnostics as a warning|keeps an invalid config authoritative' — 2 tests passed, 15 skipped; 94.2s wall including worker preparation.
  • Restart-module proof: node --experimental-vm-modules --test scripts/tests/update-restart-module-outcome.mjs — 19/19 tests passed in 2.95s wall.
  • The remotely failing already-current Doctor case passed locally at 332cb0586da; the run was stopped after that affected case rather than spending wall time on unrelated cases.
  • The four remotely failing deferred-completion cases passed across focused invocations at the current fixture contract: legacy diagnostics + resume downgrade passed, then both finalize downgrade cases passed at exact head in 72.25s wall including worker preparation.
  • pnpm exec oxfmt --write and git diff --check passed for the changed fixture files.
  • Exact-file pnpm exec oxlint src/cli/update-cli.deferred-completion.test.ts passed after the immutable-sort correction.
  • Fresh diff-scoped P0/P1 AutoReview against 0030b6960a0..e4716dcb7ef: clean (0.82 confidence).
  • The six remotely failing finalizer cases pass across focused runs: failure diagnostics, repair/config refresh, requested-channel reapplication, RPC channel restoration, and Node/Bun maintenance runtime selection. The final two-case run passed in 71.46s wall including worker preparation.
  • Exact-file oxlint and git diff --check pass for the finalizer fixture cutover.
  • Fresh diff-scoped P0/P1 AutoReview against 72043c07fb3..d73af7ce9cf: clean (0.81 confidence).
  • Earlier production evidence remains revision-bound: pnpm build and 65 focused recovery tests were recorded against production head 791ca83656bba61f01001dc36be1607b1b10ee4d; the 29-test settlement suite passed after its fixture correction. That evidence does not claim coverage for the later database-identity projection or interrupted-Doctor settlement guard.
  • Final-candidate published-parent and persisted-state compatibility qualification remains required before release publication.

Review Status

  • The fixture-owner repair is locally proven and pushed.
  • Exact-head CI and ClawSweeper review are running for d73af7ce9cf27e6278c9e26aa970633475b86ddb.
  • After merge, the release branch still requires exact-head Full Release Validation before publication.

@clawsweeper

clawsweeper Bot commented Oct 3, 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 gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations size: XL labels Oct 3, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 10:26 PM ET / October 4, 2026, 02:26 UTC (Revision 13).

ClawSweeper review

What this changes

The branch backports recovery that settles Doctor subprocesses, restores compatible package and database state, completes pending migrations, and records Gateway recovery outcomes.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: this member-authored release backport remains useful despite the upstream fixes on main. No concrete patch defect was established, but retained-state compatibility and explicitly excluded production validation remain unresolved.

Priority: P1
Reviewed head: d73af7ce9cf27e6278c9e26aa970633475b86ddb

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The backport is coherent and fixture repairs have focused support, but retained-state compatibility and named integration gaps limit readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: Ordinary contributor proof is exempt for this MEMBER-authored PR. Upstream native recovery evidence remains revision-bound; persisted custody compatibility is independently insufficient, and the captured validation excludes the database-identity projection and interrupted-Doctor guard.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Ordinary contributor proof is exempt for this MEMBER-authored PR. Upstream native recovery evidence remains revision-bound; persisted custody compatibility is independently insufficient, and the captured validation excludes the database-identity projection and interrupted-Doctor guard.
Evidence reviewed 10 items Release backport remains necessary: GitHub confirms an open MEMBER-authored PR targeting release/2026.9.9 at the pinned head. Main's merged fixes do not eliminate this release-branch contribution.
Re-review continuity: The immutable GitHub comparison against the previous reviewed head changes only finalizer tests and their shared fixture. These changes do not resolve the prior retained-state or production-validation gaps. Local historical blob inspection failed; the GitHub comparison supplied the patch evidence.
Introduced persisted contract: The introduced delta adds optional reserved/bound custody to the strict update-action payload. The existing SQLite handoff owner persists reservations before spawning and requires matching claims for binding and retirement.
Findings None None.
Security None None.

How this fits together

The managed updater coordinates package activation, Doctor repairs, database backups, and Gateway restart. Recovery selects a compatible runtime while preserving later writes and the original update failure.

flowchart TD
  A[Managed update request] --> B[Package activation]
  B --> C[Doctor and child writers]
  C --> D[Writer settlement]
  D --> E[Database compatibility decision]
  E --> F[Restore previous runtime]
  E --> G[Repair preserved candidate]
  F --> H[Verified Gateway and recorded outcome]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - Retained custody claims need verified compatibility across interruption, candidate cleanup, and rollback to released strict readers; unresolved claims can block later updates and leave the Gateway stopped.
  • Complete next step (P2) - Record focused passing validation for the database-identity projection and interrupted-Doctor settlement guard, which the captured body explicitly excludes from earlier production coverage.
  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Production versus test growth production/tooling +2130/-512; tests/support +3494/-666 The verified test merge excludes the merged parent layer, and the body justifies growth through distinct package, database, process-custody, and service-recovery responsibilities.

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-command-migrated.ts, migration/backfill/repair: src/infra/update-database-backup.ts, migration/backfill/repair: src/infra/update-database-restore.ts, migration/backfill/repair: src/infra/update-runner-git.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Qualify retained recovery state (recommended)
    Record compatibility evidence for interrupted custody claims, candidate cleanup, and rollback through supported released readers before approving this layer.
  2. Defer the broader recovery layer
    Keep the narrower merged authority repair while preserved-state compatibility remains unqualified.

Technical review

Best possible solution:

Retain the existing recovery owners, verify preserved-state compatibility, and keep canonical final-candidate Full Release Validation as the publication gate.

Do we have a high-confidence way to reproduce the issue?

Yes, for the release baseline: activation Doctor failure after a managed stop, surviving writers, or unfinished agent migrations can prevent recovery. Source and upstream evidence support that path; this review did not execute the candidate.

Is this the best way to solve the issue?

Yes, backporting the existing recovery owners is a coherent repair; retained-state qualification and the explicitly uncovered production changes still need validation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1836ae214644.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Failed activation interrupts a real managed-update workflow and can leave the Gateway unavailable.
  • merge-risk: 🚨 compatibility: The newly persisted custody field is rejected by released strict readers and needs lifecycle compatibility qualification.
  • merge-risk: 🚨 session-state: Database restoration and migration recovery must preserve intervening writes through failure and rollback.
  • merge-risk: 🚨 availability: Retained or unqualified custody claims can prevent recovery and subsequent update admission.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Ordinary contributor proof is exempt for this MEMBER-authored PR. Upstream native recovery evidence remains revision-bound; persisted custody compatibility is independently insufficient, and the captured validation excludes the database-identity projection and interrupted-Doctor guard.

Evidence

What I checked:

  • Release backport remains necessary: GitHub confirms an open MEMBER-authored PR targeting release/2026.9.9 at the pinned head. Main's merged fixes do not eliminate this release-branch contribution. (d73af7ce9cf2)
  • Re-review continuity: The immutable GitHub comparison against the previous reviewed head changes only finalizer tests and their shared fixture. These changes do not resolve the prior retained-state or production-validation gaps. Local historical blob inspection failed; the GitHub comparison supplied the patch evidence. (src/cli/update-cli.finalizer.test.ts:62, d73af7ce9cf2)
  • Introduced persisted contract: The introduced delta adds optional reserved/bound custody to the strict update-action payload. The existing SQLite handoff owner persists reservations before spawning and requires matching claims for binding and retirement. (src/infra/update-managed-service-handoff-schema.ts:56, d73af7ce9cf2)
  • Released-reader compatibility boundary: The v2026.9.8 strict update-action schema lacks custody. Candidate reclamation tests cover dead claims, orphan namespaces, unknown reservations, surviving groups, and changed generations, but exercise the candidate reader rather than a released-reader rollback lifecycle. (src/infra/update-managed-service-handoff-schema.ts:54, fc23bc864e45)
  • Verified merge composition: Raw test-merge parent records exactly match the pinned release base followed by the original PR head. Comparison against that base confirms the custody field and database-identity projection survive the merge; the already-merged requester-authority layer is separate base work. (src/cli/update-cli/update-command-executor.ts:164, 74dddd7f3076)
  • Recovery and authority safeguards: Recovery rejects failed or foreign settlement receipts and interrupted Doctor execution without settlement evidence. Custody uses pinned database identity, live lease checks, native process identity, and complete alias retirement; no concrete introduced authorization bypass was established. (src/cli/update-cli/update-command-service-recovery.ts:220, d73af7ce9cf2)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RomneyDa: 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.

  • Record released-reader compatibility for interrupted custody claims, cleanup, and rollback preservation.
  • Identify passing focused validation for the database-identity projection and interrupted-Doctor settlement guard.

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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-03T22:26:26.754Z sha c841dd9 :: blocked before merge. :: none
  • reviewed 2026-10-03T22:50:14.292Z sha aab3afa :: blocked before merge. :: none
  • reviewed 2026-10-03T23:30:34.426Z sha 2494485 :: blocked before merge. :: none
  • reviewed 2026-10-04T00:16:44.234Z sha 2494485 :: blocked before merge. :: none
  • reviewed 2026-10-04T00:40:49.310Z sha 8c50c49 :: blocked before merge. :: none
  • reviewed 2026-10-04T01:36:54.616Z sha 0030b69 :: blocked before merge. :: none
  • reviewed 2026-10-04T01:49:19.849Z sha 332cb05 :: blocked before merge. :: none
  • reviewed 2026-10-04T02:03:33.370Z sha 72043c0 :: blocked before merge. :: none

@RomneyDa
RomneyDa marked this pull request as ready for review October 3, 2026 21:07
@RomneyDa
RomneyDa marked this pull request as draft October 3, 2026 21:08
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
@RomneyDa
RomneyDa force-pushed the fix/release-2026-9-9-update-recovery branch from 791ca83 to 846b3b2 Compare October 3, 2026 21:45
@RomneyDa RomneyDa changed the title fix(update): restore Gateway after failed 2026.9.9 activation fix(update): recover Gateway after failed activation Oct 3, 2026
@RomneyDa
RomneyDa changed the base branch from release/2026.9.9 to fix/release-2026-9-9-doctor-authority October 3, 2026 21:45
@RomneyDa
RomneyDa marked this pull request as ready for review October 3, 2026 21:45
RomneyDa and others added 5 commits October 3, 2026 15:06
Backport the generic package, database, and service recovery portion of #160671 after the requester-authority fix moved to the parent stack layer.

Source: cd6c9c8
#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)
…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)
@RomneyDa
RomneyDa force-pushed the fix/release-2026-9-9-update-recovery branch from 846b3b2 to ee2b5b7 Compare October 3, 2026 22:07
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 3, 2026
steipete and others added 5 commits October 3, 2026 15:27
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)
…ness 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)
Base automatically changed from fix/release-2026-9-9-doctor-authority to release/2026.9.9 October 4, 2026 00:09
@RomneyDa

RomneyDa commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

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 gateway Gateway 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants