Skip to content

feat(backup): add verified SQLite snapshots#105718

Merged
vincentkoc merged 10 commits into
mainfrom
feat/sqlite-snapshot-cli
Jul 12, 2026
Merged

feat(backup): add verified SQLite snapshots#105718
vincentkoc merged 10 commits into
mainfrom
feat/sqlite-snapshot-cli

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Related: #94805
Related: #94967
Related: #101290

What Problem This Solves

OpenClaw had no supported way to capture one live SQLite database as a compact, portable, independently verifiable artifact. Operators either copied live database files and WAL sidecars, or relied on broad backup archives that do not provide a database-scoped restore primitive. That creates avoidable corruption and partial-copy risk during host moves, container replacement, failover preparation, and incident recovery.

This also supersedes the uneditable contributor prototype in #94805 while preserving Gio Della-Libera's design contribution and keeping the stress work in #94967 as the next validation slice.

Why This Change Was Made

This adds openclaw backup sqlite create|list|verify|restore backed by a strict local snapshot repository. Creation validates the source, uses SQLite VACUUM INTO to capture committed WAL state, verifies the compacted output, hashes and manifests it, and publishes only a fully synced snapshot directory. Verification and restore re-copy content into private pinned staging paths before SQLite opens it, and restore writes only to a fresh destination outside the repository.

The repository fails closed on schema, index, ownership, ACL, path-identity, manifest, hash, unexpected-entry, hardlink, symlink, and publication-race violations. Windows uses protected DACL directory creation; macOS validates ACL captures; POSIX paths require private ownership and modes. Scheduling, upload, retention, incremental WAL bundles, and in-place live database replacement remain out of scope.

User Impact

Operators can now create compact snapshots for the shared state database or a per-agent database, sync only completed snapshot directories, verify them independently, and restore into a fresh SQLite file. The command refuses unsafe repositories, tampered artifacts, unsupported database roles, existing restore targets, stale sidecars, and incomplete publications instead of guessing or falling back.

Evidence

  • Blacksmith Testbox through Crabbox tbx_01kxc5txjedwzht2hc1vzw3gyp (tidal-crayfish), Actions run https://github.com/openclaw/openclaw/actions/runs/29210878108.
  • Exact rebased pnpm check:changed against origin/main 2c06dfdd2f: passed in 9m57s.
  • Production pnpm build: passed in 1m29s.
  • Hosted Linux focused proof: 124 tests passed with 4 expected platform skips across schema contracts, canonical indexes, snapshot repository, SQLite snapshot primitive, CLI registration/preaction, and command behavior.
  • Native Windows 11 ARM64, Node 24.13.0 and pnpm 11.2.2: 50 tests passed with 16 expected platform skips, including protected-DACL creation, ACL validation, atomic concurrent repository creation, non-ASCII paths, WAL capture, create/list/verify/restore, and native path-length constraints.
  • Native macOS: 64 tests passed with 2 expected platform skips across the repository and infra snapshot suites, including owner/mode/ACL/path-race checks.
  • Fresh structured autoreview after rebase: no accepted or actionable findings.
  • git diff --check origin/main...HEAD: passed.

@vincentkoc vincentkoc self-assigned this Jul 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: XL maintainer Maintainer-authored PR labels Jul 12, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Land-ready proof for head 6303a48a4b726b2fa38bcb15f85c58e851e42eb3:

  • Blacksmith Testbox through Crabbox: tbx_01kxc5txjedwzht2hc1vzw3gyp (tidal-crayfish), Actions run https://github.com/openclaw/openclaw/actions/runs/29210878108.
  • env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 corepack pnpm check:changed: passed on the exact rebased diff in 9m57s.
  • corepack pnpm build: passed in 1m29s.
  • corepack pnpm test:serial src/infra/sqlite-schema-contract.test.ts src/infra/sqlite-index-schema.test.ts src/snapshot/local-repository.test.ts src/infra/sqlite-snapshot.test.ts src/cli/program/preaction.test.ts src/cli/program/register.backup.test.ts src/commands/backup-sqlite.test.ts: 124 passed, 4 expected platform skips across 5 shards.
  • Native Windows 11 ARM64, Node 24.13.0, pnpm 11.2.2: 50 passed, 16 expected platform skips. This covered protected DACL creation, ACL validation, atomic concurrent repository creation, non-ASCII paths, WAL capture, and create/list/verify/restore. WSL is not installed on that VM, so no WSL claim is made here.
  • Native macOS: 64 passed, 2 expected platform skips across the repository and infra snapshot suites.
  • Fresh post-rebase structured autoreview: no accepted/actionable findings.
  • git diff --check origin/main...HEAD: passed.

Known follow-up: cross-process destructive stress, crash injection, high-I/O repetition, additional containers/sandboxes/architectures, and the broader gateway/CLI database ownership race remain tracked under #94967 and #101290. They are the next workstream, not hidden proof for this local snapshot primitive.

@vincentkoc
vincentkoc marked this pull request as ready for review July 12, 2026 22:26
@vincentkoc
vincentkoc merged commit 2f25e9c into main Jul 12, 2026
129 of 133 checks passed
@vincentkoc
vincentkoc deleted the feat/sqlite-snapshot-cli branch July 12, 2026 22:27
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 13, 2026
* feat(backup): expose verified SQLite snapshots

Co-authored-by: Gio Della-Libera <[email protected]>

* feat(sqlite): add verified snapshot repository (openclaw#105525)

Co-authored-by: Gio Della-Libera <[email protected]>

* test(sqlite): use canonical snapshot schemas

* fix(backup): restrict SQLite snapshot roles

* fix(sqlite): harden snapshot staging paths

Co-authored-by: Gio Della-Libera <[email protected]>

* fix(sqlite): pin snapshot repository paths

Co-authored-by: Gio Della-Libera <[email protected]>

* fix(sqlite): secure Windows snapshot staging

Co-authored-by: Gio Della-Libera <[email protected]>

* fix(sqlite): validate macOS ACL captures

* test(sqlite): preserve stat uid type

* style(sqlite): satisfy snapshot lint

---------

Co-authored-by: Gio Della-Libera <[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 commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant