Skip to content

fix(update): roll back activated releases that fail Doctor or Gateway startup - #197851

Merged
obviyus merged 4 commits into
mainfrom
fix/update-post-activation-rollback
Nov 13, 2026
Merged

obviyus merged 4 commits into
mainfrom
fix/update-post-activation-rollback

Conversation

@obviyus

@obviyus obviyus commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

What

Two gaps meant a bad release could stay installed after activation:

  1. Post-activation rollback never had a baseline without the candidate canary. captureUpdateActivationSchemas read the pre-activation state schema versions only when the canary reported candidateSchemaVersions. Without that baseline, rollbackFailedUpdate returns rollback-state-unverified for every post-activation failure and leaves the bad release installed. The baseline is now read for every SQLite-backed update. PostgreSQL keeps the candidate-only read for now; reading a live PostgreSQL baseline before the owning Gateway stops is unproven.
  2. Updates that do not restart a service never booted the activated release. The new activated-gateway-startup step boots it once on real state, with channels, providers, cron and watchers suppressed, and waits for /readyz (2 min budget, fails fast if the process exits). If the Gateway cannot become ready, the update fails into the existing post-activation rollback. The step is skipped, with an advisory, when a running Gateway owns the state, when the profile uses a remote Gateway, or when the Gateway serves TLS (the probe is plain HTTP). It is also skipped when the commit did not change or a service restart will verify readiness itself. Setup failures (port bind, lock read) fail the update into rollback instead of escaping it.

This PR does not remove the candidate canary. It makes the post-activation path safe enough that removing the canary can be evaluated in a follow-up.

Evidence

Isolated git-checkout installs (synthetic state, umask 077), seeded bad releases, real openclaw update --yes --no-restart. The canary was skipped through a local-only experiment flag that is not part of this PR, so the post-activation path is what decides each outcome.

Seeded fault main, canary skipped this PR, canary skipped
Gateway crashes at boot post-update-failed; left on bad commit; Gateway dead activated-gateway-startup-failed (12.4 s); rolled back to base; Gateway healthy
Doctor config transform writes an invalid value rollback-state-unverified; left on bad commit rolled back to base ("Previous package and configuration restored"); Gateway healthy
State migration adds a column, then throws rollback-state-unverified; left on bad commit; Gateway dead doctor-failed; rolled back to base; Gateway healthy
Clean update (no fault) ok ok; boot check 4.5 s

On the exact head 1062ee4 with the candidate canary on (normal path): clean update ok (774 s); Gateway crash refused before activation by the canary (runtime-verification-failed), checkout stayed on base, Gateway healthy.

In the migration case the migration transaction rolled back, so the schema stayed at v39. The baseline comparison is what lets rollback see that.

Data compatibility from the latest stable release. On the head 46c067c, with the canary on:

  • Fresh state was seeded by the published [email protected]: doctor plus a Gateway boot, ready.
  • This head then opened that state: doctor exit 0, Gateway ready.
  • A real openclaw update --yes --no-restart ran on it:
    • Clean update: ok (823 s), checkout on the target commit, Gateway healthy afterwards. Schema versions are unchanged (agent v41). The row-count differences are only bookkeeping: schema_meta, gateway_boot_lifecycle and update_runs.
    • Gateway crash: the canary refused it before activation (runtime-verification-failed). The checkout stayed on this head and the Gateway stayed healthy; the only state change is one update_runs row.

Tests

  • update-activated-gateway-check.test.ts: ready, failed boot, live owner, and an untouched failed result.
  • The execution fixture mocks the new boot check the same way it already mocks the canary, since both cross a process boundary.
  • Five update-cli.preactivation-inspection.test.ts cases fail on main on this host as well; they are not affected by this change.

Accepted edge cases

  • PostgreSQL state keeps the previous canary-dependent baseline.
  • A plugin that fails during load is non-fatal at Gateway startup, so the boot check accepts it, as the canary does.
  • TLS Gateways with --no-restart are not booted; they are verified on their next restart.
  • A running Gateway with --no-restart keeps serving the previous release until its own restart; the update reports that instead of booting a second Gateway on the same state.

… startup

Post-activation rollback refused every failure as rollback-state-unverified
when the candidate canary did not report schema versions, because the
pre-activation state baseline was only read in that case. Read it for every
SQLite-backed update so rollback can compare schemas and restore the previous
release when nothing migrated.

Updates that do not restart a service never booted the activated release.
Boot it once on real state with channels, providers and cron suppressed; a
Gateway that cannot become ready fails the update into the same rollback.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 12, 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 cli CLI command changes size: M labels Nov 12, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Capture SQLite rollback baselines independently of canary metadata and verify eligible activated Gateways before completing updates without restart.

Example: An isolated openclaw update --yes --no-restart activates a release whose Gateway crashes, with the candidate canary bypassed for fault injection.

  • Before: The bad release remains installed because post-activation rollback lacks its schema baseline.
  • After: The startup check fails and the existing rollback restores the previous release.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, correct, and supported by real update recovery and latest-stable compatibility results, with no remaining finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied isolated CLI results exercise post-activation rollback with injected faults and normal canary behavior; current-head results additionally show published 2026.11.3 state loading, successful clean update, unchanged schemas, and a healthy Gateway after candidate refusal.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A failed activated release can remain installed instead of restoring the previous working release.
