Skip to content

feat(store): never lose the database on a schema upgrade - #41

Merged
lgalabru merged 4 commits into
mainfrom
feat/store-upgrade-safety
Nov 25, 2026
Merged

lgalabru merged 4 commits into
mainfrom
feat/store-upgrade-safety

Conversation

@lgalabru

@lgalabru lgalabru commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

TL;DR

A branch build (rex-native, schema v12) upgraded the shared ~/.axel/axel.db; main (v10) then refused it, the database got deleted to "fix" it, and every thread in flight was lost. It was recovered from processes that still held it open. Store::open now copies a database aside before upgrading it, refuses newer or other-branch databases untouched with a message that says not to delete them, fingerprints migrations, runs each one under an IMMEDIATE lock, and won't adopt a deleted database's -wal/-shm.

Also adopts rex-native's migrations 11 and 12 verbatim (tables only) so main opens the recovered v12 database, plus ADR 0011 and RFD 0004 (linked devices, from #40). Upgrades now cost one VACUUM INTO copy; the newest two are kept.

Agent Trajectory

  • Asked to fix "a bunch of sqlite errors" after a regression. axel doctor worked, but axel.db had been recreated at 16:49 with every migration stamped at the same second. lsof showed 14 axel processes still holding the deleted 301 MB file and its never-checkpointed 13 MB WAL, and sharing the old -shm with the new empty database, which caused the errors.
  • Recovered the data by copying the open file descriptors out of a running process with lldb (fcopyfile), checked it (integrity_check ok, 15,643 events, 75 threads), and restored it. The installed v10 binary couldn't open it: rex-native had migrated it to v12.
  • Then asked to make sure a schema upgrade never does this again, with tests. The safeguards target each step of that incident: a copy to go back to, an error that names it, detection of two branches' "migration 11", and never mixing sidecar files.
  • The new concurrency test failed on the first version: two openers in one process shared a backup temp name (pid only), and VACUUM INTO refuses a non-empty file. Temp names are now unique per attempt.
  • For v12 the owner chose to port rex-native's two migrations rather than downgrade the database (which would drop 751 inspector rows) or run the branch build.
  • cargo test -p axel-store: 61 passed. Two tests elsewhere (acp host, config remote) fail locally on main as well: the 1Password commit signer errors inside their own git commit.

Opening the database now protects it before changing it:

- copy it to axel.db.v<N>.bak (VACUUM INTO) before migrating from v<N>,
  keeping the newest two; a failed copy stops the upgrade
- refuse a newer database untouched, with a message that says to install
  the newer build, not to delete the database, and where the pre-upgrade
  copy is
- record a fingerprint of each migration's SQL and refuse, untouched, a
  database whose migration N came from another branch (SchemaDiverged)
- apply each migration in its own IMMEDIATE transaction, re-reading the
  version under the lock, so concurrent opens run each step once
- rename a -wal/-shm left behind by a deleted database instead of letting
  the new database adopt it
The rex-native build migrated the owner's database to v12 (model_requests,
inspected_threads, model_requests.throttled), and main refused it. Copy both
migrations verbatim so main opens that database, nothing has to be dropped,
and the numbering and fingerprints match when rex-native merges. Only the
tables come over; the inspector proxy stays on its branch.
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
axel Ready Ready Preview Nov 25, 2026 3:46am UTC

@lgalabru
lgalabru merged commit e6fed31 into main Nov 25, 2026
4 checks passed
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.

1 participant