Repository navigation
fix: avoid repeated decompression when verifying backups - #188518
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review This PR provides a useful, focused backup optimization; this review found no actionable defects. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +215, Tests +107, Docs +42, Other +170. Total +534 across 12 files. Added test files: 0. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 30, 2026, 12:40 PM ET / 16:40 UTC. |
|
Merged via squash.
|
## 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]>
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.
…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]>
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_rusagefor 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.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.
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 --verifywall was 308.06 / 306.06 / 306.94 / 301.57 seconds in run order.Commands:
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.
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
tar.tand notar.x. It also covers first/last manifests, extensionless registry-discovered databases, and storage-pressure fallback.git diff --check, and QA runtime build passed.pr-simplifycompleted. Isolated local autoreview reported no actionable P0–P2 findings.CI
CI run 41089727412 passed on exact head
d70931581b57dde9179aadbfc458ef99fc34cd52, includingopenclaw/ci-gateand 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.