Skip to content

fix(db): guard duplicate directories migrations — drift self-heals instead of boot crash-loop - #272

Merged
aarontrowbridge merged 3 commits into
local/amicodefrom
fix/270-idempotent-directory-migrations
Aug 31, 2026
Merged

fix(db): guard duplicate directories migrations — drift self-heals instead of boot crash-loop#272
aarontrowbridge merged 3 commits into
local/amicodefrom
fix/270-idempotent-directory-migrations

Conversation

@aarontrowbridge

Copy link
Copy Markdown
Member

Closes #270

Root cause (from a live hub incident, 2026-08-30)

normal_stryfe (d088a74) re-adds session.directories, which PR #215's 20260820000001_add_session_directories had already added. Databases bootstrapped by a #215-era binary carry the column + the old journal row but not the new one — so every binary whose migration list includes normal_stryfe exits ~1s into boot on such databases. Under Restart=always that is a hub crash-loop. The erlich hub survived only because its running binary predates the duplicate; the next routine upgrade would have bricked it.

Verified against a consistent snapshot of the production DB with an isolated XDG_DATA_HOME harness:

DB state before after
column + old row, normal_stryfe pending crash duplicate column name: directories boots, journal reconciles 40 → 41
column, both rows removed crash boots, both rows re-recorded (self-heal)
fresh DB boots (41 rows) boots (41 rows) — unchanged

The fix

Both directories migrations get a column-existence guard (PRAGMA table_info) before their ADD COLUMN; the runner records the journal row either way, so journal-vs-schema drift self-heals on next boot instead of crash-looping.

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cb299340-5dce-4b6a-b589-bd2a3fe12425


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…270)

A production database can carry the directories column without the journal
row (observed on the erlich hub after a binary-lineage change), and the
runner can then replay this migration at boot — the unguarded ADD COLUMN
crash-looped the hub (exit ~1s, 29 systemd restarts). With the guard the
migration no-ops on drift and the journal self-heals: the runner records
the row either way.
… drifted DBs (#270)

normal_stryfe (d088a74) re-adds session.directories, which PR #215's
20260820000001 already added. Databases bootstrapped by a #215-era binary
have the column and the OLD journal row but not this one, so every binary
carrying this migration exits ~1s at boot on them (crash-loop under
Restart=always). Guard with a column-existence check; the journal row is
recorded either way, reconciling the drift.
…e skew

The default branch's committed generated/types.ts is stale vs its own
sources (a question-options default field never made it into the generated
file), so the unit lane's check:generated step fails on ANY PR against it —
observed on #272 where the only changes are two migration guards. Regenerated
with the repo's own bun run generate; no source changes.
@aarontrowbridge
aarontrowbridge merged commit d35b857 into local/amicode Aug 31, 2026
3 checks passed
@aarontrowbridge
aarontrowbridge deleted the fix/270-idempotent-directory-migrations branch August 31, 2026 00:41
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.

fix(db): make directories migrations idempotent — journal-vs-schema drift boot-crashes the hub

1 participant