Repository navigation
feat(backup): create PostgreSQL archives while the Gateway runs - #185236
Conversation
- backup create captures each PostgreSQL store from its own repeatable-read export snapshot beside a running Gateway or embedded agent owner instead of refusing; with no owner it keeps offline custody as before - restore, Git backups, generic local snapshots, update capture, and Doctor ports keep refusing while the Gateway runs - read sequence allocation facts inside the export snapshot so a restored store never reissues a captured row ID after concurrent inserts - docs: describe online archive capture and its per-store consistency
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesAllows PostgreSQL archive creation while the Gateway runs and captures sequence allocations safely alongside concurrent inserts. Example: Run openclaw backup create --verify with state, agents, and Workboard on PostgreSQL 17.11.
Review scores
ProductKind: Feature · Worth it: Needs a maintainer decision · Fix scope: Partial Merge readiness⛔ Blocked before merge - 1 item remains This PR provides useful, focused work with no definite correctness finding; accepting the changed archive consistency contract requires a maintainer decision. Priority: P2 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherThe archive command passes captured configuration and engine selection into the existing backup owner, which exports PostgreSQL stores through workers and packages their matched anchors, images, and manifests. flowchart TD
A[Backup CLI] --> B[Archive planner]
B --> C[Backup ownership scope]
C --> D[Database backup worker]
D --> E[PostgreSQL store snapshots]
E --> F[Matched export capsules]
F --> G[Verified archive]
Technical reviewBest possible solution: Accept or reject online archive consistency explicitly, retaining this focused implementation and the existing stopped-Gateway path if approved. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the online refusal, and the contributor supplies before-and-after CLI evidence; this read-only review ran no target code. Is this the best way to solve the issue? The patch is a small implementation using the existing ownership callback and materializer, with distinct regressions for custody routing and allocation ordering. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 30fa910885f1. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +68, Docs +12. Total +91 across 9 files. Added test files: 1. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 26, 2026, 8:34 PM ET / October 27, 2026, 00:34 UTC. |
|
Merged via squash.
|
…claw#185236) - backup create captures each PostgreSQL store from its own repeatable-read export snapshot beside a running Gateway or embedded agent owner instead of refusing; with no owner it keeps offline custody as before - restore, Git backups, generic local snapshots, update capture, and Doctor ports keep refusing while the Gateway runs - read sequence allocation facts inside the export snapshot so a restored store never reissues a captured row ID after concurrent inserts - docs: describe online archive capture and its per-store consistency
Related: #183094
What Problem This Solves
openclaw backup createrefuses to run while the Gateway is up once any store is on PostgreSQL, so every routine backup on a PostgreSQL install means taking the Gateway down for the whole archive.User Impact
User impact: operators on PostgreSQL can take a verified whole-installation archive without stopping the Gateway; it keeps serving requests during the capture.
On one production install with state, agents, and Workboard on PostgreSQL, the nightly offline archive on 2026-10-26 stopped the Gateway at 05:00:04 and it was healthy again at 05:23:35 (15 GB archive, verified). The same morning's update stopped the Gateway at 07:42:39 and the archive step alone ran until 08:08:48. With this change, that nightly backup no longer needs downtime.
Unchanged and still offline-only:
backup restore, Git backups, generic local snapshots that select PostgreSQL, update capture, and Doctor database ports. With the Gateway stopped,backup createkeeps taking offline custody exactly as before.Consistency note for review (per the storage review checkpoint, this touches reader consistency): with the Gateway running, each PostgreSQL store is exported from its own
REPEATABLE READ READ ONLYsnapshot, and stores are captured one after another, not at one shared instant. That is the same per-store consistency the archive already gives live SQLite stores. Rows committed after a store's snapshot belong to the next backup. Operators who need one quiescent point across all stores can still stop the Gateway first.Why This Change Was Made
The PostgreSQL export already reads each store inside one repeatable-read, read-only transaction, so it is safe to run beside a live writer. The archive was refused only because it borrowed the offline-custody gate built for restore and update capture (#170828 added that gate together with the PostgreSQL backup path; its history records no separate reason to exclude online archive capture). This change lets only the archive caller run its read-only capture when a running Gateway or embedded agent owns the state, through the existing
onForeignOwnerhook that read-only commands such asworktrees listalready use.Running online exposed one real bug: the export read sequence allocation facts before its snapshot opened. A row committed in between was captured with an ID above the recorded allocation, so a matched restore would reissue that ID and the next insert would hit a duplicate key. Allocations are now read inside the export snapshot, and the manifest's PostgreSQL facts are read after the export; sequences only advance, so this can leave gaps but never reuse a captured ID. Offline behavior is unchanged because nothing writes between the reads.
Technical inventory
src/snapshot/database-backup.ts:runOfflineDatabaseBackuptakes{ online: true }. When set and the caller supplied its config and engine selection, a foreign owner runs the capture in the same database-backup scope instead of refusing. Nested store captures inside the archive join that scope. All other callers still passonForeignOwner: "refuse". The in-processhasActiveGatewayStateOwnerrefusal (backup inside the Gateway process) is unchanged.src/infra/backup-create.ts: the archive path opts in with{ online: true }.src/snapshot/database-backup-core.worker.ts:exportPostgresBackupno longer pre-reads allocations;materializeDatabasePortreads them inside its repeatable-read transaction, and the manifest records a post-export read.docs/cli/backup.md,docs/gateway/postgresql.md,docs/install/backups.md,docs/reference/database-engines.mddescribe online archive capture, its per-store consistency, and which commands stay offline-only.createBackupArchivecallers inherit the behavior:backup create --to <location>andmigrate apply's pre-migration backup now run beside a running Gateway; Doctor's schema-guard archive runs under its own maintenance custody and is unaffected.Evidence
Live run, isolated test Gateway on PostgreSQL 17.11 (scratch cluster and state dir, all three families on PostgreSQL):
3b3efe9539c, Gateway up):openclaw backup create --verifyrefused: "This operation requires exclusive offline state ownership ... This command is offline-only." No archive./readyzprobe): archive created in 6 s,Archive verification: passed, exit 0; 19/19 readyz probes returned 200; standaloneopenclaw backup verifypassed; archive contains state, agent, and Workboard PostgreSQL capsules. The Workboard capsule holds the 5 cards committed before its snapshot. After stopping the Gateway,openclaw backup restoreimported that capsule into a fresh namespace with the same 5 cards.Regression tests, red on main and green with the fix:
src/snapshot/database-backup.online.test.ts: archive capture runs beside a running owner and nested store captures join it; a non-archive capture still refuses. On main:LocalStateOwnerError ... This command is offline-only.src/infra/database-engine/logbook-port.postgres.test.ts(PostgreSQL conformance): a row committed just before the export snapshot opens is covered by the recorded allocation, and a restored store issues the next ID. On main:expected { value: '70', called: true } to deeply equal { value: '71', called: true }.Consumer tests: 10 backup unit test files (192 passed, 1 skipped) and 8 PostgreSQL conformance files (27 passed) covering archive create, verify, restore, mixed engines, update capture, Git backup secrets, and agent/state/logbook ports.
Lanes:
changed-lanesselected core, coreTests, docs.check:changed --stagedpassed format,tsgo:core,tsgo:core:test, oxlint on changed files, and the database ratchets and guards. Two steps failed,deprecated API usage(extensions/codex/harness.ts:261) anddead export scan(codex, agents, plugins exports). Both fail identically on the unmodified base and name no touched file.git diff --checkis clean.Not covered: a full production-sized (15 GB) online run, and a Gateway restart racing a running capture.
Command transcripts