Skip to content

Handle defensive ALTER TABLE defects in migrations#488

Merged
BunsDev merged 1 commit intoOpenKnots:mainfrom
jbrahy:fix/migrations-catch-sqlite-duplicate-column
Apr 21, 2026
Merged

Handle defensive ALTER TABLE defects in migrations#488
BunsDev merged 1 commit intoOpenKnots:mainfrom
jbrahy:fix/migrations-catch-sqlite-duplicate-column

Conversation

@jbrahy
Copy link
Copy Markdown
Contributor

@jbrahy jbrahy commented Apr 21, 2026

Summary

  • bun dev crashes on first run on a fresh machine: migration 27 errors with SQLiteError: duplicate column name: default_model_selection and turbo exits non-zero, so the server never comes up.
  • Migrations 020, 025, and 027 try to swallow "column already exists" errors on their defensive ALTER TABLE ... ADD COLUMN calls via .pipe(Effect.catch(() => Effect.void)), but @effect/sql-sqlite-bun throws the underlying SQLiteError from db.query(sql) before its internal try/catch (see node_modules/@effect/sql-sqlite-bun/dist/SqliteClient.js:47), so it surfaces as an Effect defect, not a failure. Effect.catch only handles failures, so the error escapes. On a fresh DB, migration 25 adds default_model_selection, then migration 27 re-adds it and crashes.
  • Swap Effect.catch for Effect.catchCause in the four migrations using that pattern so both failures and defects are absorbed, which restores the intended "idempotent on replay" behavior.

Test plan

  • Delete ~/.okcode/dev/state.sqlite* and run bun dev — server now migrates cleanly, web comes up at http://localhost:5733/, bootstrap thread/project created, WS welcome fires.
  • bun run fmt:check, bun run lint, bun --filter okcodes typecheck all pass.

The defensive ADD COLUMN statements in migrations 020, 025, and 027
use Effect.catch to swallow "duplicate column" errors on re-runs, but
@effect/sql-sqlite-bun throws from db.query() outside its try/catch,
so the SQLiteError surfaces as an Effect defect rather than a failure.
Effect.catch only handles failures, so migration 27 crashed on fresh
databases because migration 25 had already added default_model_selection.

Switch to Effect.catchCause so both failures and defects are absorbed.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 21, 2026

@jbrahy is attempting to deploy a commit to the 0xBuns Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added size:S vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 21, 2026
@jbrahy
Copy link
Copy Markdown
Contributor Author

jbrahy commented Apr 21, 2026

hey @BunsDev how do I get this commited? I couldn't install the latest without fixing this bug

@BunsDev BunsDev merged commit d2529b5 into OpenKnots:main Apr 21, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants