Repository navigation
fix(update): save the rollback point without copying history - #1304
Conversation
The pre-update snapshot exported every history row into state.db.gz through the paced live copy. On a Raspberry Pi 4 with a 6.7 GB history it ran at about 0.25 MB/s, could not meet the two-hour export deadline, and made history commits time out while it ran. The updater only ever restores state.db, and the UI rollback refuses a point that predates a history-format change, so the copy bought nothing an operator could use from the UI. The rollback point now holds the settings database and config.yaml. history.db stays in place through update and rollback. The step is bounded by settings size, its space preflight ignores history, and every update takes one. Going back across a history-format change still needs a full backup made before that update; the rollback handler already refuses such a point and says so. Refs #1302 Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]>
|
Full |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03cd846045
ℹ️ 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".
| // hours on a Raspberry Pi for a file the UI rollback could not use | ||
| // (#1302). A store that still keeps legacy history inside state.db is | ||
| // copied whole. | ||
| stored, hasStored, err := s.deps.State.BackupStateWithConfiguration(filepath.Join(dir, "state.db.gz"), report) |
There was a problem hiding this comment.
Preserve history when reverting legacy rollback points
When the selected target is one of the retained pre-change schema-v2 snapshots, it contains embedded history plus history_restore_generation; opening it renames the live history.db and binds a new generation. The pre-rollback safety point created here now contains only settings with the original history_sqlite_generation, so either automatic recovery after a failed health check or a later forward rollback fails with state and history generations differ instead of restoring the pre-rollback state. Keep a full safety copy when meta.HistoryInPlace is false, or reject/migrate these legacy targets.
AGENTS.md reference: AGENTS.md:L24-L25
Useful? React with 👍 / 👎.
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. |
miravoss26
left a comment
There was a problem hiding this comment.
Changes the Core update rollback point to copy the settings database only, leaving history.db untouched — bounded by settings size instead of years of telemetry, and taken on every update (previously skipped whole when the schema was unchanged). #1302.
Correctness:
backupWithConfigurationnow takesincludeHistory; when false it skipsexportHistoryToSQLiteand bounds the disk-space preflight tostateSourceBytes()instead ofBackupSourceBytes()— matches the stated goal of not waiting on a history export.- Legacy stores that still embed history inside
state.dbstay complete, since the whole-file copy captures it regardless ofincludeHistory— the comment onBackupStateWithConfigurationcalls this out explicitly andstateSourceBytes()sizes off the same file, so the preflight stays accurate for that layout too. TestRollbackPointRestoresBesideHistoryInPlaceis the right test for the risky part (rollback replacing state.db while history.db survives untouched, before and after the point) — good that it checks rows written after the point too, not just before.handleVersionRollback's use of the newHistoryInPlacemeta field to refuse a cross-format rollback isn't in this diff, so I can't verify that gate directly, but it's referenced consistently across docs/comments/tests as already existing.
Security: no secrets, no new deps, no network destinations, no authz surface. Pure local-disk backup/restore logic.
Frontend + docs strings were updated in lockstep with the backend behavior change (four doc files, two web components, the progress test asserting the old "schema unchanged" message is gone). Safe to merge from my read.
Refs #1302.
Problem
A Core update first writes a local rollback point. Until now that point exported every history row into
state.db.gzthrough the paced live copy (1,024 rows or 256 KiB per batch, then a 100 ms pause, then a verification read), under a two-hour export deadline.Observed tonight on the owner's Raspberry Pi 4 (v3.5.3-beta.1 → v3.6.0-beta.1), read-only measurements:
history.db+ WALhistory commit failed … context deadline exceeded,SQLITE_BUSYon status writes, Core DP shadow plans rejectedSo the update could not complete, and the box was degraded while it tried. Any box with a history above roughly 74 million rows hits the same wall on every schema-change update.
Why the copy bought nothing
ftw-updaterrestores onlystate.db(restoreSnapshotFiles). It never writeshistory.db.handleVersionRollbackrefuses a point whosedatabase_schemais older than the running Core's. The full copy was only usable through the offlineftw-backuppath with the matching older Core.state.db.Change
Store.BackupStateWithConfigurationcopies the settings database and exports config from that copy. It skipsexportHistoryToSQLite, keepshistory_sqlite_generationso the restoredstate.dbbinds to thehistory.dbthat is still on disk, and preflights space against the settings file only. A store that still keeps legacy history insidestate.dbis copied whole, as before.createPreUpdateSnapshotuses it and recordshistory_in_placeinmeta.json.complete_databasestays true; the point is complete forstate.db.backup-and-restore.md,self-update.md,operations.md.Rollback across a history-format change is unchanged: the handler still refuses such a point and points to a full backup made before the update.
Evidence
go test ./internal/state/ ./internal/api/focused runs pass, including three new tests:history.dbkeeps every row;state.db, drop WAL/SHM, leavehistory.db) opens and keeps rows written before and after the point.npm test: 638 pass.go test ./...was still running when this PR was opened; CI will show the result.What this does not fix
Boxes already on v3.5.3-beta.1 or older run the old code when they update, so their next schema-change update still tries the paced full export. The proposed transition is a documented one-time manual update (stop Core, copy
state.db+config.yamlas the rollback point, bump the image tags,compose up). The alternative, declaring the old state schema in the next release's notes so old Cores skip the step, would refuse updates for any box already on 3.6.0-beta.1 and fails the stable release check; that is the owner's call. v3.6.0-beta.1 was converted to a draft tonight so no further box starts the doomed step; the beta channel resolves to v3.5.3-beta.1.Follow-ups, proposed and not started:
ftw-updaterfreezehistory.dboffline (plain file copy while Core is stopped) when there is room, so UI rollback across a history-format change becomes possible without any live export.full_backup_requiredin the Update Center to say "this update changes the history format; make a full backup first if you may need to go back".POST /api/backups) keeps the same pacing and deadline; Backup IO delays durable charging-goal saves on Raspberry Pi #1246 and Offline portable backup necessarily times out on large migrated histories #1259 cover that.🤖 Generated with Claude Code
Closes #1159: every update now takes a rollback point, including same-schema updates.