Skip to content

feat(backup): preserve source artifacts for internal captures - #189638

Merged
roboclaw-bot merged 4 commits into
mainfrom
openclaw/backup-preserve-source
Oct 31, 2026
Merged

roboclaw-bot merged 4 commits into
mainfrom
openclaw/backup-preserve-source

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Internal filesystem captures need to read SQLite state without changing the source WAL index or recovering rollback journals in place.

User Impact

No new CLI flags or changes to ordinary backups. This adds the internal createBackupArchive({ preserveSourceArtifacts: true, ... }) mode for isolated migration/checkpoint capture processes. Default backup sanitization and compaction, archive format, and PostgreSQL online: true capture remain unchanged.

The internal mode preserves row IDs by skipping compaction, so free-page bytes can remain in its archive. It still applies the existing row-level sanitizers and is not a secure-deletion export.

Why This Change Was Made

The backup owner applies the existing artifact-preserving read scope during planning as well as private SQLite acquisition. Legacy audit reconciliation is refused before it can take a source write lease. Acquisition uses verified private images and preserves row IDs. No companion profile, anchor inventory, CLI, or quiescence API is included.

The hosted review's P2 fixture finding is repaired at the shared backup scratch owner: drain fixture state, retire idle state readers and the retained native broker, then remove the case directory. Failed custody settlement retains the directory. The regression starts cold with a short fixture prefix so a long-socket-path fallback cannot mask the deleted-socket failure. Production behavior is unchanged by this repair.

Extracted and adapted from galiniliev's source commit, with contributor credit retained.

Evidence

Changed preserving mode through the production CLI consumer

This is additional evidence for the changed mode, distinct from the ordinary CLI compatibility run below. The existing stacked consumer in PR #189685 executed its built CLI while a disposable Gateway and PostgreSQL 17.11 were running:

node dist/index.js --profile <isolated-profile> backup create
  --local-companion --verify --no-include-workspace
  --output <owned-checkpoint.tar.gz> --json
exit: 0
localCompanion: true
verified: true

The original native command and terminal receipt, successful build log, clean build stamps, capture output, witness implementation and retained archive were independently inspected—not inferred from PR6's rating. Runtime source was 399a3cfc1ab391ae5c17b85350aa2b7c1aabde6e; both build stamps and build-info identify it. The comparison to integrated consumer head 9bbf226cf8db03c4ed0b96effc4143d296620c2a changes only three test/support/allocation files, so the tested production inputs remain identical.

The call chain was personally checked: CLI option/action → unchanged backupCreateCommand option forwarding → archive owner selecting preserveSourceArtifacts: true → the preserving planning scope and private SQLite snapshot acquisition. The private-acquisition/row-ID block is byte-identical to this PR, as are sqlite-snapshot.ts, sqlite-readonly-location.ts, sqlite-snapshot-staging-owner.ts, artifact-preserving-state-reads.ts, commands/backup.ts, and the lockfile. The two archive modules as a whole are not claimed identical: PR6 adds profile/anchor inventory and its own destination policy.

The retained 953,531-byte archive has SHA-256 7f149851302acccaeef09415c98c367b534135db960240dd81dcb7e3929f259c. Its unique manifest reports local-companion, one PostgreSQL anchor and zero export capsules; it contains both the shared-anchor and fixed-local credential SQLite images. A separate read-only audit extracted private copies and matched whole-row hashes/counts against the original capture-time witness: 2 device identities, 2 device tokens and 1 native exec socket credential, with the same anchor store/engine/namespace. No credential values are published. Retained final-effect receipts additionally show offline verify/restore, a successful allowed protected RPC after activation, and rejection before effect of a client revoked after capture.

This qualifies actual production-consumer selection/acquisition and a usable archive. PR6's credential-retention policy is not attributed to PR4, which retains its existing sanitizers. The exact-base WAL/DELETE fingerprint, row-ID and sanitization oracles below remain the detailed preservation proof; this retained consumer run is not mislabeled as a new before/after WAL measurement. No new public API or service rerun was introduced for this evidence audit.

Original-base, invariant and compatibility proof

  • Exact original-base red: Ran the final regression against unchanged production code at f1c93577085244aa96aa87b53a2df9b59d293bd7 in a separate checkout, copying only the regression and corrected fixture helper. Both cases failed at the intended product assertions: WAL capture changed a source-family SHA-256; DELETE capture produced row ID 1 instead of 71. Setup failures are not counted as this evidence.
  • Hosted finding red/green: Personally reproduced the reviewed-head CI failure: WAL passed, then DELETE failed with connect ENOENT for the previous case's removed scratch/oc-br-*/resource.sock. Native Bun and a short CI-style temporary root exposed it; the earlier long local path had relocated the socket outside case scratch and masked the lifetime mismatch. With the shared cleanup repair, both unchanged preservation assertions pass.
  • CI-equivalent affected groups: scripts/ci-run-node-test-shard.mts, OPENCLAW_CI_TEST_RUNTIME_POLICY=bun-all, short CI-style TMPDIR, and the original seven changed-3 targets followed by all remaining shared-fixture consumers: 16/16 invocations, 241 tests passed, zero failed invocations. This covers config capture, archive streaming/publication, audit migration/restore and bounded retries, credentials, ownership, privacy, mixed engines, ordinary backup commands, atomic publication, restore/verification and SQLite hardlinks. No test timeout, assertion, skip, or baseline exception was weakened.
  • Final-effect preservation: Both WAL and rollback-journal cases compare source SHA-256, device/inode, size, mtime/ctime and sidecar presence, then extract the real archive and independently check committed values, row ID 71 and cleared destination leases. External native writers are necessary to preserve genuine SQLite lock ownership. Latest local preservation bodies: 3.029s, file duration 9.68s, wrapper wall time 17.77s. Audit suite: 8 passed, file duration 21.32s, wrapper wall time 24.85s. These are local per-file timings; current-head hosted CI has since completed successfully.
  • Real shipped CLI compatibility: Ran pnpm openclaw --profile <isolated-profile> backup create --verify --no-include-workspace --json, then backup restore --json, with synthetic state, matching isolated service selectors and an owner-claimed port. The restored database independently retained the committed witness value, compacted its implicit row ID from 71 to 1 as ordinary backups should, and contained zero runtime leases. No live Gateway was changed and no publication guard was disabled. This proves ordinary CLI compatibility; the new preserving mode deliberately remains an internal archive-owner API.
  • Checks and independent review: Complete scoped check:changed passed, including all core test type graphs, guards, dead-export scans, core/script lint and formatting. Targeted type-aware lint on the two repaired TypeScript files passed all 293 rules with zero warnings/errors; git diff --check and the test-line ratchet passed. Final full-PR local autoreview against the original base completed source verification with no actionable P0–P2 findings. Its earlier INDEX-only finding was resolved by staging the reviewed repair and verifying index/worktree equality before the final review. The reviewed repair is dc21e69acc5f63c281f3a531e4252a4cda68387e; publication head 9bac5c28b3c3094ad653119ce06082e4173fe62a is tree-identical. Local ClawSweeper was unavailable; the documented local-autoreview/hosted-review fallback is used. Paginated current-head CI readback observed 139 terminal check runs: 63 success, 75 skipped, 1 neutral, no failure or pending; all three commit statuses, including openclaw/ci-gate, are successful. Skipped runs are not counted as executed proof.
  • Scope and cost: One unique +142-line test allocation, shared scalar unchanged; the fixture repair adds 23 test/support lines. Production net growth remains 46 lines. Earlier timeout/setup attempts were retained as failed attempts, not credited as success or established baseline failures; the source-bound results above are the final proof.

Worked on by

roboclaw-bot and others added 2 commits October 31, 2026 18:16
Worked on by:
- @galiniliev

Co-authored-by: galiniliev <[email protected]>
OpenClaw-Publication: 13c22d85-5d08-4693-a372-4f031d1e46e8
@clawsweeper

clawsweeper Bot commented Oct 31, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature 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:feature Preliminary submission classification; full source review pending. labels Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds an internal backup mode that preserves source SQLite artifacts and row IDs while retaining existing row-level sanitizers.

Example: Capture a database containing witness row ID 71 while an external SQLite writer holds a WAL or rollback journal.

  • Before: Capture can change source-family artifacts, and compaction changes the archived row ID to 1.
  • After: The preserving mode leaves source fingerprints unchanged and archives committed data with row ID 71 while clearing destination runtime leases.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused implementation, shipped-consumer evidence, meaningful regression controls, resolved prior finding, and successful current-head gates support landing.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied built CLI consumer trace exercises preserving-mode selection and private acquisition with a usable verified archive; source comparisons confirm unchanged production inputs for that run. Independent archive assertions cover WAL and rollback-journal fingerprints, committed data, preserved row IDs, and destination sanitization, while the ordinary CLI round trip covers default compatibility.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Internal migration and checkpoint captures need committed SQLite images without changing source journals or implicit row IDs.
Reason: The maintainer-authored direction has a concrete stacked consumer and keeps the capability inside existing backup owners without adding CLI configuration.

Merge readiness

✅ Ready for maintainer review

This PR provides a useful internal capture mode with adequate behavior evidence and no remaining actionable findings; it is ready for normal landing.

Priority: P2
Reviewed head: 9bac5c28b3c3094ad653119ce06082e4173fe62a

Before merge

None.

Findings

None.

Agent review details

How this fits together

The archive owner resolves backup resources, acquires verified SQLite images, sanitizes private copies, and publishes a restorable archive.

flowchart TD
  A[Internal capture caller] --> B[Backup archive owner]
  B --> C[Artifact preserving planning scope]
  C --> D[Existing SQLite acquisition owner]
  D --> E[Private image and row sanitizers]
  E --> F[Archive publication]
  C --> G[Legacy audit refusal]
Loading

Technical review

Best possible solution:

Land the focused internal mode using the existing acquisition owners and retain ordinary backup compaction and sanitization defaults.

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

This is an additive capability; supplied original-base controls fail at source-fingerprint and row-ID assertions, and the retained regressions exercise those contracts through the real archive owner.

Is this the best way to solve the issue?

The change is appropriately scoped: it reuses existing read scopes and private acquisition, preserves sanitizers, and refuses legacy reconciliation that would violate source preservation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Legacy audit capture and bounded retries keeps the original intent (0d17751: Avoid lease expiry during slow snapshots while preventing duplicate audit imports after restore.)
  • Ordinary snapshot compaction changes intended behavior with a stated reason (386b0e6: Capture live SQLite state in verified, sanitized images; ordinary backup compaction removes deleted data from free pages.)
  • Canonical database ownership and sanitization keeps the original intent (2f17d11: Preserve configured agent roots through a shared resource inventory and apply canonical snapshot guarantees.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Introduced behavior and unchanged defaults: The pinned introduced diff adds an opt-in internal parameter, scopes planning reads, and selects private acquisition with preserved row IDs; ordinary capture retains its existing path. (src/infra/backup-create.ts:347, 9bac5c28b3c3)
  • Preservation and sanitization boundary: The acquisition block reuses createVerifiedSqliteSnapshot; global, agent, and client sanitizers remain in place. The WAL and DELETE regressions compare source hashes and identities, then inspect committed values, row ID 71, and cleared leases in the extracted archive. (src/infra/backup-sqlite-snapshot.ts:406, 9bac5c28b3c3)
  • Original audit consistency contract retained: The bounded capture-and-witness algorithm from fix(backup): preserve audit capture across slow snapshots #130962 is relocated without removing its consistency checks; preserving capture refuses before acquiring the source write lease. (src/infra/backup-sqlite-snapshot.ts:687, 0d1775116e44)
  • Changed-mode production consumer proof: The self-contained terminal evidence records a successful built CLI capture through feat(backup): add PostgreSQL local companion checkpoints #189685 with localCompanion and verified both true. Its source selects preserveSourceArtifacts and contains the same private-acquisition block. The tested-runtime comparison changes only test/support/allocation files; the consumer's separate credential policy is excluded from this assessment. (src/infra/backup-create.ts:347, 9bbf226cf8db)
  • Earlier finding resolved: The shared fixture now drains state cleanup, retires idle state readers and the retained broker, and only then removes scratch; failed settlement retains the directory. The cold, short-root regression exposes the previously masked socket lifetime failure. (src/infra/backup-create-family.test-support.ts:47, 9bac5c28b3c3)
  • Current-head checks and mergeability: Paginated readback found all check runs terminal, with 64 successful, 85 skipped, one neutral, and no failures; all three commit statuses succeed. GitHub reports the reviewed head mergeable and clean. (9bac5c28b3c3)

Likely related people:

  • Peter Steinberger: Raw commit 9bb764c adds src/infra/backup-sqlite-snapshot.ts:365 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9bb764cb29f0; files: src/infra/backup-sqlite-snapshot.ts)

PR surface

Source +46, Tests +142, Other +2. Total +190 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 100 54 +46
Tests 3 152 10 +142
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 6 254 64 +190

Review metrics

Metric Value Why it matters
Production versus test growth Production +100/-54; tests and support +152/-10 Growth adds preservation selection and distinct WAL, rollback-journal, and legacy-audit refusal coverage; much of the production addition relocates the existing audit capture algorithm.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: A useful internal backup capability with limited scope and unchanged ordinary CLI defaults.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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 (2 earlier review cycles)
  • reviewed 2026-10-31T18:33:44.791Z sha d945ef9 :: needs changes before merge. :: [P2] Retire the retained broker before deleting each case's scratch root
  • reviewed 2026-10-31T20:37:07.426Z sha 9bac5c2 :: needs maintainer review before merge. :: none

Reviewed October 31, 2026, 5:24 PM ET / 21:24 UTC (Revision 3).

roboclaw-bot and others added 2 commits October 31, 2026 20:29
Keep per-case native socket custody until state readers and the broker join.
Start preservation proof cold under short roots so the socket-path fallback
cannot hide the removed-socket regression.

Co-authored-by: galiniliev <[email protected]>
Worked on by:
- @galiniliev

Co-authored-by: galiniliev <[email protected]>
OpenClaw-Publication: 8d66e0e9-1742-4a32-b7ef-5349abb5dece
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. 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:feature Preliminary submission classification; full source review pending. labels Oct 31, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 31, 2026
@roboclaw-bot
roboclaw-bot merged commit f33e48e into main Oct 31, 2026
161 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/backup-preserve-source branch October 31, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants