Skip to content

fix(update): avoid snapshot failures in live recovery checks - #191332

Merged
vincentkoc merged 6 commits into
mainfrom
fix/live-recovery-admission-20261103
Nov 3, 2026
Merged

vincentkoc merged 6 commits into
mainfrom
fix/live-recovery-admission-20261103

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #191331

What Problem This Solves

Update recovery admission and reconciliation can copy an entire SQLite database to read a small amount of metadata. A concurrent checkpoint can invalidate that copy and refuse an update with wal-copy-unstable. Async progress bookkeeping can repeat the copy after initial admission.

User Impact

Qualified live or cleanly closed databases now use the existing isolated metadata reader. Cold, retained, unknown and maintenance-owned sources retain their private-read protections. Metadata inspection grants no execution authority; the updater retains recovery and continuation decisions.

How It Works

One fixed command reads recovery reservations and companions in the same snapshot. Reconciliation and async progress use that boundary, while the writer still rechecks recovery in its synchronous transaction. Shared recovery facts live in the existing low-level store, avoiding eager update-policy imports from ordinary config and plugin reads.

The worker awaits asynchronous operation preparation while retaining active-work ownership. After lazy loading and before native SQLite access, it rechecks its original physical identity and lifetime. Existing post-read identity checks, transfer cleanup and shutdown settlement remain in place. No schema or configuration changes are introduced.

Compiled finalizer fixtures explicitly include their manifest-selected spawn broker. The fixture copier uses the canonical dist-root resolver for nested entries while retaining mixed-generation refusal and narrow dependency closure. The native wrapper inventory includes the required source closure.

Production growth is net 110 lines for the shared read/lifecycle boundary; test sources add 386 lines. Duplicate reconciliation dispatch is removed. No retries, timeouts or ownership checks are weakened.

Evidence

  • Before: the test-only baseline reproduced wal-copy-unstable after ten snapshot attempts on Node 24.22.1 and pinned Bun. Baseline CI.
  • After: at ccd99233779a1f1e74761589ccb21754a317d3f9, all 15 recovery-admission cases passed on both Node and Bun, including the original live checkpoint-writer case, warm reconciliation, clean close, retained snapshots, retargeting, and pending/orphan recovery refusal. Regression proof.
  • The corrected compiled Bun finalizer cases passed with normal cleanup; their shard passed all 62 tests. Finalizer proof. Build Artifacts and Darwin also passed at that head. The tested merge was e095f4f5cfc4df8095e134fdc5937c5e630228de, combining main b571be3ad980307803f343a373275d225466b6d8 and the reviewed head.
  • Final-head qualification passed at 844995f0c84c6a327fcb7ee54dd243566decd3a9: CI (69 passed, 27 skipped), Build Artifacts, and Darwin. All attempt 1, with no failed or unfinished jobs. The tested merge was 1fe19f0c25db91190895534044a11ed381cbf92e, parents main 44ea3371d4340868ae53c7c3196f1ffb81940b0f and this head. The exact-head ClawSweeper review has no findings or before-merge actions.
  • Production passed independent source review and six complete structured review passes covering the corrective delta and its owner contracts. Fixture, mechanical lint and overlapping main changes received separate scoped reviews. Signed hooks, targeted formatting, whitespace and the test-line ratchet passed. Source review is separate from runtime proof.

Follow-ups: synchronous runtime-provisioner child-custody observation can still require a private snapshot before service stop; initialization can precede the advertised overall update deadline. This PR does not claim every updater metadata read is copy-free or fix that deadline gap.

@vincentkoc vincentkoc self-assigned this Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 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 scripts Repository scripts size: XS labels Nov 2, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 2, 2026 17:26
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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. 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-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR routes qualified update recovery and reconciliation reads through the existing isolated metadata reader instead of copying the entire SQLite database.

Example: An update checks recovery metadata while the running Gateway checkpoints its SQLite WAL.

  • Before: The private copy can fail with wal-copy-unstable after ten attempts and refuse the update.
  • After: Qualified live sources use a pinned metadata transaction while pending or malformed recovery still refuses admission.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with meaningful native boundary coverage and no actionable findings; supplied behavior evidence remains harness-based and current-head CI is pending.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied support exercises recovery admission, reconciliation, progress writes, and native lifecycle boundaries in tests rather than a shipped CLI update, and redirected CI logs could not be inspected.
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 running Gateway's SQLite checkpoints can cause recovery metadata inspection to refuse an update with wal-copy-unstable.
Reason: The maintainer-authored repair removes unnecessary database copies at the demonstrated boundary while retaining recovery refusal and artifact-preservation contracts.

Merge readiness

✅ Ready for maintainer review

This PR addresses a concrete update failure, resolves the previous finding, and has no actionable correctness findings at the reviewed head; exact-head CI remains pending.

Priority: P2
Reviewed head: 844995f0c84c6a327fcb7ee54dd243566decd3a9

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not show an installed CLI update against a checkpointing Gateway; the committed regression exercises the production read owner and native subprocesses through a test harness.
Agent review details

How this fits together

The updater requests recovery and reconciliation facts from shared-state readers, then applies recovery policy and rechecks live executor authority before transactional bookkeeping.

flowchart TD
A[Update command] --> B[Recovery admission]
B --> C[Shared state read owner]
C --> D[Qualified isolated metadata reader]
C --> E[Private snapshot fallback]
D --> F[Updater recovery policy]
E --> F
F --> G[Transactional bookkeeping]
Loading

Technical review

Best possible solution:

Keep the focused shared-reader repair and its recovery safeguards, then land through the normal exact-head CI gate.

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

Current main retains the snapshot-backed recovery path identified in #191331, and the committed regression exercises admission against a real checkpoint-writing subprocess; no target code was run during this review.

Is this the best way to solve the issue?

The patch fixes the read boundary through existing owners, consolidates reconciliation dispatch, and preserves separate private-snapshot and synchronous writer contracts without adding state, retries, or configuration.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Production repair replaces the previously failing path: Recovery admission now awaits a fixed shared-state command and evaluates returned facts with the existing updater policy; fetched main still uses the synchronous recovery reader. (src/infra/update-run-recovery-admission.ts:35, 844995f0c84c)
  • Coherent recovery facts retain existing ownership: Reservations and companion records are read together through the existing store and transaction owner; continuation decisions remain with the updater. (src/infra/update-run-recovery-store.ts:46, 844995f0c84c)
  • Source identity and lifecycle checks survive asynchronous preparation: The child awaits operation preparation, rechecks its original lifetime and physical identity before native access, and retains post-read identity checks and settlement ownership. (src/state/startup-metadata-live-read.worker.ts:62, 844995f0c84c)
  • Final transactional recovery guard remains: The mutation worker still verifies recovery bindings inside its transaction and requests live admission before transaction and commit. (src/infra/update-run-mutation.worker.ts:101, 844995f0c84c)
  • Preceding-head regression jobs passed: GitHub reports success for the cited recovery-admission and compiled-finalizer jobs at ccd9923. Raw log retrieval was blocked by the environment's redirected storage-host allowlist, so individual log assertions were not independently inspected. (ccd99233779a)
  • Current correction is mechanical: The preceding tested head differs only by replacing sort with toSorted in the metadata identity test. (src/state/startup-metadata-live-read.worker.test.ts:56, 844995f0c84c)

PR surface

Source +110, Tests +386, Other +9. Total +505 across 28 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 14 261 151 +110
Tests 11 410 24 +386
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 9 0 +9
Total 28 680 175 +505

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The repair addresses checkpoint-related update refusal with limited scope; the reported Gateway remained ready.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 (1 earlier review cycle)
  • reviewed 2026-11-02T17:42:59.658Z sha f28de73 :: needs changes before merge. :: [P2] Include the production repair before landing the failing regression

Reviewed November 2, 2026, 10:17 PM ET / November 3, 2026, 03:17 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Nov 3, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review ccd99233779a1f1e74761589ccb21754a317d3f9. The production repair is complete. The diagnostic Bun finalizer failure was a missing manifest-selected spawn broker in compiled fixtures; the fixture correction now passes both previously failing cases and all 62 tests in that shard. Build Artifacts passed. Current CI remains in progress, with the two previously attributed inherited max-lines failures still reported.

Affected-path proof: https://github.com/openclaw/openclaw/actions/runs/41569389525/job/125699325714

@clawsweeper

clawsweeper Bot commented Nov 3, 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. labels Nov 3, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review 844995f0c84c6a327fcb7ee54dd243566decd3a9. This advances the requested head by one mechanical test-line correction (sort() to toSorted()) after the full lint log identified the actual error. The catalog/registry line-limit annotations are warnings, not a basis for a CI exception.

Production is unchanged. On the preceding head, all 15 recovery-admission tests passed on both Node and Bun, including the original live checkpoint-writer regression: https://github.com/openclaw/openclaw/actions/runs/41569389525/job/125699325737. The repaired compiled Bun finalizer shard passed all 62 tests: https://github.com/openclaw/openclaw/actions/runs/41569389525/job/125699325714. Build Artifacts and Darwin passed. Current-head CI is pending; no previous run is relabeled as current-head success.

@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed 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. 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 3, 2026
@vincentkoc
vincentkoc enabled auto-merge (squash) November 3, 2026 03:25
@vincentkoc
vincentkoc merged commit 1a74a80 into main Nov 3, 2026
175 checks passed
@vincentkoc
vincentkoc deleted the fix/live-recovery-admission-20261103 branch November 3, 2026 03:39
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…w#191332)

* test(update): reproduce recovery admission with a live writer

* fix(update): read live admission metadata through its owner

* fix(update): preserve metadata worker preparation boundaries

* test(update): expose cohort worker shutdown failures

* test(update): include nested spawn broker in compiled fixtures

* test(state): use non-mutating sort in metadata identity assertion
steipete added a commit that referenced this pull request Nov 5, 2026
Let the reconciliation owner skip read transactions for empty selections while retaining the existing composite snapshot for nonempty runs and already-pinned callers. The synthetic boot/restart workload removes eight statements with unchanged warm turns. Related: #190918, #191332.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
Let the reconciliation owner skip read transactions for empty selections while retaining the existing composite snapshot for nonempty runs and already-pinned callers. The synthetic boot/restart workload removes eight statements with unchanged warm turns. Related: openclaw#190918, openclaw#191332.
obviyus added a commit that referenced this pull request Nov 24, 2026
…es (#204502)

Closes #204363

## What Problem This Solves

A PostgreSQL update can migrate its data and then crash. Restoring the previous package alone leaves that package unable to read the newer schema, so no Gateway serves.

## User Impact

Protected release trials migrate private server-side copies and publish their anchors only after validation. Failed trials select the original data with the previous release. SQLite agent databases under PostgreSQL shared state are protected in the same private pass.

The restart is longer. Plan for both server copies, indexes, WAL, temporary work and retained generations. Namespace names change on schema-changing updates; namespace-bound reporting, dump and grant-management scripts must use the current anchor. Source access grants and schema-local defaults are carried and verified, including grant options and column permissions.

## Why This Change Was Made

This extends the existing startup copy-and-swap owner, exact server carrier and durable file plan. It removes the PostgreSQL-anchor version-zero exclusion and its mixed-engine skip. It adds no application schema/version change, trial format, launcher SQL, public flag, timeout or retry loop. There is no portable-export or unprotected in-place fallback for protected stores.

The first verified server copy is the migration destination, not a frozen capture followed by a second restore. A separate frozen-export manifest would misdescribe a namespace that is about to migrate, so retention uses the existing preserved anchors, store UUID and exact role ownership. Normal frozen captures retain their isolation.

Shared state uses that server carrier too. The older backup owner withheld it because credential rollback needed exported shared-state rows; c2 instead retains those rows in the untouched original namespace, selected by the preserved anchor. That removes the need for a portable shared-state export in the protected trial without removing ordinary captures for uncovered stores.

<details>
<summary>Compatibility and inventory source notes</summary>

The physical PostgreSQL version is read in [`state-upgrade-databases.ts:83–92`](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/state-upgrade-databases.ts#L83-L92). Its [independent family-version filter](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/state-upgrade-databases.ts#L152-L153) replaces the old shared-state version-zero early return, so SQLite agents are not skipped when state uses PostgreSQL. Genuine fresh SQLite version-zero catalogs remain bootstrap-owned.

`v2026.8.1-beta.1` and `beta.2` wrote absolute registry paths. Schema 9 in [#124728](#124728) rewrites eligible in-tree rows to relative paths ([migration lines 269–278](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/openclaw-state-db-schema-repair.ts#L269-L278)); `beta.3` and stable include it, and PostgreSQL starts at schema 24. No new reader rebase or row rewriting is needed.

</details>

## Result Wording

- Preparation runs while the previous Gateway serves; a missing CREATE grant names the exact administrator SQL before stopping it.
- Candidate boot logs: “Preparing a protected PostgreSQL copy for OpenClaw … The previous data will stay available for recovery.”
- A healthy candidate keeps the normal update-success message.
- A recovered failed trial keeps the shared serving-version result and retry/report next action. Current versions also show the already-recorded exit-78 startup cause detail, including the server-space remedy.
- Namespace cleanup failure keeps the recovery pair and logs a warning; it never fails a serving release.
- Larger stores keep the existing in-place migration path, with this recorded notice: “This PostgreSQL store (X GiB) is too large to copy within the update window. It is migrated in place, without automatic data rollback. Back it up first: https://docs.openclaw.ai/install/updating#rollback”.

## Evidence

**Product qualification and final-head CI are complete: 89 checks passed, none failed or pending.** Actual [rollback and pre-stop privilege-refusal screenshots](#204502 (comment)) and [corrected space-remedy and successful in-place screenshots](#204502 (comment)) are attached. The corrected normal CLI update exits **0**; it supersedes the recorded pre-fix helper timeout. Every AWS lease was released with `--wait`, and task tunnels were stopped.

Final head: `5bbf3e6712d04546a8a8d639188976be606c7ef5`. [CI attempt 2](https://github.com/openclaw/openclaw/actions/runs/45379513209/attempts/2) and the [CI gate](https://github.com/openclaw/openclaw/actions/runs/45386761656) passed. One Doctor process-custody cleanup test failed on the first attempt; its [single authorized same-head retry](https://github.com/openclaw/openclaw/actions/runs/45379513209/job/138411642189) passed. No cleanup guard, assertion or product timeout was weakened.

- Complete AWS qualification archive builds and package checks passed: pristine reporter41 plus next42 and post-migration-crash42 fixtures from `ad7e628030`. [run_9f2fdf8a02d2aad39a29f67029739435](https://crabbox.openclaw.ai/portal/runs/run_9f2fdf8a02d2aad39a29f67029739435), exit 0. The large-mode fixture also built from `513b774d28` ([run_b92c7c5b1893ded6f4b4c02bbe3e8058](https://crabbox.openclaw.ai/portal/runs/run_b92c7c5b1893ded6f4b4c02bbe3e8058), exit 0). Schema 42 and the lowered large-mode threshold are disposable qualification overlays, not shipped schema or policy changes.

- PostgreSQL 16 focused owner run [run_0a734ee4124db7308ba39734795af613](https://crabbox.openclaw.ai/portal/runs/run_0a734ee4124db7308ba39734795af613): **7/7 pass** on `ad7e6280300163cf55c97987ca36229427a6e236`. Includes a non-superuser runtime owner, real reader and column-only roles, grant options, default grants for later tables, unchanged originals, both historical v39 layouts, mixed engines, frozen-launcher file recovery and owned namespace pruning.
- The new startup regression is red on base `0956e14e6814`: three intended assertion failures (PG-shared cases return current; configured-agent case falls back), not import/setup failures. [run_f03e6807f052b8bee5d12ce55a5a1bd9](https://crabbox.openclaw.ai/portal/runs/run_f03e6807f052b8bee5d12ce55a5a1bd9).
- Reader access is red on pre-ACL `997e3bd583`: actual PostgreSQL `42501 permission denied for schema` after source-owner checks, cloning and physical validation. [run_374698ce02d32a9c790a68028b747f1c](https://crabbox.openclaw.ai/portal/runs/run_374698ce02d32a9c790a68028b747f1c).
- The same deterministic 100-session/10,752-message/42 MiB prose recipe measured **22.030 s** for one direct state+agent copy (7.831 s state, 14.181 s agent), versus **44.9 s** for the earlier server capture+restore. This is prior-head primitive evidence at `4a2ac42861`; physical sizes were 109,199,360 B and 109,256,704 B, respectively. It excludes migration and Gateway readiness and is not a fleet-percentile claim.
- Implementation-head actual 1 GiB copy (`ad7e628030`): **91.312 s** summed API calls (state 6.295 s, agent 85.018 s); **94.903 s** enclosing interval includes receipt/bookkeeping. Fixture: 1,000 sessions, 114,688 messages, 448 MiB prose, 1,074,192,384 physical bytes. Actual in-clone ANALYZE was **8.923 ms / 924.153 ms**; COMMIT→statistics COMMIT **15 ms / 929 ms**, with no statement-cap hit. Same AWS c7a.8xlarge/32 CPUs/PG16.15 loopback environment. [run_ea0ba8f4997497d5471b2514409ac2c1](https://crabbox.openclaw.ai/portal/runs/run_ea0ba8f4997497d5471b2514409ac2c1). Copy interval alone uses 7.91% of the existing budget; migration and readiness are not included.
- Implementation-head static quality (`ad7e628030`): core and test typechecks, lint, format parity, line-cap, SQL-worker/dialect and import-cycle guards passed. That earlier `check:changed` run reported an unchanged UI dead export; the UI file and the main-only `plugin-npm-prepared-release-retained-producer.test.ts` ratchet finding were left unchanged. [run_a6eca5556aa261ea23377fa7ef465043](https://crabbox.openclaw.ai/portal/runs/run_a6eca5556aa261ea23377fa7ef465043). Final CI above is green.
- Additional AWS owner checks [run_5bfc8d62fbe03884f89f1e074d773274](https://crabbox.openclaw.ai/portal/runs/run_5bfc8d62fbe03884f89f1e074d773274), exit 0: real PostgreSQL mixed-engine migration/rollback/prune including a retained JSON configuration file (**3/3**), measured size-mode selection (**2/2**), core typecheck and database-worker ratchet (**166→166** live SQL calls). The earlier bounded update/report/Doctor/startup set passed **102 tests** before static checks found the explicit-return and duplicate-query issues now corrected; its obsolete static continuation was stopped.
- Corrected reporter/candidate full builds passed on `056e58a1f6` ([run_1600dd89588952b226d0c9a1c1464616](https://crabbox.openclaw.ai/portal/runs/run_1600dd89588952b226d0c9a1c1464616), including **83** report/startup-progress owner tests) and `816d247a8e` ([run_1806f6db08bd5a5b96115f85fc7371c0](https://crabbox.openclaw.ai/portal/runs/run_1806f6db08bd5a5b96115f85fc7371c0)).
- Real PG16 terminal-row regression: with the metadata guard removed, the live-custody test receives `undefined` instead of its terminal record; fixed code passes. [run_d6d5571a1f215a87f5595a2d208c00c7](https://crabbox.openclaw.ai/portal/runs/run_d6d5571a1f215a87f5595a2d208c00c7), exit 0. The test overlay SHA-256 `9e183ef1082b9919f31565434c84e98bd9f36efdae23ae3eebcf1029ada42a1e` matches the committed test.
- Historical BLOB corpus: `40910f1112` (before the trace change) and `f5b0f14e05` fail on the premature `Uint8Array` path; main `87f5739fbc` passes ([comparison run](https://crabbox.openclaw.ai/portal/runs/run_bd406b7313533d912b0cf2724017665e)). The corrected `eea155e5d7` full runtime build and corpus case pass, including **all original database `.pre-` hashes**: [run_036ade5c82663f841278cda6d372825b](https://crabbox.openclaw.ai/portal/runs/run_036ade5c82663f841278cda6d372825b), exit 0.

### Linux / PostgreSQL 16 live outcomes

Times are measured HTTP unavailability, with the sampled upper bound in parentheses—not total package-install time.

| Case / update run | Observed result | Unavailable seconds |
| --- | --- | --- |
| [Healthy `3216f87a`](https://crabbox.openclaw.ai/portal/runs/run_348b18b19173c81569cb78f95c97723b) | New namespace, schema 42, unchanged selected table counts; custom reader and default grants still work | 93.443 (93.945) |
| [Crash after private migration `8f78b578`](https://crabbox.openclaw.ai/portal/runs/run_a61b9c3d4becc39890a1efc1f29939c5) | Original namespace/schema 41 and old T serve; Control UI and rollback status reachable | 109.198 (109.700) |
| [Missing CREATE `06cfa933`](https://crabbox.openclaw.ai/portal/runs/run_a98b7abc71e6338fce59695e96e535c6) | Refuses before stop with exact grant; old boot ID unchanged | No unavailable samples |
| [Real space refusal `124b69ae`](https://crabbox.openclaw.ai/portal/runs/run_6c1b9afbbcdcf7e53cdcb9e3205c2fd3) | PG `53100` from a 64 MiB tablespace against a >100 MiB source; exit 78, schema-41 reporter serves; Settings and CLI name the space problem and remedy | 26.559 (27.063) |
| [During server copy](https://crabbox.openclaw.ai/portal/runs/run_e1068fb7d19e614c83fb4895f8118d84) | Backend transaction aborts after one interruption; retry succeeds | 102.281 (102.785) |
| [After private anchor, before live publication `c2462582`](https://crabbox.openclaw.ai/portal/runs/run_13461405a6ea35983c16ded96c9a2d79) | One interruption; retry succeeds | 105.403 (105.906) |
| [Corrected large-store CLI `26687f74`](https://crabbox.openclaw.ai/portal/runs/run_f6ff27e1f1f6dbf9ee1c96dfbd330585) | **Exit 0**, same namespace 41→42, real migration witness; notice in CLI, status and Settings | 20.602 (21.106) |

The corrected large-store run is [run_f6ff27e1f1f6dbf9ee1c96dfbd330585](https://crabbox.openclaw.ai/portal/runs/run_f6ff27e1f1f6dbf9ee1c96dfbd330585), exit 0. A qualification-only lowered threshold selects that branch on a small store; production policy is unchanged.

Cleanup was proved by **byte-identical replay of the existing durable plan**, not a claim that the earlier ad7 retry pruned successfully. Namespace inventory **32→30**: only failed state `restore_ea858c2cbd3241ee9273fb6fee420cdd` and agent `restore_b5af9a52198b4d87b57fcc3d8f755721` were dropped. Live `restore_a8c51d96f8d34ebd8fba8966297a85b3` / `restore_b3ce0081721947ef946c5abf222f6d21` and originals `pgcrash_state_4f1e55aebce84abd` / `pgcrash_agent_889dbaaff3c64c0d` stayed intact. No manual `DROP` or invented plan operations were used.

Cleanup observation: [run_d5c7866cee8a21eb5dd5e79f78ce1a64](https://crabbox.openclaw.ai/portal/runs/run_d5c7866cee8a21eb5dd5e79f78ce1a64).

Plugin maintenance still reports the existing engine-selection warning in these fixtures; core success is not relabelled or hidden. The recorded space cause retains a descriptor warning and generic triage wording alongside the visible free-space remedy.

## Large-store Decision and Named Limits

- **Final decision:** preparation reads the physical sizes of the namespaces that would be copied. At the measured simplification of **90 s/GiB**, an estimate of **at most 600 s** selects c2, leaving half of the existing 20-minute deadline for a retry. Above it, the existing in-place path remains available, without copy-only privilege requirements. Blocking updates would be worse than main for these users. This constant replaces a per-server rate estimate and should be revisited when actual larger-store rates are measured; there is no new user flag, configuration, timer or persisted field.
- A crash before a durable plan discards the private shadow and copies again on the second start. Both starts share that deadline; a large-store retry can expire safely and return to the old version. After publication, the next start sees the target version and reuses the selected namespace.
- **Post-COMMIT, at most ~10 s of planner statistics run before the private anchor is recorded. A crash there can leave one unreferenced namespace requiring manual cleanup.** The [COMMIT→statistics call](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/infra/database-engine/port.worker.ts#L707-L712) precedes the [private anchor write](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/snapshot/database-backup.operations.ts#L441-L456). The bound is the existing `postgres-planner-statistics.ts:16` statement timeout, not a new timer. No new marker was added.
- Deep, external and symlinked paths outside the installed launcher's recoverable inventory keep their ordinary Doctor captures but do not gain automatic data rollback here ([#204394](#204394)).
- A serving T that predates the generic exit-78 report projection still has its old first-hop message. Preparation-time permission refusal keeps its named reason; newer serving versions show recorded boot-refusal detail.
- An older preparer also does not persist the candidate's new informational size notice from a successful check. Candidate boot logs the in-place selection, but the large-store CLI/status notice proof starts an updated schema-41 reporter. This first-hop limitation does not change the older updater's baseline in-place behavior.
- Trial-only writes are discarded on rollback. A PostgreSQL outage is not repaired by restoring anchors; readiness, not a file-level rolled-back label, confirms recovery.
- Already-stranded installations without a preserved original namespace still require a compatible build or a verified matched backup. Never lower schema markers or drop uncertain namespaces to force startup.

## Final-head Scope and Test Budget

`ad7e628030..056e58a` adds physical-size selection and the existing persisted diagnostic notice for the large in-place branch. Below the threshold, the protected copy/migration path is unchanged. Live qualification found retained JSON configuration files reaching the PostgreSQL anchor reader during pruning; the final head filters that existing list once, covered by the real rollback/prune test. Actual disk-space refusal also exposed two diagnostic issues: the report preferred a truncated prefix over the full recorded stderr tail, and normal startup progress printed completion lines after a failed start. The final head uses the existing bounded tail and emits completion only for successful startup phases, leaving the refusal last; CLI finalization is unchanged. Other changes reuse the schema owner's typed content-version reader, make undefined preflight success explicit, compute retention once, correct the docs, and remove 136 redundant wiring-test lines. Mode selection, corrected cleanup and final cause visibility require their own final-source live proof; ad7 live runs do not prove those changes.

Final head `5bbf3e6712` has the `816d247a8e` package runtime plus the SQLite-only legacy-safe discovery correction proved by the BLOB corpus. Remaining changes are the verified test overlay, a test-local rename/import correction, allocation notes and documentation. No PostgreSQL runtime change is excluded from the final 816 package proof.

The CLI failure was a physical-read mismatch, not an uncompleted notice: a real PostgreSQL run was `finished/succeeded`, but `update.runs.get` read the SQLite anchor and returned `run:null`, so the existing follower timed out. The shortcut predates this PR (`1a74a80617cf`, #191332). The earlier PostgreSQL trial used Settings to start updates and `openclaw update status` to inspect them; it did not exercise foreground CLI following. The fix changes the reader owner, not polling, deadlines or the public protocol.

For historical BLOB registry paths, the existing preflight reader leaves non-string rows to Doctor. Both `main` and `ops` databases in the corpus are independently discovered at `agents/<id>/agent/openclaw-agent.sqlite`; the existing corpus test hashes **every** original database and checks its `.pre-` original (`test/state-upgrade.e2e.test.ts:189,247–248`). Non-default legacy BLOB registrations that fall outside that discovery remain a named #204394 limitation, not a new coercion or refusal.

Remaining test allocation (approved after those cuts):
- Real PostgreSQL ACL/non-superuser tests preserve reader access, ownership, grant options and historical layouts.
- Mixed-engine migration failure and crash recovery prove originals survive and only owned unreferenced namespaces are pruned.
- Copy-refusal tests prove preparation fails before stop with an actionable cause.
- Generic report projection and one nested startup-progress regression (tracing off/on) prove recorded boot-refusal remedies remain the final visible cause.
- One parameterized size-routing test proves under/over selection, the notice and retained SQLite protection.
- One real PostgreSQL terminal-read regression exercises the physical command path used by the CLI follower, rather than the SQLite anchor.

Production delta against the base: **+1192/−234, net +958 lines across 27 files**. The growth covers physical-engine inventory/validation, transactional access-right preservation, paired namespace retention, measured mode selection and refusal-output ordering. Existing duplicate private PostgreSQL capture work is removed; standalone and uncovered-store captures remain.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 25, 2026
…es (#204502)

Closes #204363

## What Problem This Solves

A PostgreSQL update can migrate its data and then crash. Restoring the previous package alone leaves that package unable to read the newer schema, so no Gateway serves.

## User Impact

Protected release trials migrate private server-side copies and publish their anchors only after validation. Failed trials select the original data with the previous release. SQLite agent databases under PostgreSQL shared state are protected in the same private pass.

The restart is longer. Plan for both server copies, indexes, WAL, temporary work and retained generations. Namespace names change on schema-changing updates; namespace-bound reporting, dump and grant-management scripts must use the current anchor. Source access grants and schema-local defaults are carried and verified, including grant options and column permissions.

## Why This Change Was Made

This extends the existing startup copy-and-swap owner, exact server carrier and durable file plan. It removes the PostgreSQL-anchor version-zero exclusion and its mixed-engine skip. It adds no application schema/version change, trial format, launcher SQL, public flag, timeout or retry loop. There is no portable-export or unprotected in-place fallback for protected stores.

The first verified server copy is the migration destination, not a frozen capture followed by a second restore. A separate frozen-export manifest would misdescribe a namespace that is about to migrate, so retention uses the existing preserved anchors, store UUID and exact role ownership. Normal frozen captures retain their isolation.

Shared state uses that server carrier too. The older backup owner withheld it because credential rollback needed exported shared-state rows; c2 instead retains those rows in the untouched original namespace, selected by the preserved anchor. That removes the need for a portable shared-state export in the protected trial without removing ordinary captures for uncovered stores.

<details>
<summary>Compatibility and inventory source notes</summary>

The physical PostgreSQL version is read in [`state-upgrade-databases.ts:83–92`](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/state-upgrade-databases.ts#L83-L92). Its [independent family-version filter](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/state-upgrade-databases.ts#L152-L153) replaces the old shared-state version-zero early return, so SQLite agents are not skipped when state uses PostgreSQL. Genuine fresh SQLite version-zero catalogs remain bootstrap-owned.

`v2026.8.1-beta.1` and `beta.2` wrote absolute registry paths. Schema 9 in [#124728](#124728) rewrites eligible in-tree rows to relative paths ([migration lines 269–278](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/openclaw-state-db-schema-repair.ts#L269-L278)); `beta.3` and stable include it, and PostgreSQL starts at schema 24. No new reader rebase or row rewriting is needed.

</details>

## Result Wording

- Preparation runs while the previous Gateway serves; a missing CREATE grant names the exact administrator SQL before stopping it.
- Candidate boot logs: “Preparing a protected PostgreSQL copy for OpenClaw … The previous data will stay available for recovery.”
- A healthy candidate keeps the normal update-success message.
- A recovered failed trial keeps the shared serving-version result and retry/report next action. Current versions also show the already-recorded exit-78 startup cause detail, including the server-space remedy.
- Namespace cleanup failure keeps the recovery pair and logs a warning; it never fails a serving release.
- Larger stores keep the existing in-place migration path, with this recorded notice: “This PostgreSQL store (X GiB) is too large to copy within the update window. It is migrated in place, without automatic data rollback. Back it up first: https://docs.openclaw.ai/install/updating#rollback”.

## Evidence

**Product qualification and final-head CI are complete: 89 checks passed, none failed or pending.** Actual [rollback and pre-stop privilege-refusal screenshots](#204502 (comment)) and [corrected space-remedy and successful in-place screenshots](#204502 (comment)) are attached. The corrected normal CLI update exits **0**; it supersedes the recorded pre-fix helper timeout. Every AWS lease was released with `--wait`, and task tunnels were stopped.

Final head: `5bbf3e6712d04546a8a8d639188976be606c7ef5`. [CI attempt 2](https://github.com/openclaw/openclaw/actions/runs/45379513209/attempts/2) and the [CI gate](https://github.com/openclaw/openclaw/actions/runs/45386761656) passed. One Doctor process-custody cleanup test failed on the first attempt; its [single authorized same-head retry](https://github.com/openclaw/openclaw/actions/runs/45379513209/job/138411642189) passed. No cleanup guard, assertion or product timeout was weakened.

- Complete AWS qualification archive builds and package checks passed: pristine reporter41 plus next42 and post-migration-crash42 fixtures from `ad7e628030`. [run_9f2fdf8a02d2aad39a29f67029739435](https://crabbox.openclaw.ai/portal/runs/run_9f2fdf8a02d2aad39a29f67029739435), exit 0. The large-mode fixture also built from `513b774d28` ([run_b92c7c5b1893ded6f4b4c02bbe3e8058](https://crabbox.openclaw.ai/portal/runs/run_b92c7c5b1893ded6f4b4c02bbe3e8058), exit 0). Schema 42 and the lowered large-mode threshold are disposable qualification overlays, not shipped schema or policy changes.

- PostgreSQL 16 focused owner run [run_0a734ee4124db7308ba39734795af613](https://crabbox.openclaw.ai/portal/runs/run_0a734ee4124db7308ba39734795af613): **7/7 pass** on `ad7e6280300163cf55c97987ca36229427a6e236`. Includes a non-superuser runtime owner, real reader and column-only roles, grant options, default grants for later tables, unchanged originals, both historical v39 layouts, mixed engines, frozen-launcher file recovery and owned namespace pruning.
- The new startup regression is red on base `0956e14e6814`: three intended assertion failures (PG-shared cases return current; configured-agent case falls back), not import/setup failures. [run_f03e6807f052b8bee5d12ce55a5a1bd9](https://crabbox.openclaw.ai/portal/runs/run_f03e6807f052b8bee5d12ce55a5a1bd9).
- Reader access is red on pre-ACL `997e3bd583`: actual PostgreSQL `42501 permission denied for schema` after source-owner checks, cloning and physical validation. [run_374698ce02d32a9c790a68028b747f1c](https://crabbox.openclaw.ai/portal/runs/run_374698ce02d32a9c790a68028b747f1c).
- The same deterministic 100-session/10,752-message/42 MiB prose recipe measured **22.030 s** for one direct state+agent copy (7.831 s state, 14.181 s agent), versus **44.9 s** for the earlier server capture+restore. This is prior-head primitive evidence at `4a2ac42861`; physical sizes were 109,199,360 B and 109,256,704 B, respectively. It excludes migration and Gateway readiness and is not a fleet-percentile claim.
- Implementation-head actual 1 GiB copy (`ad7e628030`): **91.312 s** summed API calls (state 6.295 s, agent 85.018 s); **94.903 s** enclosing interval includes receipt/bookkeeping. Fixture: 1,000 sessions, 114,688 messages, 448 MiB prose, 1,074,192,384 physical bytes. Actual in-clone ANALYZE was **8.923 ms / 924.153 ms**; COMMIT→statistics COMMIT **15 ms / 929 ms**, with no statement-cap hit. Same AWS c7a.8xlarge/32 CPUs/PG16.15 loopback environment. [run_ea0ba8f4997497d5471b2514409ac2c1](https://crabbox.openclaw.ai/portal/runs/run_ea0ba8f4997497d5471b2514409ac2c1). Copy interval alone uses 7.91% of the existing budget; migration and readiness are not included.
- Implementation-head static quality (`ad7e628030`): core and test typechecks, lint, format parity, line-cap, SQL-worker/dialect and import-cycle guards passed. That earlier `check:changed` run reported an unchanged UI dead export; the UI file and the main-only `plugin-npm-prepared-release-retained-producer.test.ts` ratchet finding were left unchanged. [run_a6eca5556aa261ea23377fa7ef465043](https://crabbox.openclaw.ai/portal/runs/run_a6eca5556aa261ea23377fa7ef465043). Final CI above is green.
- Additional AWS owner checks [run_5bfc8d62fbe03884f89f1e074d773274](https://crabbox.openclaw.ai/portal/runs/run_5bfc8d62fbe03884f89f1e074d773274), exit 0: real PostgreSQL mixed-engine migration/rollback/prune including a retained JSON configuration file (**3/3**), measured size-mode selection (**2/2**), core typecheck and database-worker ratchet (**166→166** live SQL calls). The earlier bounded update/report/Doctor/startup set passed **102 tests** before static checks found the explicit-return and duplicate-query issues now corrected; its obsolete static continuation was stopped.
- Corrected reporter/candidate full builds passed on `056e58a1f6` ([run_1600dd89588952b226d0c9a1c1464616](https://crabbox.openclaw.ai/portal/runs/run_1600dd89588952b226d0c9a1c1464616), including **83** report/startup-progress owner tests) and `816d247a8e` ([run_1806f6db08bd5a5b96115f85fc7371c0](https://crabbox.openclaw.ai/portal/runs/run_1806f6db08bd5a5b96115f85fc7371c0)).
- Real PG16 terminal-row regression: with the metadata guard removed, the live-custody test receives `undefined` instead of its terminal record; fixed code passes. [run_d6d5571a1f215a87f5595a2d208c00c7](https://crabbox.openclaw.ai/portal/runs/run_d6d5571a1f215a87f5595a2d208c00c7), exit 0. The test overlay SHA-256 `9e183ef1082b9919f31565434c84e98bd9f36efdae23ae3eebcf1029ada42a1e` matches the committed test.
- Historical BLOB corpus: `40910f1112` (before the trace change) and `f5b0f14e05` fail on the premature `Uint8Array` path; main `87f5739fbc` passes ([comparison run](https://crabbox.openclaw.ai/portal/runs/run_bd406b7313533d912b0cf2724017665e)). The corrected `eea155e5d7` full runtime build and corpus case pass, including **all original database `.pre-` hashes**: [run_036ade5c82663f841278cda6d372825b](https://crabbox.openclaw.ai/portal/runs/run_036ade5c82663f841278cda6d372825b), exit 0.

### Linux / PostgreSQL 16 live outcomes

Times are measured HTTP unavailability, with the sampled upper bound in parentheses—not total package-install time.

| Case / update run | Observed result | Unavailable seconds |
| --- | --- | --- |
| [Healthy `3216f87a`](https://crabbox.openclaw.ai/portal/runs/run_348b18b19173c81569cb78f95c97723b) | New namespace, schema 42, unchanged selected table counts; custom reader and default grants still work | 93.443 (93.945) |
| [Crash after private migration `8f78b578`](https://crabbox.openclaw.ai/portal/runs/run_a61b9c3d4becc39890a1efc1f29939c5) | Original namespace/schema 41 and old T serve; Control UI and rollback status reachable | 109.198 (109.700) |
| [Missing CREATE `06cfa933`](https://crabbox.openclaw.ai/portal/runs/run_a98b7abc71e6338fce59695e96e535c6) | Refuses before stop with exact grant; old boot ID unchanged | No unavailable samples |
| [Real space refusal `124b69ae`](https://crabbox.openclaw.ai/portal/runs/run_6c1b9afbbcdcf7e53cdcb9e3205c2fd3) | PG `53100` from a 64 MiB tablespace against a >100 MiB source; exit 78, schema-41 reporter serves; Settings and CLI name the space problem and remedy | 26.559 (27.063) |
| [During server copy](https://crabbox.openclaw.ai/portal/runs/run_e1068fb7d19e614c83fb4895f8118d84) | Backend transaction aborts after one interruption; retry succeeds | 102.281 (102.785) |
| [After private anchor, before live publication `c2462582`](https://crabbox.openclaw.ai/portal/runs/run_13461405a6ea35983c16ded96c9a2d79) | One interruption; retry succeeds | 105.403 (105.906) |
| [Corrected large-store CLI `26687f74`](https://crabbox.openclaw.ai/portal/runs/run_f6ff27e1f1f6dbf9ee1c96dfbd330585) | **Exit 0**, same namespace 41→42, real migration witness; notice in CLI, status and Settings | 20.602 (21.106) |

The corrected large-store run is [run_f6ff27e1f1f6dbf9ee1c96dfbd330585](https://crabbox.openclaw.ai/portal/runs/run_f6ff27e1f1f6dbf9ee1c96dfbd330585), exit 0. A qualification-only lowered threshold selects that branch on a small store; production policy is unchanged.

Cleanup was proved by **byte-identical replay of the existing durable plan**, not a claim that the earlier ad7 retry pruned successfully. Namespace inventory **32→30**: only failed state `restore_ea858c2cbd3241ee9273fb6fee420cdd` and agent `restore_b5af9a52198b4d87b57fcc3d8f755721` were dropped. Live `restore_a8c51d96f8d34ebd8fba8966297a85b3` / `restore_b3ce0081721947ef946c5abf222f6d21` and originals `pgcrash_state_4f1e55aebce84abd` / `pgcrash_agent_889dbaaff3c64c0d` stayed intact. No manual `DROP` or invented plan operations were used.

Cleanup observation: [run_d5c7866cee8a21eb5dd5e79f78ce1a64](https://crabbox.openclaw.ai/portal/runs/run_d5c7866cee8a21eb5dd5e79f78ce1a64).

Plugin maintenance still reports the existing engine-selection warning in these fixtures; core success is not relabelled or hidden. The recorded space cause retains a descriptor warning and generic triage wording alongside the visible free-space remedy.

## Large-store Decision and Named Limits

- **Final decision:** preparation reads the physical sizes of the namespaces that would be copied. At the measured simplification of **90 s/GiB**, an estimate of **at most 600 s** selects c2, leaving half of the existing 20-minute deadline for a retry. Above it, the existing in-place path remains available, without copy-only privilege requirements. Blocking updates would be worse than main for these users. This constant replaces a per-server rate estimate and should be revisited when actual larger-store rates are measured; there is no new user flag, configuration, timer or persisted field.
- A crash before a durable plan discards the private shadow and copies again on the second start. Both starts share that deadline; a large-store retry can expire safely and return to the old version. After publication, the next start sees the target version and reuses the selected namespace.
- **Post-COMMIT, at most ~10 s of planner statistics run before the private anchor is recorded. A crash there can leave one unreferenced namespace requiring manual cleanup.** The [COMMIT→statistics call](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/infra/database-engine/port.worker.ts#L707-L712) precedes the [private anchor write](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/snapshot/database-backup.operations.ts#L441-L456). The bound is the existing `postgres-planner-statistics.ts:16` statement timeout, not a new timer. No new marker was added.
- Deep, external and symlinked paths outside the installed launcher's recoverable inventory keep their ordinary Doctor captures but do not gain automatic data rollback here ([#204394](#204394)).
- A serving T that predates the generic exit-78 report projection still has its old first-hop message. Preparation-time permission refusal keeps its named reason; newer serving versions show recorded boot-refusal detail.
- An older preparer also does not persist the candidate's new informational size notice from a successful check. Candidate boot logs the in-place selection, but the large-store CLI/status notice proof starts an updated schema-41 reporter. This first-hop limitation does not change the older updater's baseline in-place behavior.
- Trial-only writes are discarded on rollback. A PostgreSQL outage is not repaired by restoring anchors; readiness, not a file-level rolled-back label, confirms recovery.
- Already-stranded installations without a preserved original namespace still require a compatible build or a verified matched backup. Never lower schema markers or drop uncertain namespaces to force startup.

## Final-head Scope and Test Budget

`ad7e628030..056e58a` adds physical-size selection and the existing persisted diagnostic notice for the large in-place branch. Below the threshold, the protected copy/migration path is unchanged. Live qualification found retained JSON configuration files reaching the PostgreSQL anchor reader during pruning; the final head filters that existing list once, covered by the real rollback/prune test. Actual disk-space refusal also exposed two diagnostic issues: the report preferred a truncated prefix over the full recorded stderr tail, and normal startup progress printed completion lines after a failed start. The final head uses the existing bounded tail and emits completion only for successful startup phases, leaving the refusal last; CLI finalization is unchanged. Other changes reuse the schema owner's typed content-version reader, make undefined preflight success explicit, compute retention once, correct the docs, and remove 136 redundant wiring-test lines. Mode selection, corrected cleanup and final cause visibility require their own final-source live proof; ad7 live runs do not prove those changes.

Final head `5bbf3e6712` has the `816d247a8e` package runtime plus the SQLite-only legacy-safe discovery correction proved by the BLOB corpus. Remaining changes are the verified test overlay, a test-local rename/import correction, allocation notes and documentation. No PostgreSQL runtime change is excluded from the final 816 package proof.

The CLI failure was a physical-read mismatch, not an uncompleted notice: a real PostgreSQL run was `finished/succeeded`, but `update.runs.get` read the SQLite anchor and returned `run:null`, so the existing follower timed out. The shortcut predates this PR (`1a74a80617cf`, #191332). The earlier PostgreSQL trial used Settings to start updates and `openclaw update status` to inspect them; it did not exercise foreground CLI following. The fix changes the reader owner, not polling, deadlines or the public protocol.

For historical BLOB registry paths, the existing preflight reader leaves non-string rows to Doctor. Both `main` and `ops` databases in the corpus are independently discovered at `agents/<id>/agent/openclaw-agent.sqlite`; the existing corpus test hashes **every** original database and checks its `.pre-` original (`test/state-upgrade.e2e.test.ts:189,247–248`). Non-default legacy BLOB registrations that fall outside that discovery remain a named #204394 limitation, not a new coercion or refusal.

Remaining test allocation (approved after those cuts):
- Real PostgreSQL ACL/non-superuser tests preserve reader access, ownership, grant options and historical layouts.
- Mixed-engine migration failure and crash recovery prove originals survive and only owned unreferenced namespaces are pruned.
- Copy-refusal tests prove preparation fails before stop with an actionable cause.
- Generic report projection and one nested startup-progress regression (tracing off/on) prove recorded boot-refusal remedies remain the final visible cause.
- One parameterized size-routing test proves under/over selection, the notice and retained SQLite protection.
- One real PostgreSQL terminal-read regression exercises the physical command path used by the CLI follower, rather than the SQLite anchor.

Production delta against the base: **+1192/−234, net +958 lines across 27 files**. The growth covers physical-engine inventory/validation, transactional access-right preservation, paired namespace retention, measured mode selection and refusal-output ordering. Existing duplicate private PostgreSQL capture work is removed; standalone and uncovered-store captures remain.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit c7b132a)
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…es (openclaw#204502)

Closes openclaw#204363

## What Problem This Solves

A PostgreSQL update can migrate its data and then crash. Restoring the previous package alone leaves that package unable to read the newer schema, so no Gateway serves.

## User Impact

Protected release trials migrate private server-side copies and publish their anchors only after validation. Failed trials select the original data with the previous release. SQLite agent databases under PostgreSQL shared state are protected in the same private pass.

The restart is longer. Plan for both server copies, indexes, WAL, temporary work and retained generations. Namespace names change on schema-changing updates; namespace-bound reporting, dump and grant-management scripts must use the current anchor. Source access grants and schema-local defaults are carried and verified, including grant options and column permissions.

## Why This Change Was Made

This extends the existing startup copy-and-swap owner, exact server carrier and durable file plan. It removes the PostgreSQL-anchor version-zero exclusion and its mixed-engine skip. It adds no application schema/version change, trial format, launcher SQL, public flag, timeout or retry loop. There is no portable-export or unprotected in-place fallback for protected stores.

The first verified server copy is the migration destination, not a frozen capture followed by a second restore. A separate frozen-export manifest would misdescribe a namespace that is about to migrate, so retention uses the existing preserved anchors, store UUID and exact role ownership. Normal frozen captures retain their isolation.

Shared state uses that server carrier too. The older backup owner withheld it because credential rollback needed exported shared-state rows; c2 instead retains those rows in the untouched original namespace, selected by the preserved anchor. That removes the need for a portable shared-state export in the protected trial without removing ordinary captures for uncovered stores.

<details>
<summary>Compatibility and inventory source notes</summary>

The physical PostgreSQL version is read in [`state-upgrade-databases.ts:83–92`](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/state-upgrade-databases.ts#L83-L92). Its [independent family-version filter](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/state-upgrade-databases.ts#L152-L153) replaces the old shared-state version-zero early return, so SQLite agents are not skipped when state uses PostgreSQL. Genuine fresh SQLite version-zero catalogs remain bootstrap-owned.

`v2026.8.1-beta.1` and `beta.2` wrote absolute registry paths. Schema 9 in [openclaw#124728](openclaw#124728) rewrites eligible in-tree rows to relative paths ([migration lines 269–278](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/state/openclaw-state-db-schema-repair.ts#L269-L278)); `beta.3` and stable include it, and PostgreSQL starts at schema 24. No new reader rebase or row rewriting is needed.

</details>

## Result Wording

- Preparation runs while the previous Gateway serves; a missing CREATE grant names the exact administrator SQL before stopping it.
- Candidate boot logs: “Preparing a protected PostgreSQL copy for OpenClaw … The previous data will stay available for recovery.”
- A healthy candidate keeps the normal update-success message.
- A recovered failed trial keeps the shared serving-version result and retry/report next action. Current versions also show the already-recorded exit-78 startup cause detail, including the server-space remedy.
- Namespace cleanup failure keeps the recovery pair and logs a warning; it never fails a serving release.
- Larger stores keep the existing in-place migration path, with this recorded notice: “This PostgreSQL store (X GiB) is too large to copy within the update window. It is migrated in place, without automatic data rollback. Back it up first: https://docs.openclaw.ai/install/updating#rollback”.

## Evidence

**Product qualification and final-head CI are complete: 89 checks passed, none failed or pending.** Actual [rollback and pre-stop privilege-refusal screenshots](openclaw#204502 (comment)) and [corrected space-remedy and successful in-place screenshots](openclaw#204502 (comment)) are attached. The corrected normal CLI update exits **0**; it supersedes the recorded pre-fix helper timeout. Every AWS lease was released with `--wait`, and task tunnels were stopped.

Final head: `5bbf3e6712d04546a8a8d639188976be606c7ef5`. [CI attempt 2](https://github.com/openclaw/openclaw/actions/runs/45379513209/attempts/2) and the [CI gate](https://github.com/openclaw/openclaw/actions/runs/45386761656) passed. One Doctor process-custody cleanup test failed on the first attempt; its [single authorized same-head retry](https://github.com/openclaw/openclaw/actions/runs/45379513209/job/138411642189) passed. No cleanup guard, assertion or product timeout was weakened.

- Complete AWS qualification archive builds and package checks passed: pristine reporter41 plus next42 and post-migration-crash42 fixtures from `ad7e628030`. [run_9f2fdf8a02d2aad39a29f67029739435](https://crabbox.openclaw.ai/portal/runs/run_9f2fdf8a02d2aad39a29f67029739435), exit 0. The large-mode fixture also built from `513b774d28` ([run_b92c7c5b1893ded6f4b4c02bbe3e8058](https://crabbox.openclaw.ai/portal/runs/run_b92c7c5b1893ded6f4b4c02bbe3e8058), exit 0). Schema 42 and the lowered large-mode threshold are disposable qualification overlays, not shipped schema or policy changes.

- PostgreSQL 16 focused owner run [run_0a734ee4124db7308ba39734795af613](https://crabbox.openclaw.ai/portal/runs/run_0a734ee4124db7308ba39734795af613): **7/7 pass** on `ad7e6280300163cf55c97987ca36229427a6e236`. Includes a non-superuser runtime owner, real reader and column-only roles, grant options, default grants for later tables, unchanged originals, both historical v39 layouts, mixed engines, frozen-launcher file recovery and owned namespace pruning.
- The new startup regression is red on base `5c569ef59a78`: three intended assertion failures (PG-shared cases return current; configured-agent case falls back), not import/setup failures. [run_f03e6807f052b8bee5d12ce55a5a1bd9](https://crabbox.openclaw.ai/portal/runs/run_f03e6807f052b8bee5d12ce55a5a1bd9).
- Reader access is red on pre-ACL `997e3bd583`: actual PostgreSQL `42501 permission denied for schema` after source-owner checks, cloning and physical validation. [run_374698ce02d32a9c790a68028b747f1c](https://crabbox.openclaw.ai/portal/runs/run_374698ce02d32a9c790a68028b747f1c).
- The same deterministic 100-session/10,752-message/42 MiB prose recipe measured **22.030 s** for one direct state+agent copy (7.831 s state, 14.181 s agent), versus **44.9 s** for the earlier server capture+restore. This is prior-head primitive evidence at `4a2ac42861`; physical sizes were 109,199,360 B and 109,256,704 B, respectively. It excludes migration and Gateway readiness and is not a fleet-percentile claim.
- Implementation-head actual 1 GiB copy (`ad7e628030`): **91.312 s** summed API calls (state 6.295 s, agent 85.018 s); **94.903 s** enclosing interval includes receipt/bookkeeping. Fixture: 1,000 sessions, 114,688 messages, 448 MiB prose, 1,074,192,384 physical bytes. Actual in-clone ANALYZE was **8.923 ms / 924.153 ms**; COMMIT→statistics COMMIT **15 ms / 929 ms**, with no statement-cap hit. Same AWS c7a.8xlarge/32 CPUs/PG16.15 loopback environment. [run_ea0ba8f4997497d5471b2514409ac2c1](https://crabbox.openclaw.ai/portal/runs/run_ea0ba8f4997497d5471b2514409ac2c1). Copy interval alone uses 7.91% of the existing budget; migration and readiness are not included.
- Implementation-head static quality (`ad7e628030`): core and test typechecks, lint, format parity, line-cap, SQL-worker/dialect and import-cycle guards passed. That earlier `check:changed` run reported an unchanged UI dead export; the UI file and the main-only `plugin-npm-prepared-release-retained-producer.test.ts` ratchet finding were left unchanged. [run_a6eca5556aa261ea23377fa7ef465043](https://crabbox.openclaw.ai/portal/runs/run_a6eca5556aa261ea23377fa7ef465043). Final CI above is green.
- Additional AWS owner checks [run_5bfc8d62fbe03884f89f1e074d773274](https://crabbox.openclaw.ai/portal/runs/run_5bfc8d62fbe03884f89f1e074d773274), exit 0: real PostgreSQL mixed-engine migration/rollback/prune including a retained JSON configuration file (**3/3**), measured size-mode selection (**2/2**), core typecheck and database-worker ratchet (**166→166** live SQL calls). The earlier bounded update/report/Doctor/startup set passed **102 tests** before static checks found the explicit-return and duplicate-query issues now corrected; its obsolete static continuation was stopped.
- Corrected reporter/candidate full builds passed on `056e58a1f6` ([run_1600dd89588952b226d0c9a1c1464616](https://crabbox.openclaw.ai/portal/runs/run_1600dd89588952b226d0c9a1c1464616), including **83** report/startup-progress owner tests) and `816d247a8e` ([run_1806f6db08bd5a5b96115f85fc7371c0](https://crabbox.openclaw.ai/portal/runs/run_1806f6db08bd5a5b96115f85fc7371c0)).
- Real PG16 terminal-row regression: with the metadata guard removed, the live-custody test receives `undefined` instead of its terminal record; fixed code passes. [run_d6d5571a1f215a87f5595a2d208c00c7](https://crabbox.openclaw.ai/portal/runs/run_d6d5571a1f215a87f5595a2d208c00c7), exit 0. The test overlay SHA-256 `9e183ef1082b9919f31565434c84e98bd9f36efdae23ae3eebcf1029ada42a1e` matches the committed test.
- Historical BLOB corpus: `40910f1112` (before the trace change) and `f5b0f14e05` fail on the premature `Uint8Array` path; main `47b6dfba22` passes ([comparison run](https://crabbox.openclaw.ai/portal/runs/run_bd406b7313533d912b0cf2724017665e)). The corrected `eea155e5d7` full runtime build and corpus case pass, including **all original database `.pre-` hashes**: [run_036ade5c82663f841278cda6d372825b](https://crabbox.openclaw.ai/portal/runs/run_036ade5c82663f841278cda6d372825b), exit 0.

### Linux / PostgreSQL 16 live outcomes

Times are measured HTTP unavailability, with the sampled upper bound in parentheses—not total package-install time.

| Case / update run | Observed result | Unavailable seconds |
| --- | --- | --- |
| [Healthy `3216f87a`](https://crabbox.openclaw.ai/portal/runs/run_348b18b19173c81569cb78f95c97723b) | New namespace, schema 42, unchanged selected table counts; custom reader and default grants still work | 93.443 (93.945) |
| [Crash after private migration `8f78b578`](https://crabbox.openclaw.ai/portal/runs/run_a61b9c3d4becc39890a1efc1f29939c5) | Original namespace/schema 41 and old T serve; Control UI and rollback status reachable | 109.198 (109.700) |
| [Missing CREATE `06cfa933`](https://crabbox.openclaw.ai/portal/runs/run_a98b7abc71e6338fce59695e96e535c6) | Refuses before stop with exact grant; old boot ID unchanged | No unavailable samples |
| [Real space refusal `124b69ae`](https://crabbox.openclaw.ai/portal/runs/run_6c1b9afbbcdcf7e53cdcb9e3205c2fd3) | PG `53100` from a 64 MiB tablespace against a >100 MiB source; exit 78, schema-41 reporter serves; Settings and CLI name the space problem and remedy | 26.559 (27.063) |
| [During server copy](https://crabbox.openclaw.ai/portal/runs/run_e1068fb7d19e614c83fb4895f8118d84) | Backend transaction aborts after one interruption; retry succeeds | 102.281 (102.785) |
| [After private anchor, before live publication `c2462582`](https://crabbox.openclaw.ai/portal/runs/run_13461405a6ea35983c16ded96c9a2d79) | One interruption; retry succeeds | 105.403 (105.906) |
| [Corrected large-store CLI `26687f74`](https://crabbox.openclaw.ai/portal/runs/run_f6ff27e1f1f6dbf9ee1c96dfbd330585) | **Exit 0**, same namespace 41→42, real migration witness; notice in CLI, status and Settings | 20.602 (21.106) |

The corrected large-store run is [run_f6ff27e1f1f6dbf9ee1c96dfbd330585](https://crabbox.openclaw.ai/portal/runs/run_f6ff27e1f1f6dbf9ee1c96dfbd330585), exit 0. A qualification-only lowered threshold selects that branch on a small store; production policy is unchanged.

Cleanup was proved by **byte-identical replay of the existing durable plan**, not a claim that the earlier ad7 retry pruned successfully. Namespace inventory **32→30**: only failed state `restore_ea858c2cbd3241ee9273fb6fee420cdd` and agent `restore_b5af9a52198b4d87b57fcc3d8f755721` were dropped. Live `restore_a8c51d96f8d34ebd8fba8966297a85b3` / `restore_b3ce0081721947ef946c5abf222f6d21` and originals `pgcrash_state_4f1e55aebce84abd` / `pgcrash_agent_889dbaaff3c64c0d` stayed intact. No manual `DROP` or invented plan operations were used.

Cleanup observation: [run_d5c7866cee8a21eb5dd5e79f78ce1a64](https://crabbox.openclaw.ai/portal/runs/run_d5c7866cee8a21eb5dd5e79f78ce1a64).

Plugin maintenance still reports the existing engine-selection warning in these fixtures; core success is not relabelled or hidden. The recorded space cause retains a descriptor warning and generic triage wording alongside the visible free-space remedy.

## Large-store Decision and Named Limits

- **Final decision:** preparation reads the physical sizes of the namespaces that would be copied. At the measured simplification of **90 s/GiB**, an estimate of **at most 600 s** selects c2, leaving half of the existing 20-minute deadline for a retry. Above it, the existing in-place path remains available, without copy-only privilege requirements. Blocking updates would be worse than main for these users. This constant replaces a per-server rate estimate and should be revisited when actual larger-store rates are measured; there is no new user flag, configuration, timer or persisted field.
- A crash before a durable plan discards the private shadow and copies again on the second start. Both starts share that deadline; a large-store retry can expire safely and return to the old version. After publication, the next start sees the target version and reuses the selected namespace.
- **Post-COMMIT, at most ~10 s of planner statistics run before the private anchor is recorded. A crash there can leave one unreferenced namespace requiring manual cleanup.** The [COMMIT→statistics call](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/infra/database-engine/port.worker.ts#L707-L712) precedes the [private anchor write](https://github.com/openclaw/openclaw/blob/ad7e6280300163cf55c97987ca36229427a6e236/src/snapshot/database-backup.operations.ts#L441-L456). The bound is the existing `postgres-planner-statistics.ts:16` statement timeout, not a new timer. No new marker was added.
- Deep, external and symlinked paths outside the installed launcher's recoverable inventory keep their ordinary Doctor captures but do not gain automatic data rollback here ([openclaw#204394](openclaw#204394)).
- A serving T that predates the generic exit-78 report projection still has its old first-hop message. Preparation-time permission refusal keeps its named reason; newer serving versions show recorded boot-refusal detail.
- An older preparer also does not persist the candidate's new informational size notice from a successful check. Candidate boot logs the in-place selection, but the large-store CLI/status notice proof starts an updated schema-41 reporter. This first-hop limitation does not change the older updater's baseline in-place behavior.
- Trial-only writes are discarded on rollback. A PostgreSQL outage is not repaired by restoring anchors; readiness, not a file-level rolled-back label, confirms recovery.
- Already-stranded installations without a preserved original namespace still require a compatible build or a verified matched backup. Never lower schema markers or drop uncertain namespaces to force startup.

## Final-head Scope and Test Budget

`ad7e628030..056e58a` adds physical-size selection and the existing persisted diagnostic notice for the large in-place branch. Below the threshold, the protected copy/migration path is unchanged. Live qualification found retained JSON configuration files reaching the PostgreSQL anchor reader during pruning; the final head filters that existing list once, covered by the real rollback/prune test. Actual disk-space refusal also exposed two diagnostic issues: the report preferred a truncated prefix over the full recorded stderr tail, and normal startup progress printed completion lines after a failed start. The final head uses the existing bounded tail and emits completion only for successful startup phases, leaving the refusal last; CLI finalization is unchanged. Other changes reuse the schema owner's typed content-version reader, make undefined preflight success explicit, compute retention once, correct the docs, and remove 136 redundant wiring-test lines. Mode selection, corrected cleanup and final cause visibility require their own final-source live proof; ad7 live runs do not prove those changes.

Final head `5bbf3e6712` has the `816d247a8e` package runtime plus the SQLite-only legacy-safe discovery correction proved by the BLOB corpus. Remaining changes are the verified test overlay, a test-local rename/import correction, allocation notes and documentation. No PostgreSQL runtime change is excluded from the final 816 package proof.

The CLI failure was a physical-read mismatch, not an uncompleted notice: a real PostgreSQL run was `finished/succeeded`, but `update.runs.get` read the SQLite anchor and returned `run:null`, so the existing follower timed out. The shortcut predates this PR (`ba58d6a00b17`, openclaw#191332). The earlier PostgreSQL trial used Settings to start updates and `openclaw update status` to inspect them; it did not exercise foreground CLI following. The fix changes the reader owner, not polling, deadlines or the public protocol.

For historical BLOB registry paths, the existing preflight reader leaves non-string rows to Doctor. Both `main` and `ops` databases in the corpus are independently discovered at `agents/<id>/agent/openclaw-agent.sqlite`; the existing corpus test hashes **every** original database and checks its `.pre-` original (`test/state-upgrade.e2e.test.ts:189,247–248`). Non-default legacy BLOB registrations that fall outside that discovery remain a named openclaw#204394 limitation, not a new coercion or refusal.

Remaining test allocation (approved after those cuts):
- Real PostgreSQL ACL/non-superuser tests preserve reader access, ownership, grant options and historical layouts.
- Mixed-engine migration failure and crash recovery prove originals survive and only owned unreferenced namespaces are pruned.
- Copy-refusal tests prove preparation fails before stop with an actionable cause.
- Generic report projection and one nested startup-progress regression (tracing off/on) prove recorded boot-refusal remedies remain the final visible cause.
- One parameterized size-routing test proves under/over selection, the notice and retained SQLite protection.
- One real PostgreSQL terminal-read regression exercises the physical command path used by the CLI follower, rather than the SQLite anchor.

Production delta against the base: **+1192/−234, net +958 lines across 27 files**. The growth covers physical-engine inventory/validation, transactional access-right preservation, paired namespace retention, measured mode selection and refusal-output ordering. Existing duplicate private PostgreSQL capture work is removed; standalone and uncovered-store captures remain.

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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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.

Live update recovery metadata inspection can fail during SQLite checkpoints

1 participant