Reason: The maintainer-authored direction restores existing recovery expectations, preserves the canary, and explicitly records the configurations that remain advisory.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and is ready for ordinary landing consideration: earlier findings are resolved, compatibility evidence clears the previous blocker, and no actionable defect remains.

Priority: P2
Reviewed head: 46c067c8f9559ae863301ddedcd8db16858f5937

Before merge

None.

Findings

None.

Agent review details

How this fits together

The CLI updater coordinates candidate validation, activation, Doctor, verification, and rollback; these changes supply rollback schema facts and feed activated-Gateway startup results into that existing lifecycle.

flowchart TD
  A[CLI update] --> B[Candidate validation]
  B --> C[Capture schema baseline]
  C --> D[Activate and run Doctor]
  D --> E[Service readiness or eligible boot check]
  E --> F[Complete update]
  D --> G[Existing rollback owner]
  E --> G
Loading

Technical review

Best possible solution:

Land the focused baseline and startup checks through the existing update and rollback owners while preserving the documented skips.

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

Current-main source establishes the missing-baseline refusal path, and the author supplies real CLI before-and-after fault results; this review ran no target code.

Is this the best way to solve the issue?

The change repairs baseline capture at its producer and reuses existing process, readiness, and rollback owners; the added modules separate CLI eligibility from the process boundary without creating competing state ownership.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Pre-activation schema capture changes intended behavior with a stated reason (9b3f350: Foreground-update work consolidated activation and recovery under the detached CLI updater; this PR explains why its candidate-dependent baseline prevents later rollback.)
  • Mutable result settlement keeps the original intent (77224e7: The timing repair retained update phase receipts and extracted settlement; the new startup result feeds the existing failure and recovery path.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head patch; the changes are limited to baseline capture, activated startup verification, settlement integration, and supporting tests. (46c067c8f955)
  • Current-main defect remains: Current main still captures schemaVersions only when candidateSchemaVersions exists, while rollbackFailedUpdate refuses restoration without that baseline. (src/cli/update-cli/update-command-schema.ts:536, ee854a1d7579)
  • Earlier findings resolved: The caller requires explicitly local Gateway mode; TLS and live-owner cases produce advisory skips, and lock, entrypoint, and port preparation errors return failed results for rollback. (src/infra/update-activated-gateway-check.ts:70, 46c067c8f955)
  • Production-path and upgrade evidence: The full PR body reports real CLI fault-injection outcomes for Gateway crashes, invalid Doctor output, and failed migrations, plus current-head updates using state seeded by published [email protected] with unchanged schema versions and healthy Gateway results. (46c067c8f955)
  • Accepted scope: The maintainer-authored PR explicitly retains the candidate canary and accepts PostgreSQL's existing baseline behavior, nonfatal plugin-load failures, and advisory skips for TLS and running Gateways. (46c067c8f955)
  • Existing lifecycle owners reused: The boot check uses the existing launcher, readiness observer, termination helper, and --update-canary mode; Gateway startup suppresses autonomous sidecars in that mode. (src/gateway/server-startup-post-attach.ts:297, 46c067c8f955)

PR surface

Source +212, Tests +120. Total +332 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 220 8 +212
Tests 3 120 0 +120
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 340 8 +332

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Improves update recovery for post-activation failures without evidence of an urgent widespread regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-12T18:15:09.932Z sha 1062ee4 :: needs changes before merge. :: [P1] Probe the transport selected by the saved TLS configuration | [P1] Preserve updates for remote-only profiles | [P2] Settle startup preparation errors through the rollback path
  • reviewed 2026-11-13T05:04:23.057Z sha 096c4d0 :: blocked before merge. :: [P1] Skip the boot probe for profiles without a configured local Gateway
  • reviewed 2026-11-13T05:35:40.802Z sha 46c067c :: blocked before merge. :: none

Reviewed November 13, 2026, 1:26 AM ET / 06:26 UTC (Revision 4).

@obviyus
obviyus marked this pull request as ready for review November 13, 2026 04:02
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 096c4d0: remote-only profiles and TLS Gateways now get an advisory non-check instead of a local plain-HTTP boot; lock, entrypoint and port preparation errors return a failed result so post-activation rollback settles them. Tests cover all three.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 46c067c: the activated-release boot now runs only when gateway.mode is explicitly local; unset or remote modes (and TLS) report an advisory non-check without touching saved config. Data-compatibility proof from published [email protected] state is running and will be added to the PR body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 13, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Data-model compatibility proof added to the PR body: state seeded by published [email protected] loads under this head (doctor exit 0, Gateway ready), then a real clean update succeeds with schemas unchanged, and a Gateway-crash release is refused with the Gateway still healthy.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus
obviyus merged commit da0e0ba into main Nov 13, 2026
176 checks passed
@obviyus
obviyus deleted the fix/update-post-activation-rollback branch November 13, 2026 07:38
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
… startup (openclaw#197851)

* fix(update): roll back activated releases that fail Doctor or Gateway startup

Post-activation rollback refused every failure as rollback-state-unverified
when the candidate canary did not report schema versions, because the
pre-activation state baseline was only read in that case. Read it for every
SQLite-backed update so rollback can compare schemas and restore the previous
release when nothing migrated.

Updates that do not restart a service never booted the activated release.
Boot it once on real state with channels, providers and cron suppressed; a
Gateway that cannot become ready fails the update into the same rollback.

Co-authored-by: obviyus <[email protected]>

* test(update): isolate the activated-release boot in CLI fixtures

Co-authored-by: obviyus <[email protected]>

* fix(update): skip the activated boot for remote and TLS Gateways and settle its setup errors

Co-authored-by: obviyus <[email protected]>

* fix(update): boot the activated release only for explicitly local Gateways

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 14, 2026
… startup (#197851)

* fix(update): roll back activated releases that fail Doctor or Gateway startup

Post-activation rollback refused every failure as rollback-state-unverified
when the candidate canary did not report schema versions, because the
pre-activation state baseline was only read in that case. Read it for every
SQLite-backed update so rollback can compare schemas and restore the previous
release when nothing migrated.

Updates that do not restart a service never booted the activated release.
Boot it once on real state with channels, providers and cron suppressed; a
Gateway that cannot become ready fails the update into the same rollback.

Co-authored-by: obviyus <[email protected]>

* test(update): isolate the activated-release boot in CLI fixtures

Co-authored-by: obviyus <[email protected]>

* fix(update): skip the activated boot for remote and TLS Gateways and settle its setup errors

Co-authored-by: obviyus <[email protected]>

* fix(update): boot the activated release only for explicitly local Gateways

Co-authored-by: obviyus <[email protected]>

---------

Co-authored-by: obviyus <[email protected]>

(cherry picked from commit da0e0ba)

Release adaptation: retain the release canary entry API; capture the baseline
unconditionally because this release's state and agent stores are SQLite.
Do not import newer PostgreSQL family-selection internals.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit 5e8319192c2915057b43043dead1a9ec376fa51a)
obviyus added a commit that referenced this pull request Nov 15, 2026
…eck (#198268)

## Problem

Before activation, `openclaw update` rehearses the candidate. It copies all SQLite state and plugin payloads into a scratch directory, runs the candidate's `doctor --fix`, `doctor --lint`, `config validate` and `plugins list` against the copy, then boots a private Gateway on it. On Peanutto's production-sized state this took 10–15 minutes of a 26-minute update (about 46%).

#197851 made that rehearsal redundant. Post-activation rollback now always has a pre-activation SQLite schema baseline, and `--no-restart` updates boot the activated release once (`activated-gateway-startup`) and roll back when it cannot become ready. Doctor and Gateway startup are proven on real state after activation, with rollback.

## Change

The driver no longer rehearses. Before activation it runs only the candidate's recovery worker once: `update-migrated-finalize --check` (step `candidate-recovery`). That one stateless call already produced every canary output used later:

| Canary output | Replacement |
| --- | --- |
| `candidateSchemaVersions` (activation schema baseline, PostgreSQL baseline gate, post-Doctor schema check) | `--check` `state`/`agent` |
| `gatewayRestartCompletion` | `--check` `gatewayRestartCompletion` |
| `doctorConfigWrites` (delegated Doctor config writes) | `--check` `doctorConfigWrites: "pid-start-v1"` |
| `doctorConfigChanges` | Removed. Activation Doctor reports its own `configChanges` and refusal keys. |
| `validatedConfigSnapshot` | Unchanged: the config read before the check |
| Observed canary Gateway startup ms (previous-Gateway readiness window) | Removed; the existing five-minute floor or `--timeout` applies |
| Missing worker → "uses the current updater" advisory | Kept as-is |

Call sites:

- `openclaw update` (`validateUpdateCandidateWithProgress`) calls `checkUpdateCandidate`. The progress-writer and state-worker scaffolding that kept WAL readable during the copy is gone.
- `openclaw update preflight` (external supervisors) reads config and runs `--check`. Its receipt `coverage` changes from `isolated-core-startup` to `candidate-runtime`, so a supervisor can tell the weaker proof apart. `--source-root` is still accepted.
- Immutable activation runs `--check` before drain and before rollback. The post-start private canary and its second observation are removed; live readiness verification and rollback are unchanged.
- `snapshot-space-preflight` keeps only the activation database backup/rollback space check.
- Automatic-update backoff keys on repeated identical activation failures (`openclaw doctor`, `post-update verification`, `activated-gateway-startup`) instead of `candidate-doctor`, which no longer runs. It counts runs recorded as `rolled-back` as well as `failed`, because a failed activation usually restores the previous release (ClawSweeper finding; the `rolled back` campaign case fails without it).
- The previous-Gateway readiness budget uses the existing floor (5 min, 90 min on Windows) or `--timeout`.
- **Fix found by E2E:** `captureUpdateDatabases` retires idle state-read workers before acquiring capture ownership. A reader started before activation lazy-imported `gateway-owner-lease.worker` by its old hashed chunk name; when the target rehashes that chunk the ownership check fails and automatic restore is disabled.
- **Fix found by E2E:** the no-restart `activated-gateway-startup` boot (#197851) writes boot bookkeeping to real state, after which database rollback saw "changes after Doctor" and refused. `adoptUpdateBootDatabaseWrites` attributes the boot's own writes to the update when nothing else wrote since Doctor. Accepted edge case: a foreign write during the boot window is attributed the same way. Covered by the `activated-boot` case of `update-command-database-rollback.test.ts` (settlement and restore, not helper output).
- Restore uses the plugin-cohort binding captured before Doctor, because the previous build cannot open a state database Doctor migrated to a newer schema (`newer-schema` case).

### #197922's delegated rehearsal is removed

#197922 (merged 11-14) made the candidate run its own rehearsal (`openclaw update rehearse`, package marker `openclaw.updateRehearsalProtocol: 1`) when the installed updater supports delegation. This PR removes the rehearsal, so it also removes the delegation: the driver-side delegated rehearsal, the candidate-side `update rehearse` command, the rehearsal contract and the marker (−1,803 lines of #197922).

- **No released version depends on it.** `git tag --contains 3ab80ab` lists only `release-publish/*` cuts of 2026.11.3; `v2026.11.3` (npm `latest`) and `v2026.11.5-beta.1..3` do not contain it, and `npm view [email protected] openclaw.updateRehearsalProtocol` is empty. Per AGENTS.md, main and beta are not shipped contracts.
- **Updaters built from main since #197922 fall back.** When the target lacks the marker, they run their own rehearsal (the path #197922 kept for unsupported targets). Proven below: a main updater (merge base, which contains #197922) updated to this branch, rehearsed it itself and finished `ok`.

### Rollback no longer runs without the retained runtime

Runtime retention copies the running updater so its lazy imports and workers keep working after the package or checkout is replaced. Since #185178 a retention failure only logged "continuing update without a verified retained rollback runtime". With the canary gone, rollback is the only safety net, and it loads code from that retained runtime.

Reproduced (package install, retention fault injected, then a migration that commits and a Doctor that fails): Doctor committed the migration, `database rollback` failed with `Cannot find module …/dist/update-candidate-state-<hash>.mjs`, the update ended `state-migrated-no-rollback` and **left the target release active**. The same faults without the retention failure roll back the databases and the package.

Chosen behavior: **every retention failure now stops the update before staging or activation**, with "Could not retain the running updater (<reason>). The update stopped before changing the installation; retry it." Cancellation and uncertain subprocess cleanup still propagate unchanged.

- Least complex: it deletes #185178's fallback (−26 production lines) instead of making rollback independent of the copy, which would mean preloading every lazy rollback import and pinning every worker entry, a second retention mechanism.
- Measured cost on large installs: #185178 was motivated by a worker output cap that #184958 has since fixed. Peanutto (183k entries, ~4 GB retained) completed retention on all 17 updates since 2026-10-27, so this refusal would not have fired once. The remaining causes are a source file changing during the copy (retry) and a host-owned plugin link (documented fix in `docs/cli/update.md#runtime-retention-failures`).
- Retention itself goes away with Git releases in a later slice; this does not redesign it.

### What was removed

- Driver: `update-candidate-canary.ts`, `update-candidate-canary-commands.ts`, canary-only lint/failure/config helpers, Git startup-runtime selection, the validation wrapper scaffolding, and #197922's delegated rehearsal.
- Candidate: `update rehearse`, `update-rehearsal-contract.ts`, the `updateRehearsalProtocol` marker.
- #185178's retention fallback.
- Tests: the canary suites and their test-support, and the delegated-rehearsal tests.

Against the merge base: **production +383 / −2,198** (net −1,815), tests +648 / −6,140, docs +111 / −134, config −18.

### What stays, and why

Released updaters, including stable 2026.11.3, still rehearse whatever candidate they install, using **the candidate's** state-copy worker, rehearsal-aware Doctor and lint, `update-candidate-rehearsal`/`-snapshot`, plugin-tree copy and `--update-canary` startup progress. Deleting those would break upgrades from every shipped version, so the candidate side stays until no supported update source runs the canary. Historical step identities (`candidate-doctor` etc.) stay so existing `update_runs` history renders.

## Review findings

- **Config-convergence test** (`update-cli.config-convergence.test.ts`): the stateless check no longer receives config, so the test now asserts what the check does receive at its boundary, the owning profile's `stateDir` and `OPENCLAW_CONFIG_PATH`, keeps an explicit `candidate-recovery` refusal through the result contract, and asserts authored config bytes are unchanged.
- **Data-model compatibility:** no schema, config or stored-data shape changes. Existing state from 2026.11.3 (state schema 22 → 40) and Peanutto's production databases (3.3 GB) load through the real update path below.
- **Boot-writes test:** replaced by the `activated-boot` settlement-and-restore case in the database rollback matrix; it fails when boot-write adoption is disabled.

## Evidence

Harness: real `openclaw update --yes --no-restart --json --tag <packed tarball>` from an npm-global install on isolated `env -i` state (cloned per run with `cp -c`), run on mbp-m5, three at a time. Base = merge base `1e64efd` with inert env-gated faults; head = this branch on the same base (`8065ed6`; the "with fix" rows use `097a6ba`, the retention fix before its refusal wording). The merged head `97ca0de` is that change with current `main` merged in. Fault targets are the same tarball plus env-gated faults: `gateway-crash` (Gateway throws at boot), `plugin-crash` (acpx throws at load), `migration-broken` (state v41 adds a column then throws), `committed-migration` (v41 commits, then Doctor throws), `retention` (runtime retention throws after the native helper is bound). "Gateway after" = a fresh Gateway on the post-update state reaches `/readyz`. Schema = state `user_version` after the run (base 40, fault target 41).

| Case | main (canary) | this PR |
| --- | --- | --- |
| clean update | ok; validating 65 s (retention 18, candidate Doctor 7, candidate Gateway 6) | ok; validating 52 s (retention 32, `candidate-recovery` + admission ~20); **no candidate Doctor/Gateway phase** |
| gateway crash | refused at `candidate-gateway-startup`; base kept | activated, `activated-gateway-startup` failed → **database rollback + package rollback**; base active; Gateway after ok |
| committed migration + failed Doctor | refused at `candidate-doctor` | v41 committed, Doctor failed → **database rollback (state back to v40) + package rollback**; base active; Gateway after ok |
| broken migration | refused at `candidate-doctor` | Doctor failed → database + package rollback; state v40; Gateway after ok |
| plugin crash | ok (plugin failure recorded) | ok (plugin failure recorded) |
| retention failure + gateway crash | refused at `candidate-gateway-startup` | before fix: rolled back; **with fix: refused before activation** |
| retention failure + committed migration | refused at `candidate-doctor` | before fix: **`Cannot find module`, rollback failed, `state-migrated-no-rollback`, target left active, state stuck at v41**; with fix: refused before staging, base active, state v40, Gateway after ok |
| 2026.11.3 → head | — | ok (2026.11.3's own canary against the kept candidate surfaces); state schema 22 → 40; Gateway after ok |
| main updater (contains #197922) → head | — | target lacks the marker → updater ran its own rehearsal → ok; Gateway after ok |
| Peanutto-shaped clean update (3.28 GB SQLite: Peanutto's state + 3.1 GB agent DB, its plugin set) | ok; **validating 236 s** (retention 50, candidate snapshot 47, candidate Doctor 64, lint 22, candidate Gateway 27); update 949 s | ok; **validating 68 s** (retention 50, `candidate-recovery` + admission ~18); update 839 s; Gateway after ok |

Peanutto-shaped: the validating phase drops by **168 s** (236 → 68 s), all of it the four rehearsal steps (160 s). Those two runs overlapped each other, so their activation and total times are not a clean comparison; small-state wall times are likewise not comparable across rows (runs overlapped three at a time). The ~950 s mean saving estimated from Peanutto's live history (where the candidate Doctor took 200–670 s) is unmeasured here.

Tests: 31 touched update test files plus the admission test pass (mbp-m5, `ocx test`, 957 s). The retention suites pass (50); 7 of them fail on the previous head because retention resolved instead of stopping. `pnpm tsgo:core`, `pnpm check:test-types`, oxfmt clean. oxlint reports one inherited `max-lines` on `update-command-service-maintenance.ts` (750 lines here, 756 on main).


**Exact-head check on `97ca0de`** (same harness, run after the last merge of `main`): 2026.11.3 → head ok, schema 22 → 40, Gateway after ok (398 s); clean head update ok, schema unchanged, Gateway after ok (383 s); Peanutto-shaped clean update ok, Gateway after ok (738 s).

### CI notes

- `update-cli.candidate-admission.test.ts` > "blocks package updates when the target requires a newer Node runtime" still asserted the multi-line diagnostic that `764761e` moved into the saved report; it fails the same way on main `f24c2097`, whose changed-lane CI does not select this suite. Updated to assert the one-line refusal and the recovery steps.
- `extensions/a2a/src/inbound.test.ts` (interleaved same-context replies) failed in an earlier run of this PR and fails locally on main `f24c2097` too; this PR does not touch that plugin. The branch now includes main through #199736, the fix for the earlier memory-core `manager-shadow-write.test.ts` failure.
- `src/gateway/github-pr-workspace-preparation.test.ts` > "recovers an interrupted initial exact install (bound runtime=true)" (`checks-node-changed-compact-large-22`) fails 3/3 locally on both this head `97ca0de5` and main `e182b8d5`, also fails on main `a1dd4938`, and failed again on the rerun of the failed job (run 43763967024, attempt 2), with the same `expect(runtime?.isPaused()).toBe(true)` assertion at line 884. This PR does not touch `src/gateway`.

## Accepted edge cases

- Problems only Doctor or Gateway startup reveal are found after activation. The update rolls back the release and the pre-activation database baseline instead of refusing first: one activation/rollback cycle (with restart, a brief Gateway outage) in exchange for skipping the rehearsal on every successful update.
- `--no-restart` with a Gateway still running the old code: the activated release is not booted (reported), as in #197851.
- External supervisors using `update preflight` get less proof (`coverage: "candidate-runtime"`) and must verify readiness after activation.
- A retention failure now stops the update; the user retries or fixes the named cause.

## Gaps

- `checks-fast-baseline-ratchets` on `dffdf91` reported `database-worker`/`database-dialect` failures after a runner shutdown signal. Both ratchets pass locally against the merge base (`SQLite T1 live calls: 166 -> 166`; dialect: no construct-group growth).

- The Git-checkout path was not re-run in this round (the m5 repository was mid-repack). Retention and rollback share one owner across package and Git installs, and the earlier Git runs are in this PR's history.
- The fixed refusal message was proven in unit tests; the E2E refusal ran on the fix before the message wording was added.
- The main updater at the merge base refuses a relocated state directory in its canary snapshot ("Restored client credentials do not match the captured shared database": the credential receipt pins the shared database inode). The harness repoints the receipt after each `cp -c`; head never runs that snapshot.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…eck (openclaw#198268)

## Problem

Before activation, `openclaw update` rehearses the candidate. It copies all SQLite state and plugin payloads into a scratch directory, runs the candidate's `doctor --fix`, `doctor --lint`, `config validate` and `plugins list` against the copy, then boots a private Gateway on it. On Peanutto's production-sized state this took 10–15 minutes of a 26-minute update (about 46%).

openclaw#197851 made that rehearsal redundant. Post-activation rollback now always has a pre-activation SQLite schema baseline, and `--no-restart` updates boot the activated release once (`activated-gateway-startup`) and roll back when it cannot become ready. Doctor and Gateway startup are proven on real state after activation, with rollback.

## Change

The driver no longer rehearses. Before activation it runs only the candidate's recovery worker once: `update-migrated-finalize --check` (step `candidate-recovery`). That one stateless call already produced every canary output used later:

| Canary output | Replacement |
| --- | --- |
| `candidateSchemaVersions` (activation schema baseline, PostgreSQL baseline gate, post-Doctor schema check) | `--check` `state`/`agent` |
| `gatewayRestartCompletion` | `--check` `gatewayRestartCompletion` |
| `doctorConfigWrites` (delegated Doctor config writes) | `--check` `doctorConfigWrites: "pid-start-v1"` |
| `doctorConfigChanges` | Removed. Activation Doctor reports its own `configChanges` and refusal keys. |
| `validatedConfigSnapshot` | Unchanged: the config read before the check |
| Observed canary Gateway startup ms (previous-Gateway readiness window) | Removed; the existing five-minute floor or `--timeout` applies |
| Missing worker → "uses the current updater" advisory | Kept as-is |

Call sites:

- `openclaw update` (`validateUpdateCandidateWithProgress`) calls `checkUpdateCandidate`. The progress-writer and state-worker scaffolding that kept WAL readable during the copy is gone.
- `openclaw update preflight` (external supervisors) reads config and runs `--check`. Its receipt `coverage` changes from `isolated-core-startup` to `candidate-runtime`, so a supervisor can tell the weaker proof apart. `--source-root` is still accepted.
- Immutable activation runs `--check` before drain and before rollback. The post-start private canary and its second observation are removed; live readiness verification and rollback are unchanged.
- `snapshot-space-preflight` keeps only the activation database backup/rollback space check.
- Automatic-update backoff keys on repeated identical activation failures (`openclaw doctor`, `post-update verification`, `activated-gateway-startup`) instead of `candidate-doctor`, which no longer runs. It counts runs recorded as `rolled-back` as well as `failed`, because a failed activation usually restores the previous release (ClawSweeper finding; the `rolled back` campaign case fails without it).
- The previous-Gateway readiness budget uses the existing floor (5 min, 90 min on Windows) or `--timeout`.
- **Fix found by E2E:** `captureUpdateDatabases` retires idle state-read workers before acquiring capture ownership. A reader started before activation lazy-imported `gateway-owner-lease.worker` by its old hashed chunk name; when the target rehashes that chunk the ownership check fails and automatic restore is disabled.
- **Fix found by E2E:** the no-restart `activated-gateway-startup` boot (openclaw#197851) writes boot bookkeeping to real state, after which database rollback saw "changes after Doctor" and refused. `adoptUpdateBootDatabaseWrites` attributes the boot's own writes to the update when nothing else wrote since Doctor. Accepted edge case: a foreign write during the boot window is attributed the same way. Covered by the `activated-boot` case of `update-command-database-rollback.test.ts` (settlement and restore, not helper output).
- Restore uses the plugin-cohort binding captured before Doctor, because the previous build cannot open a state database Doctor migrated to a newer schema (`newer-schema` case).

### openclaw#197922's delegated rehearsal is removed

openclaw#197922 (merged 11-14) made the candidate run its own rehearsal (`openclaw update rehearse`, package marker `openclaw.updateRehearsalProtocol: 1`) when the installed updater supports delegation. This PR removes the rehearsal, so it also removes the delegation: the driver-side delegated rehearsal, the candidate-side `update rehearse` command, the rehearsal contract and the marker (−1,803 lines of openclaw#197922).

- **No released version depends on it.** `git tag --contains e32cb9a` lists only `release-publish/*` cuts of 2026.11.3; `v2026.11.3` (npm `latest`) and `v2026.11.5-beta.1..3` do not contain it, and `npm view [email protected] openclaw.updateRehearsalProtocol` is empty. Per AGENTS.md, main and beta are not shipped contracts.
- **Updaters built from main since openclaw#197922 fall back.** When the target lacks the marker, they run their own rehearsal (the path openclaw#197922 kept for unsupported targets). Proven below: a main updater (merge base, which contains openclaw#197922) updated to this branch, rehearsed it itself and finished `ok`.

### Rollback no longer runs without the retained runtime

Runtime retention copies the running updater so its lazy imports and workers keep working after the package or checkout is replaced. Since openclaw#185178 a retention failure only logged "continuing update without a verified retained rollback runtime". With the canary gone, rollback is the only safety net, and it loads code from that retained runtime.

Reproduced (package install, retention fault injected, then a migration that commits and a Doctor that fails): Doctor committed the migration, `database rollback` failed with `Cannot find module …/dist/update-candidate-state-<hash>.mjs`, the update ended `state-migrated-no-rollback` and **left the target release active**. The same faults without the retention failure roll back the databases and the package.

Chosen behavior: **every retention failure now stops the update before staging or activation**, with "Could not retain the running updater (<reason>). The update stopped before changing the installation; retry it." Cancellation and uncertain subprocess cleanup still propagate unchanged.

- Least complex: it deletes openclaw#185178's fallback (−26 production lines) instead of making rollback independent of the copy, which would mean preloading every lazy rollback import and pinning every worker entry, a second retention mechanism.
- Measured cost on large installs: openclaw#185178 was motivated by a worker output cap that openclaw#184958 has since fixed. Peanutto (183k entries, ~4 GB retained) completed retention on all 17 updates since 2026-10-27, so this refusal would not have fired once. The remaining causes are a source file changing during the copy (retry) and a host-owned plugin link (documented fix in `docs/cli/update.md#runtime-retention-failures`).
- Retention itself goes away with Git releases in a later slice; this does not redesign it.

### What was removed

- Driver: `update-candidate-canary.ts`, `update-candidate-canary-commands.ts`, canary-only lint/failure/config helpers, Git startup-runtime selection, the validation wrapper scaffolding, and openclaw#197922's delegated rehearsal.
- Candidate: `update rehearse`, `update-rehearsal-contract.ts`, the `updateRehearsalProtocol` marker.
- openclaw#185178's retention fallback.
- Tests: the canary suites and their test-support, and the delegated-rehearsal tests.

Against the merge base: **production +383 / −2,198** (net −1,815), tests +648 / −6,140, docs +111 / −134, config −18.

### What stays, and why

Released updaters, including stable 2026.11.3, still rehearse whatever candidate they install, using **the candidate's** state-copy worker, rehearsal-aware Doctor and lint, `update-candidate-rehearsal`/`-snapshot`, plugin-tree copy and `--update-canary` startup progress. Deleting those would break upgrades from every shipped version, so the candidate side stays until no supported update source runs the canary. Historical step identities (`candidate-doctor` etc.) stay so existing `update_runs` history renders.

## Review findings

- **Config-convergence test** (`update-cli.config-convergence.test.ts`): the stateless check no longer receives config, so the test now asserts what the check does receive at its boundary, the owning profile's `stateDir` and `OPENCLAW_CONFIG_PATH`, keeps an explicit `candidate-recovery` refusal through the result contract, and asserts authored config bytes are unchanged.
- **Data-model compatibility:** no schema, config or stored-data shape changes. Existing state from 2026.11.3 (state schema 22 → 40) and Peanutto's production databases (3.3 GB) load through the real update path below.
- **Boot-writes test:** replaced by the `activated-boot` settlement-and-restore case in the database rollback matrix; it fails when boot-write adoption is disabled.

## Evidence

Harness: real `openclaw update --yes --no-restart --json --tag <packed tarball>` from an npm-global install on isolated `env -i` state (cloned per run with `cp -c`), run on mbp-m5, three at a time. Base = merge base `6b9404d` with inert env-gated faults; head = this branch on the same base (`8065ed6`; the "with fix" rows use `097a6ba`, the retention fix before its refusal wording). The merged head `97ca0de` is that change with current `main` merged in. Fault targets are the same tarball plus env-gated faults: `gateway-crash` (Gateway throws at boot), `plugin-crash` (acpx throws at load), `migration-broken` (state v41 adds a column then throws), `committed-migration` (v41 commits, then Doctor throws), `retention` (runtime retention throws after the native helper is bound). "Gateway after" = a fresh Gateway on the post-update state reaches `/readyz`. Schema = state `user_version` after the run (base 40, fault target 41).

| Case | main (canary) | this PR |
| --- | --- | --- |
| clean update | ok; validating 65 s (retention 18, candidate Doctor 7, candidate Gateway 6) | ok; validating 52 s (retention 32, `candidate-recovery` + admission ~20); **no candidate Doctor/Gateway phase** |
| gateway crash | refused at `candidate-gateway-startup`; base kept | activated, `activated-gateway-startup` failed → **database rollback + package rollback**; base active; Gateway after ok |
| committed migration + failed Doctor | refused at `candidate-doctor` | v41 committed, Doctor failed → **database rollback (state back to v40) + package rollback**; base active; Gateway after ok |
| broken migration | refused at `candidate-doctor` | Doctor failed → database + package rollback; state v40; Gateway after ok |
| plugin crash | ok (plugin failure recorded) | ok (plugin failure recorded) |
| retention failure + gateway crash | refused at `candidate-gateway-startup` | before fix: rolled back; **with fix: refused before activation** |
| retention failure + committed migration | refused at `candidate-doctor` | before fix: **`Cannot find module`, rollback failed, `state-migrated-no-rollback`, target left active, state stuck at v41**; with fix: refused before staging, base active, state v40, Gateway after ok |
| 2026.11.3 → head | — | ok (2026.11.3's own canary against the kept candidate surfaces); state schema 22 → 40; Gateway after ok |
| main updater (contains openclaw#197922) → head | — | target lacks the marker → updater ran its own rehearsal → ok; Gateway after ok |
| Peanutto-shaped clean update (3.28 GB SQLite: Peanutto's state + 3.1 GB agent DB, its plugin set) | ok; **validating 236 s** (retention 50, candidate snapshot 47, candidate Doctor 64, lint 22, candidate Gateway 27); update 949 s | ok; **validating 68 s** (retention 50, `candidate-recovery` + admission ~18); update 839 s; Gateway after ok |

Peanutto-shaped: the validating phase drops by **168 s** (236 → 68 s), all of it the four rehearsal steps (160 s). Those two runs overlapped each other, so their activation and total times are not a clean comparison; small-state wall times are likewise not comparable across rows (runs overlapped three at a time). The ~950 s mean saving estimated from Peanutto's live history (where the candidate Doctor took 200–670 s) is unmeasured here.

Tests: 31 touched update test files plus the admission test pass (mbp-m5, `ocx test`, 957 s). The retention suites pass (50); 7 of them fail on the previous head because retention resolved instead of stopping. `pnpm tsgo:core`, `pnpm check:test-types`, oxfmt clean. oxlint reports one inherited `max-lines` on `update-command-service-maintenance.ts` (750 lines here, 756 on main).


**Exact-head check on `97ca0de`** (same harness, run after the last merge of `main`): 2026.11.3 → head ok, schema 22 → 40, Gateway after ok (398 s); clean head update ok, schema unchanged, Gateway after ok (383 s); Peanutto-shaped clean update ok, Gateway after ok (738 s).

### CI notes

- `update-cli.candidate-admission.test.ts` > "blocks package updates when the target requires a newer Node runtime" still asserted the multi-line diagnostic that `4281497` moved into the saved report; it fails the same way on main `7e26d771`, whose changed-lane CI does not select this suite. Updated to assert the one-line refusal and the recovery steps.
- `extensions/a2a/src/inbound.test.ts` (interleaved same-context replies) failed in an earlier run of this PR and fails locally on main `7e26d771` too; this PR does not touch that plugin. The branch now includes main through openclaw#199736, the fix for the earlier memory-core `manager-shadow-write.test.ts` failure.
- `src/gateway/github-pr-workspace-preparation.test.ts` > "recovers an interrupted initial exact install (bound runtime=true)" (`checks-node-changed-compact-large-22`) fails 3/3 locally on both this head `97ca0de5` and main `ec3e3d7e`, also fails on main `9a5e62f0`, and failed again on the rerun of the failed job (run 43763967024, attempt 2), with the same `expect(runtime?.isPaused()).toBe(true)` assertion at line 884. This PR does not touch `src/gateway`.

## Accepted edge cases

- Problems only Doctor or Gateway startup reveal are found after activation. The update rolls back the release and the pre-activation database baseline instead of refusing first: one activation/rollback cycle (with restart, a brief Gateway outage) in exchange for skipping the rehearsal on every successful update.
- `--no-restart` with a Gateway still running the old code: the activated release is not booted (reported), as in openclaw#197851.
- External supervisors using `update preflight` get less proof (`coverage: "candidate-runtime"`) and must verify readiness after activation.
- A retention failure now stops the update; the user retries or fixes the named cause.

## Gaps

- `checks-fast-baseline-ratchets` on `dffdf91` reported `database-worker`/`database-dialect` failures after a runner shutdown signal. Both ratchets pass locally against the merge base (`SQLite T1 live calls: 166 -> 166`; dialect: no construct-group growth).

- The Git-checkout path was not re-run in this round (the m5 repository was mid-repack). Retention and rollback share one owner across package and Git installs, and the earlier Git runs are in this PR's history.
- The fixed refusal message was proven in unit tests; the E2E refusal ran on the fix before the message wording was added.
- The main updater at the merge base refuses a relocated state directory in its canary snapshot ("Restored client credentials do not match the captured shared database": the credential receipt pins the shared database inode). The harness repoints the receipt after each `cp -c`; head never runs that snapshot.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

1 participant