Skip to content

fix: let offline backups copy without live-work pacing - #1261

Merged
frahlg merged 2 commits into
masterfrom
fix/offline-backup-pacing-20260914
Sep 17, 2026
Merged

frahlg merged 2 commits into
masterfrom
fix/offline-backup-pacing-20260914

Conversation

@frahlg

@frahlg frahlg commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Large offline backups inherited a live-work pause and a two-hour timeout, so a sufficiently large history could never finish. The offline helper now skips that pause and deadline while preserving bounded copies and full verification. Live backups keep their existing pacing and durability.

Creation now reserves space for cold Parquet, other saved files, and all database copies that coexist during verification. Restore verifies on its writable target. Standalone verify/inspect prefer the archive filesystem and fall back to normal temporary storage when the source is read-only.

Closes #1259, #1285 and #1286.

Validation:

  • Full local PATH=/opt/homebrew/bin:$PATH make verify passes.
  • Offline create/verify/restore preserves a saved EV goal and 2,500 history points with normal temporary storage unavailable.
  • New regression verifies an archive in a non-writable directory, restores to a new directory and an existing mount, checks the saved goal and confirms scratch cleanup.
  • Space preflight includes cold history and other files before any database export. Failure leaves no partial backup. Separate tests check the maximum coexistence phase.
  • No UI changes; changesets and DCO sign-offs included.

The real large-dataset offline export and restore remain unproven. #1246 remains open: opt-in Pi IO tests still exceed the two-second durable-goal limit, including one longer control run without a backup. Journal/batch experiments did not establish a safe improvement and are not included. This PR does not claim that all live backup latency is fixed. See #1287 for the separate proposal to store less telemetry history.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T09:18:09.319011Z cee71ea 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cee71eaf82

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread go/internal/backup/archive.go Outdated
}
seen := make(map[string]bool, len(want))
tmpDir, err := os.MkdirTemp("", ".ftw-backup-verify-")
tmpDir, err := os.MkdirTemp(filepath.Dir(archivePath), ".ftw-backup-verify-")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve verification for read-only archive locations

When an archive is stored on a read-only USB mount or in a directory the invoking user cannot modify, creating this temporary directory fails even though the archive is readable and the restore destination is writable. Because both Inspect and RestoreContents call Verify, this also prevents inspecting or restoring such backups; use a caller-writable workspace or restrict same-filesystem staging to the creation path.

AGENTS.md reference: AGENTS.md:L24-L25

Useful? React with 👍 / 👎.

Comment thread go/internal/backup/archive.go Outdated
if err := os.MkdirAll(outputDir, 0o700); err != nil {
return Info{}, fmt.Errorf("backup: create output dir: %w", err)
}
if err := state.EnsureDiskSpace(outputDir, state.BackupArchiveScratch(opts.State.BackupSourceBytes(), 0)); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include non-database files in the space reservation

When dataDir contains substantial cold Parquet history or other persistent files, this preflight counts only the SQLite state/history files because extraBytes is always zero, while collectSources later adds those files to the archive. A target with room for three copies of a small database but not the cold archive therefore passes the promised refusal check and fills during creation; inventory and include the non-database source sizes before checking free space.

AGENTS.md reference: AGENTS.md:L24-L25

Useful? React with 👍 / 👎.

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. Fixes #1259: exportHistoryToSQLite always paused 100ms per 1,024 rows and ran under a hardcoded 2h context deadline, even for the read-only offline ftw-backup helper. At the reported 174,629,397-row scale that's 4h44m of pauses alone, so the export always blows the 2h deadline — confirmed with the actual row count in TestBackupArchiveScratchReservesRawGzipAndVerify, which is a nice touch (regression test asserts against the real number from the issue, not a synthetic one).

  • Fix: backupWorkContext()/backupCopyYield() branch on Store.offlineBackup (set by OpenBackupSource) — offline gets no deadline and no yield-pause; live Core backups keep both (100ms pause, 256KiB batches, 2h deadline), so the goal/session-write latency protection this pacing exists for is untouched.
  • Two related fixes bundled in, both justified by the PR body: Verify now extracts beside the archive instead of into process temp (too small for these files on some systems — the test even blocks TMPDIR/TMP/TEMP to prove it doesn't matter anymore), and Create preflights disk space (EnsureDiskSpace/BackupArchiveScratch) so a backup that can't fit raw+gzip+verify-extract fails fast instead of partway through. Probe errors (e.g. Windows) don't block — documented and tested (TestEnsureDiskSpaceSkipsUnknownProbe).
  • Tests: thorough — live-yields/offline-doesn't, deadline presence, disk-space accept/reject/skip-on-error, and a full offline create→verify→restore round-trip checking both a config value and 2,500 history rows survive. CI green across linux amd64/arm64, Windows config ACL, and the full Go suite.
  • Security screen: no secrets, no new deps, no new network destinations — pure local file I/O in backup/restore internals.
  • PR body is upfront about what's not proven yet (the actual 175M-row dataset, Pi-side FTW_STORAGE_ADMISSION=1, and #1246 live-backup-vs-goal-latency stays open) — scope is honest, not oversold.

Safe to merge from my read.

OpenBackupSource no longer inherits the live 100ms yield that made a
two-hour export deadline unreachable for large converted histories.
Live Core backups still pause between copy batches. Verification
extracts beside the archive, and create refuses to start without
room for the raw export, compressed file and extract.

Addresses #1259

Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg force-pushed the fix/offline-backup-pacing-20260914 branch from 9b9bdab to 4e9a899 Compare September 17, 2026 08:24
@frahlg
frahlg merged commit c48f3fb into master Sep 17, 2026
16 checks passed
@frahlg
frahlg deleted the fix/offline-backup-pacing-20260914 branch November 11, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offline portable backup necessarily times out on large migrated histories

2 participants