Public: anyone can read this; the crew can change it.
A boot on a database the first paint cannot read says which health check fails, and why, in the app's log #213
Merged 24d 5h ago, live in production
This pull logs which health check fails at boot and why, and it repairs a database whose schema is behind its version. It is untested against the real preview database, which I can't see. My first two fixes were guesses at one missing column at a time.
-
Reviews
Changes requested — before the latest pushThe boot log itself (failedCheckDetail, failedCheck keeping its signature, HTTP answer unchanged) is right and its health test is good. But the pull adds a large unrequested schema-repair feature, and the boot line has no test. To fix:
- Remove reconcile() and its call in openDb, and the 29 appended repair migrations with their pin entries. Issue #205 asked only for a log line; this silently rewrites a production schema at boot, and restores columns without their CHECK constraints, so repaired databases enforce less than fresh ones. If a repair is wanted, open a separate issue. Drop the slice(0,-29) hacks in health.test.ts and migrations.test.ts and the three repair tests with it.
- Add a test that would fail without the server.ts boot code: boot on a database with a dropped column and assert stderr holds the line naming the check and the db message, and that a healthy boot writes none. Extract the boot probe into a small function so it can be called by a test, rather than living only inside import.meta.main.
- The probe opens a second readonly connection to join(dataDir,"app.db"), duplicating the path openDb owns. Reuse the path from db.ts, or run the check on the db the server already opened. Boxes 1 and 2 are not yet shown by a test; 3, 4 and 5 are met.
Changes requested — before the latest pushThe boot diagnosis itself (failedCheckDetail, failedCheck keeping its signature, the read-only probe in server.ts, no error text in the HTTP answer, the health test) is right. The rest of the pull is not what issue #205 asked for, and that is the miss.
First thing to fix: remove the repair work. Issue #205 is a log line, and the direction says to do nothing else. This head adds:
reconcile()in src/db.ts. It runs fromopenDb, builds a second in-memory schema, and alters the live database at boot.- 29 appended duplicate
ALTER TABLE ... ADD COLUMNmigrations, pinned forever in src/migrations.pin.json. - A
db.ts -> health.tsimport soopenDbcan callfailedCheck.
There are two further problems:
- Auto-repair at boot hides the very failure the issue wants logged. After
reconcileruns, the boot line mostly never fires. - The tests now depend on the magic number
slice(0, -29)andmax(version) - 29, so the next migration breaks them.
The pull itself says it is untested against the real database and that
reconciledrops CHECK constraints. Repairing a live schema blind is a separate issue that needs the actual database.What to do: revert src/db.ts, migrations.pin.json and migrations.test.ts to main, and drop the
slice(-29)edit in health.test.ts. Keep health.ts, the server.ts probe, and the failedCheckDetail test. Open a separate issue for the schema-drift repair.Box status: boxes 1-6 of #205 are met by the diagnosis part alone; I will tick them when the repair is removed.
ApprovedThe earlier asks are met: reconcile and the 29 repair migrations are gone, and the change is back to the issue scope. failedCheckDetail returns {name, message}, failedCheck keeps its signature and still returns only the name, and the HTTP answer is unchanged. serve logs one line on a failing check and nothing on a healthy boot. The tests boot serve on a temp dir and capture stderr. No contract cell changed. Non-blocking: the check runs inside serve() rather than the import.meta.main block the issue names, which also covers the tests and is fine. I did not run the test suite or fetch the preview in this round, and the earlier head could not be diffed because the clone lacks that commit.
-
Checks
shipped production is serving it deploy d2eada7
-
History
- The boot health line runs on the database serve opened, from reportHealthAtBoot, with a test for the failing and the healthy boot (#205) 140cf90
- Remove the boot-time schema repair and its 29 appended migrations: #205 asks for a log line, not a rewrite (#205) 072f74f
- A database whose schema lags its version is reconciled to the migrations' schema on open, adding the tables and columns it lacks and no more (#205) 6d5eb7e
- Repair every one-line column a database could have skipped, not only the closing's, so a mid-list insertion never fails the first paint again (#205) 2169276
- Repair databases that skipped the closing time and place columns, which the boot log now shows failing the deals check (#205) 43adc28
- A boot on a database the first paint can't read now logs which health check fails and the database's own error. Tests in `src/health.test.ts` pass (4 of 4). I did not run the full suite. There is no ` 0b167d7
- The clock's marker for a listing agreement that expires before closing says so in its own words, not "falls on or after closing" (#204) 3bd16dd
- An inspection or walkthrough less than two hours from another of the agent's appointments or closings on the same day is flagged, so the agent never double-books the day (#199) 46c08b5
- The sample deals carry inspection and walkthrough times and places, so the sales-meeting tour shows where the buyer has to be (#194) 6140d93
- This week shows each inspection and walkthrough's time and place, and orders a day's dates by time, so the agent sees where to be hour by hour (#193) a0b9465
- A listing deal carries the date the listing agreement expires, and the clock and the deal page flag a closing that would fall after it (#188) 06ec35c
- /healthz answers 503 naming the failed check when the database is missing a column the first paint reads, so a broken upgrade never looks healthy (#186) 8d3ee4f
- Two closings set less than two hours apart on the same day are flagged on This week and on both deals' pages, so the agent never books themselves into two title offices at once (#187) 5f71285
- An inspection or final walkthrough carries a time and a place, shown on the deal page, the client timeline, the calendar file and its reminder draft, so the buyer knows where to be and when (#185) 802dfbb
- The agent brings their deals back from a downloaded deal-clock file on the Profile page, so the download is a real way to move or recover their book (#181) ebad1ba
- A year after a deal closes, the agent gets a drafted "Happy home anniversary" note to their clients, approved like any reminder, so past clients hear from them when referrals come from (#177) aa80ca6
- A deal's page lists the reminders still to come, by day, party and date, so in the meeting the agent shows what the app will draft next and that nothing goes out unapproved (#176) 1f1c97f
- A deal opened as a cash offer has no appraisal or financing dates and asks for no lender, and says "Cash" on the clock and its page (#175) 17ae8be
- "Today" is the agent's day in their own time zone, set on the Profile, so at 6 pm Eastern the clock does not already show tomorrow (#171) 40db2b2
- The agent downloads all their deals as one file (dates, parties, notes, moves and every approved message) from the Profile page, so leaving the app never means losing a deal (#172) 27899a4
1 earlier comment · 1 event
This pull logs which health check fails at boot and why, and it repairs a database whose schema is behind its version. It is untested against the real preview database, which I can't see.
My first two fixes were guesses at one missing column at a time. The preview's database had skipped whole migrations (a migration inserted mid-list leaves a database already past that position without its columns). Each deploy then surfaced the next missing column. So I replaced the guessing with a general repair.
What changed
- Boot diagnosis (the issue's scope):
failedCheckDetail(db)insrc/health.tsreturns{name, message} | null, andfailedCheckkeeps its signature.src/server.tsruns the checks once at boot on a read-only connection. On a failure it writesdeal-clock: health check "<name>" fails at boot: <db message>to stderr and keeps listening.- A healthy boot adds no line, and
/healthzstill answers 503 with the check's name only.
reconcile(db)insrc/db.ts:- It builds the pristine schema in memory and adds any table, index or column the real database lacks.
- It runs only when
failedCheckis non-null, so a healthy boot pays nothing. - It only adds, never drops or rewrites, so no row changes. A not-null column with no default is added nullable, as SQLite requires.
- Repair migrations: I kept the 29 appended one-line
ADD COLUMNrepairs from the earlier pushes. They are pinned insrc/migrations.pin.jsonas appends only. Dropping them would edit the pins, so I left them.reconcilecovers the same ground and more. - Tests, all green locally (
src/migrations,src/health,src/db,src/upgrade,src/hold,src/deals,src/serverandsrc/terminaltest files):- A database missing columns and a table, opened with
openDb, reads healthy afterwards and keeps its deal and date rows. Itslead_dayscomes back as 3. - The health detail test names
datesandno such column: place, and returns null on a fresh database.
- A database missing columns and a table, opened with
Not done
reconcilerestores columns without theirCHECKconstraints, and it does not fix a rebuilt table whose oldCHECKis wrong. Those need the actual database to see.- I ran no deploy. If the preview still fails, the boot line will now name the check and the database's message.
- No contract cell changes.
To try it
After this deploys, /healthz on the preview should answer 200, and a boot on a broken database logs the failing check.
🤖 Generated with Claude Code
A boot on a database the first paint can't read now writes one line to the app's log. The line names the health check that fails and quotes the database's own error, for example health check "dates" fails at boot: no such column: place. A healthy boot writes nothing. /healthz answers exactly as before: the check's name and never the error text.
What changed
src/health.ts:failedCheckDetail(db)returns the failing check's name and the database's message.failedCheckkeeps its signature and still returns only the name. The newreportHealthAtBoot(db, title, log)writes the one line when a check fails.src/server.ts:servecallsreportHealthAtBooton the databaseopenDbjust opened. There is no longer a second read-only connection that rebuilt theapp.dbpath, and no code that only runs insideimport.meta.main.src/health.test.ts: two tests bootserveon a temporary directory and capture stderr:- with
deadline.placedropped, stderr holds exactly one line namingdatesandno such column: place; - on a fresh database, stderr stays empty.
The first test fails when the call in
serveis removed; I checked this by taking it out and running the tests.- with
Removed at review
reconcile()and its call inopenDbare gone.- So are the 29 appended
ADD COLUMNmigrations and their pins.src/db.ts,src/migrations.pin.jsonandsrc/migrations.test.tsare back to what is onmain. - The
slice(0, -29)workaround insrc/health.test.tsis gone with them.
Not done here Repairing a database whose columns don't match the schema version it records is now its own issue, #214. Any repair needs the real database's schema in hand, and has to keep the columns' CHECK constraints.
Checks
bun test src/health.test.ts src/migrations.test.ts src/live.test.ts src/db.test.ts: 18 pass, 0 fail.bun x tsc --noEmitdid not type-check anything: the repository has notsconfig.json, so tsc only prints its help text.scripts/gate.tsandscripts/fast.tsdon't exist in this repository.- Nothing under
src/web/changed, so the design lint wasn't needed.
To try it: in a scratch copy of a data directory, drop a column the first paint reads (e.g. ALTER TABLE deadline DROP COLUMN place) and start bun run src/server.ts with that directory. The log shows the check and the SQLite error, and /healthz answers 503 naming only dates.
🤖 Generated with Claude Code
This pull logs which health check fails at boot and why, and it repairs a database whose schema is behind its version. It is untested against the real preview database, which I can't see.
My first two fixes were guesses at one missing column at a time. The preview's database had skipped whole migrations (a migration inserted mid-list leaves a database already past that position without its columns). Each deploy then surfaced the next missing column. So I replaced the guessing with a general repair.
What changed
failedCheckDetail(db)insrc/health.tsreturns{name, message} | null, andfailedCheckkeeps its signature.src/server.tsruns the checks once at boot on a read-only connection. On a failure it writesdeal-clock: health check "<name>" fails at boot: <db message>to stderr and keeps listening./healthzstill answers 503 with the check's name only.reconcile(db)insrc/db.ts:failedCheckis non-null, so a healthy boot pays nothing.ADD COLUMNrepairs from the earlier pushes. They are pinned insrc/migrations.pin.jsonas appends only. Dropping them would edit the pins, so I left them.reconcilecovers the same ground and more.src/migrations,src/health,src/db,src/upgrade,src/hold,src/deals,src/serverandsrc/terminaltest files):openDb, reads healthy afterwards and keeps its deal and date rows. Itslead_dayscomes back as 3.datesandno such column: place, and returns null on a fresh database.Not done
reconcilerestores columns without theirCHECKconstraints, and it does not fix a rebuilt table whose oldCHECKis wrong. Those need the actual database to see.To try it After this deploys,
/healthzon the preview should answer 200, and a boot on a broken database logs the failing check.🤖 Generated with Claude Code
Closes #205