Skip to content

fix: keep scheduled Git backups current on PostgreSQL - #201870

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/online-postgres-git-backups
Nov 20, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/online-postgres-git-backups

Conversation

@VACInc

@VACInc VACInc commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

Scheduled Git backups could not capture PostgreSQL stores because they run beside the Gateway, while Git capture required offline ownership. Use the existing online, read-only per-store backup path so these schedules can capture current data.

What Problem This Solves

With PostgreSQL shared state, every scheduled Git run failed. With SQLite shared state and PostgreSQL agents, --all could commit shared state while skipping agent history as degraded.

User Impact

Git capture can run while the Gateway serves requests, including scheduled backups. PostgreSQL restores and generic local snapshots keep their offline custody requirement. Snapshots remain consistent per store, rather than across the entire installation at one instant.

Why This Change Was Made

Git capture now prepares its config and engine selection and passes them to the same online capture owner used by archive backups. It keeps the existing export format, sanitization, and secret-redaction path. The documentation now distinguishes online capture from offline restore.

Root Cause

captureGitPostgresBackup called runOfflineDatabaseBackup without prepared config or the online-capture option. The scheduled CLI child therefore refused the running Gateway owner. The existing --all agent-degradation behavior converted that refusal into a skipped agent scope in mixed installations.

On baseline 3587df70a233dc639b733b9169797d3abd138301, the new CLI-child regression failed with This operation requires exclusive offline state ownership for PostgreSQL shared state. The mixed-engine case exited successfully but returned Agent main degraded instead of capturing the agent.

Real behavior proof

On Linux, Node 26.13.1, and a disposable PostgreSQL 18.7 server:

  • The regression runs the real backup command in a child beside a real Gateway custody owner. Both all-PostgreSQL and SQLite-state/PostgreSQL-agent cases now pass. Two consecutive captures contain the updated PostgreSQL session rows and no degraded-scope warnings.
  • An isolated foreground Gateway created a managed global-only Git schedule. cron run <id> --wait --json returned status: ok; run history reported completionStatus: succeeded with a Git commit and no degradation warning. backup git verify --global --json verified the committed PostgreSQL capsule. The Gateway still answered health checks afterward.
  • Existing offline discovery, retained-scope handling, artifact verification/restore, and PostgreSQL secret-redaction tests passed.

Commands used for the Gateway proof, with fixture paths omitted:

openclaw backup enable --repository "$repo" --every 24h --global-only
openclaw cron run "$job" --wait --wait-timeout 3m --json
openclaw cron runs --id "$job" --json
openclaw backup git verify --repository "$repo" --global --json
openclaw gateway call health --json

Copied result: scheduled Git run ok; PostgreSQL global capsule committed and verified; Gateway still healthy.

What was not tested

No paid model calls, external Git push, or native Windows/macOS run. The Gateway used mock-only model configuration; this backup flow does not invoke a model. There is no like-for-like successful-capture benchmark because the baseline refuses custody before capture. No latency claim is made.

Initial local attempts hit fixture setup failures: preload URL handling, private temporary-directory modes, mixed-engine fixture ownership, and missing search extensions. These were corrected in disposable fixtures before the reported proof. A first Gateway run captured PostgreSQL shared state but warned about an unprovisioned agent; the final global-only schedule completed without that warning.

Verification

  • OPENCLAW_VITEST_RUNTIME=node pnpm test src/infra/database-engine/git-backup.postgres.test.ts src/infra/database-engine/git-backup-secrets.postgres.test.ts src/snapshot/database-backup.online.test.ts src/snapshot/database-backup.test.ts --maxWorkers=1, with the database conformance preload: 21 tests passed across the completed runs. Secret-redaction agent cases were rerun after adding the required extensions to their fixture database: 4/4 passed.
  • Targeted TypeScript check extending tsconfig.core.json for the changed production owner, regression, and declaration inputs: passed.
  • Targeted type-aware lint, formatting of all six changed files, and git diff --check: passed.
  • pnpm build:runtime: passed in 2m 11s. It emitted advisory Control UI size-budget warnings.
  • Changed regression file: four tests passed; the two new custody cases took 63.3s and 19.2s in this local run. Real subprocess custody and repeated PostgreSQL exports are the contract under test. Exact-head CI timings for the new cases were 61.0s and 18.5s; all four tests in that file passed in PostgreSQL shard 3.
  • Simplification pass: reuse one existing capture owner; no new state, wrappers, or recovery policy. Production delta: +9/-1 lines. Regression delta: +77/-1 lines.
  • Local autoreview on the complete candidate against 3587df70a233dc639b733b9169797d3abd138301, with full backup/custody context: P0–P2 scoped-clean, no findings. The reviewer did not rerun tests in its isolated sandbox. The initial wrapper launch failed before review; the installed native CLI completed the review with isolation retained.

Exact-head CI completed successfully, including all four PostgreSQL conformance shards and the PostgreSQL 16 smoke lane. Hosted review reviewed 9fdf1390deb2333159128cdc4f7281a100c2ddea with no findings and sufficient behavior proof. Maintainer review remains required before merge.

@clawsweeper

clawsweeper Bot commented Nov 19, 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 docs Improvements or additions to documentation gateway Gateway runtime size: S labels Nov 19, 2026
@VACInc
VACInc marked this pull request as ready for review November 19, 2026 13:59
@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets PostgreSQL Git backups capture current data while the Gateway runs by reusing the existing online snapshot path.

Example: A scheduled Git backup runs with SQLite shared state and PostgreSQL agent main after session_nodes.updated_at changes from 2 to 3.

  • Before: The backup can succeed with an Agent main degraded warning while retaining older agent history.
  • After: The next Git backup contains updated_at 3 without a degraded-agent warning.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with supplied end-to-end CLI evidence and meaningful regressions; broad exact-head PostgreSQL validation remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied Linux Gateway proof exercises backup enable, cron execution, committed PostgreSQL capsule verification, and subsequent health checks; subprocess regressions additionally cover fresh agent rows in both engine configurations.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scheduled PostgreSQL Git backups cannot refresh stores while the Gateway owns them, and mixed installations can retain stale agent backups despite a successful command.
Reason: The maintainer-authored direction restores useful scheduled backups through an existing supported capture mechanism with a narrow production change.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a current PostgreSQL backup failure with a focused change; no actionable correctness or security defects were found.

Priority: P2
Reviewed head: 9fdf1390deb2333159128cdc4f7281a100c2ddea

Before merge

None.

Findings

None.

Agent review details

How this fits together

Scheduled backups invoke the Git backup command in a child process; selected stores pass through the shared database capture owner and become verified capsules committed to a Git repository.

flowchart LR
  A[Backup schedule] --> B[Git backup CLI child]
  B --> C[Selected database stores]
  C --> D[Existing online capture owner]
  D --> E[Read only PostgreSQL snapshot]
  E --> F[Verified Git capsule]
  F --> G[Git commit]
Loading

Technical review

Best possible solution:

Use the existing online read-only capture owner for Git backups while retaining the current sanitization, artifact format, and offline restore boundary.

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

Current-main source establishes the offline-custody refusal and mixed-engine degradation path, and the PR records matching baseline failures; target code was not executed during this review.

Is this the best way to solve the issue?

This is the smallest complete repair: Git capture opts into an established production owner, and the two regression cases protect distinct failure outcomes without adding production machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still contains the failure path: Git capture calls runOfflineDatabaseBackup without prepared configuration or online permission, while the shared owner refuses foreign ownership by default; mixed-engine --all capture converts an agent failure into a degraded warning. (src/snapshot/database-backup.ts:226, fb9e9fdfcf6c)
  • Focused reuse of the existing capture owner: The introduced production hunk prepares configuration and engine selection, then opts Git capture into the same online path archive backups already use; export, redaction, and restore implementations remain unchanged. (src/snapshot/database-backup.ts:225, 9fdf1390deb2)
  • Distinct regression coverage: The added cases use a real command child beside acquired Gateway custody for all-PostgreSQL and mixed-engine installations, checking successive exported row values and the committed PostgreSQL manifest without degradation warnings. (src/infra/database-engine/git-backup.postgres.test.ts:262, 9fdf1390deb2)
  • Supplied shipped-entry-point proof: The PR records an isolated Linux Gateway and PostgreSQL 18.7 run: a managed global-only schedule completed successfully, Git verification accepted its committed capsule, and the Gateway remained healthy; it also records the intended baseline failures. (9fdf1390deb2)
  • Prior online-capture design: feat(backup): create PostgreSQL archives while the Gateway runs #185236 established per-store read-only online capture and expressly left Git capture offline; this PR explains extending that existing mechanism while preserving offline restore and per-store consistency. (src/snapshot/database-backup.ts:84, f7b61f049a5c)
  • Exact-head validation remains pending: The reviewed head has PostgreSQL conformance checks running or queued, with no failed check returned by the inspected check-runs response. (9fdf1390deb2)

Likely related people:

  • Mitchell Etzel: Raw commit f7b61f0 adds src/snapshot/database-backup.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f7b61f049a5c; files: src/snapshot/database-backup.ts)
  • Peter Steinberger: Raw commit b0ab440 adds src/snapshot/database-backup.ts:334 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b0ab44081ef4; files: src/snapshot/database-backup.ts)

PR surface

Source +8, Tests +76, Docs +7. Total +91 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 1 77 1 +76
Docs 4 17 10 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 103 12 +91

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Scheduled PostgreSQL Git backups currently fail or retain stale agent history, affecting a bounded database-engine workflow.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Scheduled PostgreSQL Git backups currently fail or retain stale agent history, affecting a bounded database-engine workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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.

Reviewed November 19, 2026, 9:16 AM ET / 14:16 UTC.

@VACInc
VACInc merged commit 67796a6 into openclaw:main Nov 20, 2026
226 checks passed
@VACInc

VACInc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

@VACInc
VACInc deleted the fix/online-postgres-git-backups branch November 20, 2026 17:23
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
Co-authored-by: VACInc <[email protected]>
(cherry picked from commit 67796a6)

Gap-sweep intake (Dallin, 2026-11-24): ledger-high/P0-P1 fix not yet on 2026.11.10. Clean apply. Later main mentions of #201870: none.

Co-authored-by: RomneyDa <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…law#194384)

* docs: clarify PostgreSQL conformance coverage

* fix(cron): keep one-shot finalization working on PostgreSQL 16

* test(database): reuse cron conformance for JSON conversion regression

* test(postgres): accept fractional explain row counts

(cherry picked from commit 7ab0143)

Release adaptation: Only engine-owned jsonValue and retained cron enabled JSON replacement; preserve native boolean type with PG16 explicit ::json and SQLite json(). Omit unrelated PG docs/EXPLAIN test edits; retained one-shot enabled-transition caller present on baseline.

Follow-up dispositions: e029e18 docs: document isolated PostgreSQL restore drills (openclaw#202704); 49f0740 fix(database): report disabled memory after a port (openclaw#202630); a80b564 fix: keep database workers healthy after silent connection loss (openclaw#201856); 3d91af2 fix(config): reject reserved PostgreSQL schema prefixes (openclaw#202097); 835d722 fix: catch incompatible ownership before porting to SQLite (openclaw#202101); 67796a6 fix: keep scheduled Git backups current on PostgreSQL (openclaw#201870); cc849dd fix: recover lease heartbeats after a PostgreSQL connection loss (openclaw#201858); 6594caf fix: prepare macOS runtime pins without the PostgreSQL secret (openclaw#202102); 6ca56cd docs: clarify PostgreSQL storage and backup coverage (openclaw#202086); a079190 fix(postgres): chat history slows under concurrent reads (openclaw#190129); 2ff4256 feat(database): keep PostgreSQL rollback captures in PostgreSQL (openclaw#196236); 96c685b feat(backup): restore PostgreSQL stores into a staging database for restore drills (openclaw#194808); fb83d65 fix: reduce transcript allocation when preparing native context seeds; 71ec4d2 fix(config): keep Workboard PostgreSQL upgrades readable (openclaw#194648); b6ed907 perf(sessions): persist active transcript facts for hydration (openclaw#193682)

Validation: Baseline cron generated json(bound text) on PostgreSQL where json(text) is unavailable; helper and focused boolean regression retained. Exact PostgreSQL16 server proof unavailable; focused SQLite/helper tests queued. diff check passed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 38fdd9b52704d588d9ca24ef8e391d644961c985)
(cherry picked from commit fb935e6912388314851b05cb698ef038b83bbd07)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant