Skip to content

fix(restore): refuse newer-schema snapshots before swapping live data - #5649

Merged
thedotmack merged 4 commits into
thedotmack:mainfrom
Afloat16:afloat/20261110-restore-schema-preflight
Nov 9, 2026
Merged

thedotmack merged 4 commits into
thedotmack:mainfrom
Afloat16:afloat/20261110-restore-schema-preflight

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

A snapshot can pass SQLite quick_check while carrying a schema newer than the installed binary understands. Restore currently installs that snapshot over a healthy database and reports success; the subsequent writer guard then refuses startup.

Pass the binary's existing LATEST_SCHEMA_VERSION into the staging standalone job. Read the staged database's actual user_version, including committed WAL state, and reject a newer stamp before the live database is checkpointed, backed up, or replaced. The error tells the caller to upgrade before restoring. Unstamped, older, and current-schema snapshots retain their existing restore behavior.

Validation

  • Regression tests fail against the unchanged upstream implementation and pass with this correction.
  • The focused native Bun test selection, root and viewer TypeScript checks, and the complete production build pass.
  • Runtime artifacts are generated and compared against a baseline built with the same dependencies; only artifacts changed by this correction are included.
  • Native verification; final branch head: e6ff561f85377dc3b0dd3f1c731aeb74514ac075.

@thedotmack
thedotmack merged commit c141e54 into thedotmack:main Nov 9, 2026
13 of 16 checks passed
@thedotmack

Copy link
Copy Markdown
Owner

Merged, thank you @Afloat16! A restore now refuses a snapshot written by a newer schema before it touches anything, so the healthy live database stays in place instead of being swapped for one this version can't open. The WAL-only newer-stamp case was a sharp edge to cover. I merged main and dropped the generated bundles.

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.

2 participants