Repository navigation
feat(backup): recorded runs, scheduled backups, and git-backed versioned snapshots - #122485
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed August 12, 2026, 10:20 AM ET / 14:20 UTC. ClawSweeper reviewWhat this changesThis PR adds recorded backup runs, scheduled Gateway jobs, and Git-backed versioned SQLite backup, verification, restore, status, and Doctor flows. Merge readiness⛔ Blocked by patch quality or review findings - 8 items remain Keep open: the current head has two P1 security-boundary defects in Git-backup ownership and redaction, so it is not ready to merge. Priority: P1 Review scores
Verification
How this fits togetherBackup commands create verified copies of shared and agent SQLite state, then store deterministic snapshots in an operator-owned Git repository. Gateway cron can invoke the same command periodically, while backup records feed Status and Doctor freshness guidance. flowchart LR
A[State and agent databases] --> B[Backup command]
B --> C[Verified snapshot]
C --> D[Git backup repository]
E[Gateway cron job] --> B
B --> F[Backup run record]
F --> G[Status and Doctor]
D --> H[Restore and verify]
Before merge
Findings
Agent review detailsSecurityNeeds attention: The new remote-backup path can expose operator-staged data and a current-main device bootstrap credential. PR surfaceSource +2139, Tests +1182, Docs +202, Other +1. Total +3524 across 45 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Make backup commits path-limited and make redaction inventory cover the merged current-state schema before any remote Git backup can be merged. Do we have a high-confidence way to reproduce the issue? Yes: stage an unrelated file before running a Git backup and inspect the resulting commit; separately create a current-main pairing join code and run a redacted Git backup to observe its payload being dumped. Is this the best way to solve the issue? No: the feature path is plausible, but plain Git commit does not preserve its scoped-staging invariant and the inventory must be reconciled with current main’s credential-bearing table. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c5ba4efbd700. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
|
Addressed all seven findings on head 3891ae9:
Focused gate: 193 tests passed with 2 intentional skips; exact @clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Follow-up to the seven-finding repair summary above: CI exposed that explicitly passing @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
ce2d18a to
5157769
Compare
|
Resolved both exact-head P1 findings on rebased head 5157769:
Commit: 5157769ab02c Proof: focused gate green (22 unit tests, 8 command tests); env ratchet 502/502; Kysely guardrails green; format and @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…ned snapshots (openclaw#122485) * refactor(infra): extract shared git exec and verified snapshot-copy helpers Moves the worktrees git wrapper to src/infra/git-exec.ts (with optional maxOutputBytes for large buffered reads) and the online-backup/sanitize/ VACUUM/verify snapshot step into src/snapshot/openclaw-snapshot-copy.ts so snapshot backends share one hardened copy path. Behavior-identical moves; all importers updated. * feat(snapshot): git-backed versioned SQLite snapshot engine Deterministic per-table JSONL dumps (PK-ordered, lossless bigint/blob encoding), verbatim DDL preservation, virtual/shadow-table skipping with FTS rebuild on restore, secret-table redaction policy, manifest with per-table row counts and content hashes, and restore verification by re-serialization. Unchanged data produces no commit. * feat(backup): recorded runs, freshness surfacing, and scheduled git backups Every backup attempt is recorded in the previously writer-less backup_runs table (bounded to 200 rows). openclaw status gains a Backups overview row and JSON payload; doctor prints an informational hint when no successful backup is recorded or the newest is stale. New commands: backup git init/create/log/verify/restore and backup enable/disable, which provision one idempotent gateway cron job running scheduled git backups. * fix(state): stop bumping schema_meta.updated_at on unchanged opens updated_at now records when schema metadata actually changed instead of when the database was last opened; unconditional bumps dirtied the row on every open and defeated no-change backup detection. * docs: document versioned git backups, scheduling, and backup freshness * fix(backup): satisfy CI ownership checks * fix(backup): complete CI contract coverage * fix(backup): complete credential table redaction * fix(backup): isolate git repository ownership * fix(backup): persist push degradation * fix(backup): atomically converge schedules * fix(status): isolate backup freshness environment * fix(status): carry scan environment to freshness reads * fix(backup): harden Git repository ownership * docs(backup): document Git repository safety * fix(backup): non-creating outcome log and origin preflight for pushed schedules Recording a backup outcome never bootstraps an absent state database (a failed backup on a fresh host would otherwise create a blank DB that a retry treats as real input), and backup enable --push now requires the repository to have an origin remote, pointing at backup git init --remote instead of scheduling permanently degraded pushes. * refactor(worktrees): use shared git exec helpers * refactor(worktrees): remove unused git buffer wrapper * refactor(worktrees): consume buffered git helper * feat(backup): redact pushed schedules by default Unattended recurring pushes retain credential-bearing tables durably in remote Git history, so backup enable --push now defaults to --exclude-secrets; --include-secrets is the explicit full-fidelity override (still warned). Local non-push schedules keep full fidelity for complete restores. * fix(backup): redact audit HMAC and OAuth pending state; tolerate absent backup_runs Adds audit_identity_keys (audit HMAC key) and mcp_oauth_pending_authorizations (live OAuth callback state) to the redaction inventory, and makes read-only backup freshness treat a same-version database without the additive backup_runs table as no recorded backups instead of failing before a writable open converges the schema. * fix(backup): restrict schedules to local gateways * fix(snapshot): harden Git restore and redaction * fix(backup): block pushes of adopted history * fix(backup): contain commits and pairing secrets
What Problem This Solves
Backups existed only as a manual command: nothing ran them on a schedule, nothing recorded that they ran, and nothing noticed when they silently stopped. The
backup_runsstate table had zero production writers. Snapshots were full copies with no incremental or offsite path, and the docs explicitly declared scheduling, upload, retention, and incremental behavior out of scope.Why This Change Was Made
Backups become an operated system plus an efficient versioned backend, per the operator discussion of backup strategies:
backup_runs(bounded to 200 rows, best-effort, never fails the backup).openclaw statusgains aBackupsoverview row + JSON payload;openclaw doctorprints an informational hint when no successful backup exists or the newest is older than 14 days.openclaw backup enable --repository <dir> [--every 24h] [--push] [--exclude-secrets]provisions one idempotent gateway cron job (kind: "command", isolated session target) runningbackup git create --all;backup disableremoves it.backup git init|create|log|verify|restore. Deterministic per-table JSONL dumps (PK-ordered, lossless int64/blob encoding), verbatim SQLite DDL preserved, one commit per backup run, push optional. Unchanged databases produce no commit, so quiet cycles are free.vec0(memory-core reprovisions and reindexes on first use), and omitssession_transcript_index_stateso gateway startup reconciliation rebuilds the transcript FTS projection. Restores verify by re-serialization against per-table manifest hashes plusPRAGMA integrity_check/foreign_key_check.--exclude-secretsredacts the credential-bearing tables (documented list); pushing without it warns that history carries credential material.Supporting refactors: the worktrees git wrapper moved to
src/infra/git-exec.tsand the hardened online-backup/sanitize/VACUUM/verify copy step intosrc/snapshot/openclaw-snapshot-copy.ts, shared by the local and git snapshot backends (behavior-identical, all importers updated). One owner-level fix:schema_meta.updated_atno longer bumps on every database open — it records when schema metadata actually changed, which unconditional bumps previously defeated any no-change detection.User Impact
Operators get scheduled, history-keeping, offsite-capable backups with three commands (
backup git init,backup enable, done), visible freshness instatus, and a doctor nudge before the missing-backup regret moment. No new config keys or env vars; no schema changes (thebackup_runstable already existed).Evidence
Live-tested against copies of real production databases (24MB state DB, 55MB agent DB with FTS5, sqlite-vec, and 7.6MB of embedding blobs) in an isolated
OPENCLAW_STATE_DIR:backup git create --all: first run commits; second and third runs reportno changes(idempotence held only after theschema_meta/backup_runsfixes — the live test caught both).backup git verify: global 4.2s, agent 2.2s — every table digest byte-identical after full restore + FTS rebuild, including a 17MB trajectory table (which also exposed and fixed a 1MB exec buffer cap).backup git restore --agent main: 3,497 transcript events byte-preserved,user_version17, projection/vec tables correctly absent,integrity_checkok.--exclude-secrets: zero secret-table files in the tree; manifest documents exactly the six redacted state tables.statusshowsBackups │ last ok just now (git); doctor prints the no-backup hint on a fresh state dir.backup enable/disableround trip against a session-owned dev gateway (port 19917): job created (every 6h), idempotently updated (12h), removed;cron listconfirms each step.--allskips agents whose registered DB no longer exists (real stale QA-suite path found in production state) instead of aborting the scheduled run.Gates: focused vitest suites green (git codec, run records, schedule, snapshot repository 65, doctor contributions 107, status 19, worktrees);
pnpm buildgreen including SDK-export and dynamic-import boundary checks; env-var ratchet 502/502; autoreview (Codexgpt-5.6-sol, high) clean, zero accepted findings.Main repair carried in this PR
check-test-typesis red on currentmain: commit 92f5f07 (#114506) addedlookupFnstubs inextensions/browser/src/browser/cdp.helpers.test.tsthat do not satisfy theLookupFnoverloads, and the breakage slipped through cancelled main-push CI. This PR repairs it with the established typed-stub pattern (seesrc/infra/net/ssrf.pinning.test.ts) per the never-land-onto-red rule.