Skip to content

fix: avoid repeated decompression when verifying backups - #188518

Merged
steipete merged 1 commit into
mainfrom
pgprep/pgbackupverify
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
pgprep/pgbackupverify

Conversation

@steipete

@steipete steipete commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Refs #183094

Thanks @etzelm for the large-install timing report.

What Problem This Solves

Verifying a mixed SQLite/PostgreSQL backup repeatedly decompresses the entire archive: once to inventory it, again for PostgreSQL artifacts, and again for SQLite snapshots (with possible extra legacy discovery passes).

User Impact

Normal verification now decompresses once, including backup create --verify, while preserving the archive format, compression defaults, and existing corruption checks. Older and newer builds continue to read each other's archives. Temporary disk pressure can still use the existing filtered extraction fallback.

Why This Change Was Made

The inventory reader retains possible database artifacts in private scratch as they stream past, then the existing verifiers consume the selected files after manifest and ownership validation. This handles trailing manifests and databases discovered from an archived registry without replaying gzip. Files are moved, not hard-linked, so PostgreSQL artifact admission keeps its single-link requirement.

The change retains path/link validation, manifest and inventory checks, PostgreSQL manifest hashes/anchors/identities, SQLite shape/integrity/role/ownership checks, sidecar rejection, extraction limits, and cleanup. It consolidates the two extraction lifecycles around one archive spool; the necessary production growth supports arbitrary entry ordering and storage-pressure fallback.

Evidence

Measurements use baseline b19c8c7ccc915b55d3a2d90fbbd03c7e1e6f41b2, Apple M3 Ultra / 512 GiB RAM, Homebrew PostgreSQL 17.11, and the same isolated fixture: 6,727,835,648 bytes across three SQLite agent stores (4.307 / 1.077 / 0.539 GB) and 12,288 workspace files (805 MB), plus a real PostgreSQL Workboard store. Run order was baseline 1, candidate 1, baseline 2, candidate 2, each with real CLI create and standalone verify.

Standalone verification averaged 22.96 → 21.84 s wall and 30.09 → 16.86 s CPU. Verification within create averaged 21.21 → 13.23 s wall. Each normal mixed verification reads 3 → 1 complete compressed streams (about 6.92 → 2.31 GB). These are two-pair observations, not a general latency guarantee: host load varied and the first standalone candidate wall sample regressed. The unchanged capture and gzip phases varied substantially too; do not attribute the whole-command timing difference to this patch. SQLite capture still dominates the complete command, so this PR references rather than closes the issue.

The reusable fixture and phase instrumentation are in scripts/perf/backup-verify-*; only disposable QA runtimes were instrumented. Production code has no instrumentation.

Per-phase measurements (two interleaved pairs)

Each cell is wall seconds / CPU seconds / physical bytes read. CPU includes the Node process and exited child processes; it excludes the separately running PostgreSQL server. Physical bytes come from macOS proc_pid_rusage for the CLI process only, excluding child reads and cache hits. They are not logical bytes processed. Preparation is shown separately from its enclosing verifier. Capture includes private SQLite copies, their required checks, and the small PostgreSQL export.

Create + verify phase Baseline 1 Candidate 1 Baseline 2 Candidate 2
Database capture 202.506 / 135.974 / 5979246592 173.194 / 123.084 / 5969104896 194.928 / 140.015 / 5965443072 196.736 / 136.779 / 5979750400
Tar + gzip 78.577 / 96.338 / 811638784 115.562 / 109.386 / 811184128 86.513 / 103.360 / 811696128 85.170 / 105.928 / 811614208
Inventory (+ candidate spooling) 2.903 / 7.924 / 0 11.156 / 14.121 / 1761280 3.142 / 8.673 / 0 12.583 / 13.896 / 2281472
PostgreSQL artifact preparation 2.871 / 7.953 / 0 0.010 / 0.006 / 0 3.613 / 9.084 / 4096 0.009 / 0.005 / 0
PostgreSQL checks 0.074 / 0.064 / 4096 0.039 / 0.029 / 4096 0.041 / 0.043 / 45056 0.028 / 0.036 / 28672
SQLite artifact preparation 15.310 / 10.138 / 1101824 0.010 / 0.006 / 0 11.925 / 11.864 / 1167360 0.008 / 0.005 / 0
SQLite checks 1.206 / 1.264 / 1560576 1.324 / 1.308 / 159744 1.338 / 1.374 / 1683456 1.284 / 1.258 / 253952
Other CLI work (remainder) 4.614 / 4.604 / 49156096 4.765 / 5.020 / 30326784 5.440 / 5.448 / 40235008 5.751 / 5.503 / 55775232
Whole CLI 308.060 / 264.260 / 6842707968 306.060 / 252.960 / 6812540928 306.940 / 279.860 / 6820274176 301.570 / 263.410 / 6849703936

Baseline inventory, PostgreSQL preparation, and SQLite preparation each decompress the entire archive. Candidate inventory is the single decompression pass; preparation only moves retained artifacts in this workload. Required hash, identity, integrity, and ownership reads still run. Snapshot reporting uses the completion-bound aggregate; dispatch-only helper timings are excluded. The remainder covers startup, manifest validation, publication, cleanup and outcome recording outside the named phases.

Standalone verify Baseline 1 Candidate 1 Baseline 2 Candidate 2
Whole CLI: wall / CPU / physical read B 20.830 / 28.410 / 2337136640 26.750 / 16.860 / 2328117248 25.080 / 31.770 / 2336133120 16.920 / 16.860 / 2876035072
Full compressed input reads, bytes 6920651277 2306883759 6920651277 2306883759
Inventory (+ candidate spooling) 3.093 / 7.035 / 2306887680 22.929 / 13.373 / 2309709824 3.645 / 8.409 / 2306904064 11.125 / 12.746 / 2306924544
PostgreSQL artifact preparation 3.868 / 7.246 / 20480 0.009 / 0.006 / 0 4.717 / 8.022 / 0 0.010 / 0.006 / 0
PostgreSQL checks 0.079 / 0.104 / 1236992 0.084 / 0.046 / 1232896 0.088 / 0.116 / 1232896 0.078 / 0.048 / 1241088
SQLite artifact preparation 10.381 / 10.900 / 20480 0.013 / 0.009 / 0 11.218 / 11.089 / 221184 0.008 / 0.005 / 0
SQLite checks 1.231 / 1.280 / 1507328 1.389 / 1.333 / 1503232 1.471 / 1.415 / 114688 2.960 / 1.787 / 540405760
Other CLI work (remainder) 2.177 / 1.844 / 27463680 2.326 / 2.093 / 15671296 3.941 / 2.718 / 27660288 2.739 / 2.267 / 27463680

The standalone runs all verify the same baseline archive (2,306,883,759 bytes). Create outputs differ only slightly in time-dependent metadata (2,306,863,045–2,306,910,097 bytes). No manual cache flush was used. Initial phase load averages ranged from roughly 22 to 42; the slower candidate-1 standalone sample is retained. Whole create --verify wall was 308.06 / 306.06 / 306.94 / 301.57 seconds in run order.

Commands:

node --import ./scripts/tsx.mjs scripts/build-all.mts qaRuntime
node scripts/perf/backup-verify-measure.mjs instrument dist
# Isolated HOME/state/config/cache and task-only PostgreSQL DSN for each CLI:
BACKUP_MEASUREMENT=<create.jsonl> BACKUP_MEASURE_RUSAGE=<rusage> /usr/bin/time -l node --import ./scripts/perf/backup-verify-measure.mjs openclaw.mjs backup create --verify --output <archive> --json
BACKUP_MEASUREMENT=<verify.jsonl> BACKUP_MEASURE_RUSAGE=<rusage> /usr/bin/time -l node --import ./scripts/perf/backup-verify-measure.mjs openclaw.mjs backup verify <baseline-archive> --json

Restore and version compatibility

The candidate verifies the baseline archive. The pinned baseline QA runtime successfully restored the final candidate archive through node openclaw.mjs backup restore <candidate-archive> --target <fresh-target> --json, proving the reverse direction too.

The restored main/worker/research stores contained 4,096 / 1,024 / 512 rows with all 5,905,580,032 payload bytes equal to the deterministic fixture, correct IDs and agent identities, and zero mismatches. All 12,288 workspace files (805,306,368 bytes) matched. All 18 PostgreSQL Workboard tables matched, including the card and event; recovery used a fresh namespace with the same store identity, preserved the original namespace and anchor, and retained SQLite-default / PostgreSQL-Workboard engine selections.

Compression proposal only

A separate single run per level compressed the same 6,736,439,296-byte raw tar input after the A/B campaign. These times include file I/O and gzip, excluding database capture and tar traversal; the input was cached. No production compression setting changed.

gzip level Wall s CPU s Output bytes Physical read bytes
1 68.868 72.871 2319955272 729088
6 (current default) 73.816 79.462 2306883759 1511424
9 84.106 91.505 2304163434 327680

Level 1 is a possible follow-up decision: on this fixture it saved 6.7% wall / 8.3% CPU for 0.57% more bytes. Level 9 cost 13.9% more wall time for only 0.12% fewer bytes. These fixture-specific results do not justify silently changing the default.

Checks

  • Six focused files: 88 passed, one Windows-only long-path test skipped. Existing corruption cases stayed green. Added coverage rejects truncated gzip, modified SQLite, modified PostgreSQL artifacts, and manifest mismatch while asserting one tar.t and no tar.x. It also covers first/last manifests, extensionless registry-discovered databases, and storage-pressure fallback.
  • The mixed-archive single-pass assertion is red on baseline: one inventory pass plus two extraction passes; green with this change.
  • Core and command-test TypeScript checks, focused lint/format, test-line allocation, git diff --check, and QA runtime build passed.
  • pr-simplify completed. Isolated local autoreview reported no actionable P0–P2 findings.
node scripts/run-vitest.mjs src/commands/backup-verify.test.ts src/commands/backup-verify-completeness.test.ts src/commands/backup-verify.utf8.test.ts src/commands/backup-verify-manifest.update-recovery.test.ts src/commands/backup.create-verify.test.ts src/commands/backup-mixed-engines.test.ts --maxWorkers=1
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.commands.json --incremental
node scripts/run-oxlint.mjs --tsconfig tsconfig.json src/commands/backup-verify.ts src/commands/backup-verify-manifest.ts src/commands/backup-verify-spool.ts src/commands/backup-verify.test.ts src/commands/backup-verify-completeness.test.ts scripts/perf/backup-verify-fixture.mjs scripts/perf/backup-verify-measure.mjs
node --import ./scripts/tsx.mjs scripts/check-test-lines-ratchet.mts

CI

CI run 41089727412 passed on exact head d70931581b57dde9179aadbfc458ef99fc34cd52, including openclaw/ci-gate and all three PostgreSQL conformance steps. None of the PostgreSQL steps was skipped. The original 15-minute observation expired while they were running; the subsequent bounded landing observation confirmed completion. No workflow was manually dispatched or rerun.

Preserve archive format and verification checks while retaining database artifacts during inventory. Reuse staged artifacts for PostgreSQL and SQLite verification, with bounded extraction fallback under temporary storage pressure.\n\nRefs #183094. Thanks @etzelm for the large-install report.
@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T16:27:51.968493Z d709315 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts commands Command implementations size: L labels Oct 30, 2026
@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: 🦐 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR retains database artifacts during archive inventory so verification normally decompresses a backup only once.

Example: Verify the supplied 2,306,883,759-byte archive containing SQLite and PostgreSQL stores.

  • Before: Verification reads three complete compressed streams, totaling 6,920,651,277 bytes.
  • After: Verification reads one compressed stream while retaining the existing database checks.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, proven verification optimization that addresses only part of the linked backup-performance request; two measurement pairs do not establish general latency gains.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied real CLI measurements exercise create-with-verification and standalone verification on isolated SQLite/PostgreSQL data, showing three compressed reads reduced to one; reverse-direction restore checks report preserved data and engine selections.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: Large verified backups repeatedly decompress the same archive, consuming additional CPU and extending backup work.
Reason: The maintainer-authored direction removes measured redundant work without changing compression defaults or archive contracts; broader capture costs remain outside this PR.

Merge readiness

✅ Ready for maintainer review

This PR provides a useful, focused backup optimization; this review found no actionable defects.

Priority: P2
Reviewed head: d70931581b57dde9179aadbfc458ef99fc34cd52

Before merge

None.

Findings

None.

Agent review details

How this fits together

The backup CLI passes compressed archives to the shared verifier, which validates inventory and ownership, prepares database artifacts, checks their integrity, and returns verification results or restore metadata.

flowchart TD
  A[Backup CLI] --> B[Archive inventory stream]
  B --> C[Private artifact spool]
  B --> D[Manifest and path validation]
  D --> E[Database artifact preparation]
  C --> E
  E --> F[Existing database verifiers]
  F --> G[Verification result]
Loading

Technical review

Best possible solution:

Retain database candidates during inventory and reuse the existing verifiers, preserving filtered extraction when temporary storage cannot retain them.

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

Current-main source establishes separate inventory, PostgreSQL, and SQLite compressed passes, corroborated by the supplied baseline CLI measurements; this read-only review did not rerun them.

Is this the best way to solve the issue?

The shared spool is a focused way to eliminate repeated decompression while supporting arbitrary entry ordering and retaining existing validation owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Manifest collection and inventory validation keeps the original intent (4bb27de: Collect the bounded manifest during inventory while preserving validation precedence and original path spelling.)
  • PostgreSQL artifact preparation keeps the original intent (b7bb85a: Verify producer-declared matched capsules, hashes, anchors, identities, and sidecar rejection before restoration.)
  • SQLite verification and extraction admission keeps the original intent (350bac4: Reject corrupt snapshots and bound temporary extraction while preserving database role and ownership checks.)
  • Opaque SQLite payloads and discovered owners keeps the original intent (b10035f: Keep unmanaged SQLite files opaque while verifying managed databases through their declared or archived ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b7bb85a adds src/commands/backup-verify.ts:337 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b7bb85afb9cb; files: src/commands/backup-verify.ts)
  • Vincent Koc: Raw commit 4bb27de adds src/commands/backup-verify-manifest.ts:638 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4bb27de320c9; files: src/commands/backup-verify-manifest.ts)

PR surface

Source +215, Tests +107, Docs +42, Other +170. Total +534 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 406 191 +215
Tests 2 143 36 +107
Docs 3 42 0 +42
Config 0 0 0 0
Generated 0 0 0 0
Other 4 170 0 +170
Total 12 761 227 +534

Root-cause cluster

Relationship: partial_overlap
Canonical: #183094
Summary: This PR addresses the repeated-decompression portion of the broader large-backup performance request.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repeated archive decompression adds measurable CPU and I/O work to large verified backups without evidence of an urgent availability regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; 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 October 30, 2026, 12:40 PM ET / 16:40 UTC.

@steipete
steipete merged commit a1d51ce into main Oct 30, 2026
160 of 163 checks passed
@steipete
steipete deleted the pgprep/pgbackupverify branch October 30, 2026 16:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

roboclaw-bot added a commit that referenced this pull request Oct 31, 2026
## What Problem This Solves

Fixes backup verification hanging before restore when a PostgreSQL archive has a truncated gzip stream.

## User Impact

Damaged archives now fail promptly and close their temporary file handles. Archive verification keeps its existing single-pass behavior and corruption checks.

## Why This Change Was Made

The streamed verification introduced in #188518 could throw while canceling an entry without an error listener, leaving another consumer waiting with an open file handle. Cancel every active consumer without re-emitting the error, then stop reading if cancellation occurs during a file write. The existing corruption test also checks that all opened handles close.

## Evidence

- Reproduced the original truncated-archive case timing out at 120 seconds before the fix. It now rejects in 81 ms on pinned Bun and 69 ms on Node 24.22.1.
- Pinned Bun: 101 tests passed across seven focused backup and startup-recovery files; one existing Windows-only long-path test skipped. Node 24.22.1: all 31 completeness tests passed.
- Scoped TypeScript, lint, format, test-line and line-cap ratchets, and diff checks passed. No timeout, retry, skip, assertion weakening or baseline increase.
- Fresh independent canonical autoreview of the accepted two-file patch: P0–P2, complete, no actionable findings. pr-simplify completed. Published source is verified against that accepted patch.
- Linux proof covers archive verification and staging restore; the existing Windows-only case was not exercised. Exact-head PR CI supplies broader proof.

Requested by @steipete
## Work sessions

[Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/b5679712-7777-4ff7-a05a-81c1efab2069)

Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
Preserve archive format and verification checks while retaining database artifacts during inventory. Reuse staged artifacts for PostgreSQL and SQLite verification, with bounded extraction fallback under temporary storage pressure.\n\nRefs openclaw#183094. Thanks @etzelm for the large-install report.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…188948)

## What Problem This Solves

Fixes backup verification hanging before restore when a PostgreSQL archive has a truncated gzip stream.

## User Impact

Damaged archives now fail promptly and close their temporary file handles. Archive verification keeps its existing single-pass behavior and corruption checks.

## Why This Change Was Made

The streamed verification introduced in openclaw#188518 could throw while canceling an entry without an error listener, leaving another consumer waiting with an open file handle. Cancel every active consumer without re-emitting the error, then stop reading if cancellation occurs during a file write. The existing corruption test also checks that all opened handles close.

## Evidence

- Reproduced the original truncated-archive case timing out at 120 seconds before the fix. It now rejects in 81 ms on pinned Bun and 69 ms on Node 24.22.1.
- Pinned Bun: 101 tests passed across seven focused backup and startup-recovery files; one existing Windows-only long-path test skipped. Node 24.22.1: all 31 completeness tests passed.
- Scoped TypeScript, lint, format, test-line and line-cap ratchets, and diff checks passed. No timeout, retry, skip, assertion weakening or baseline increase.
- Fresh independent canonical autoreview of the accepted two-file patch: P0–P2, complete, no actionable findings. pr-simplify completed. Published source is verified against that accepted patch.
- Linux proof covers archive verification and staging restore; the existing Windows-only case was not exercised. Exact-head PR CI supplies broader proof.

Requested by @steipete
## Work sessions

[Discussion, implementation and verification](https://team.openclaw.ai/chat/roboclaw/~key/dashboard/b5679712-7777-4ff7-a05a-81c1efab2069)

Co-authored-by: steipete <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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