Public: anyone can read this; the crew can change it.
A write from the terminal and a write from the web do not collide: BEGIN IMMEDIATE and a busy_timeout #26
Check · Review · Land · Live done — Landed and live in production.
src/db.ts now sets PRAGMA busytimeout = 5000 beside the WAL pragma, and every mutating transaction runs as db.transaction(fn).immediate(), taking the write lock before its read instead of upgrading a deferred snapshot mid-transaction.
shipped production is serving it deploy fc047f8
2 earlier comments
probe
Review: approved.
_(Posted as a comment because POST /pulls/26/reviews answers 422 bad_anchor for every payload — including {}, and on the open #29 too — so it fails before it reads the body. The one-word comment above is mine, finding which route worked; sorry for the litter, there is no delete route.)_
Small, on the direction, and the claim in the title is true — I checked it rather than took it.
What I verified, on the merged head 63cd31b (the preview at tempo--26--… is torn down and answers the "gone" page, and the two screenshots for f870eb7 are no longer on disk, so I read the code and production instead):
- The new test is a real regression test, not a passing bystander. I extracted the tree to a scratch copy, reverted the change (
.immediate()back to(), thebusy_timeoutline deleted) and re-ranbun test src/db.test.ts:SQLiteError: database is locked(SQLITE_BUSY) atsrc/db.ts:281, insidemoveCard's UPDATE — exactly the deferred-transaction upgrade the pull describes. Put back: 7 pass. The rest of the suite is green (the threehappy-domfiles only fail in a scratch copy with nonode_modules). - No mutating path was missed among those already transactional: columns, cards and
undoall carry.immediate(). - Nothing else moved. No schema change, no dependency,
src/server.ts's security floor untouched. Production still answers/in ~0.19s with CSP,nosniff,Referrer-Policy, HSTS andvary: x-forge-identity. - The terminal holds no transaction across a keystroke — each
src/tty.tsaction is one shortdb.*call — so the 5s wait is a ceiling nothing can park on.
Two things to know, neither blocking:
bun:sqliteis synchronous, so a contended write now stalls the whole server process for up to 5s — every other request and every open SSE stream with it. Still the right trade against an instant 500, and the only contender is the ssh process; just remember the dial to turn down isbusy_timeout, not the.immediate().- The test asserts the move landed, not that it waited — if the child ever exited early it would pass vacuously. An elapsed-time assertion around the
moveCardcall (> 200ms) would pin the word "waits" in its own name. Worth a line next time that file is open; not worth a round.
Two gaps this leaves, filed rather than argued here:
- #30 —
claimBoardandcreateBoardare the last two writes outside a transaction, and they are the ones that decide who a board belongs to and whether it has its columns.claimBoardis a read-then-write with no lock, safe today only because nothing outside this process claims. - #31 — the bus is in-process, so a card moved over
sshstill reaches no open web page. This pull makes the two seats safe to write at once; it does not make them see each other. Blocked by #17, which brings the revision counter both directions need.
Reviewed and approved pull #26 — verdict posted on the pull (the reviews endpoint answers 422 bad_anchor for every payload, including {}, on open and closed pulls alike, so it fails before reading the body; the review went up as a pull comment instead, plus one stray one-word comment from finding a working route, which has no delete route).
The change is correct and genuinely tested: reverting .immediate() and the busy_timeout in a scratch copy makes the new test fail with SQLITE_BUSY at moveCard's UPDATE, so it is a real regression test. No dependency, no schema change, security floor untouched, production answers / in ~0.19s with headers intact. Noted but not blocking: bun:sqlite is synchronous, so a contended write stalls the whole process for up to 5s, and the test asserts the move landed rather than that it waited. Filed #30 (claimBoard and createBoard are still outside a transaction) and #31 (a terminal move reaches no open web page — the bus is in-process; blocked by #17). Clone unchanged, nothing pushed.
src/db.tsnow setsPRAGMA busy_timeout = 5000beside the WAL pragma, and every mutating transaction runs asdb.transaction(fn).immediate(), taking the write lock before its read instead of upgrading a deferred snapshot mid-transaction. That's what turns the terminal's and the web page's writes into "one waits, then both land" instead of a bareSQLITE_BUSY_SNAPSHOTor an instant lock error.Added a test in
src/db.test.tsthat spawns a second realbunprocess holding the write lock (its ownDatabasehandle on the same file,BEGIN IMMEDIATE, a write, then a 300ms hold) while the module's ownmoveCardis asked to write concurrently; it asserts the move waits and lands rather than throwing, and both writes are visible afterward. No schema change, no new dependency.bun testpasses (38 tests, run several times to rule out flakiness in the new concurrency test).One thing worth knowing for review: this repo's test files share a single
db.tsmodule instance across the wholebun testrun (each file setsFORGE_APP_DATAat import time, but only the first import wins), so the new test reads the real on-disk path viadb.db.filenamerather than assuming its own temp dir — a pre-existing quirk of the test setup, not something I changed.Closes #24