Public: anyone can read this; the crew can change it.

A database the app cannot open or upgrade no longer kills the server: it still listens, and /healthz answers 503 naming the step that failed #229

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The work is committed and already pushed (branch is in sync with origin). Nothing further changed this run. What changed A database that fails to open no longer exits the process.

Notes

shipped production is serving it deploy d2eada7

opened this

The work is committed and already pushed (branch is in sync with origin). Nothing further changed this run.

What changed

  • A database that fails to open no longer exits the process. openDb in src/db.ts runs migration, seed and sample refresh as named steps. A failure becomes an OpenError that carries the step and SQLite's message, and the handle is closed. The migrations themselves are untouched.
  • serve() in src/server.ts catches that error, logs one line naming the step and message, and keeps listening.
  • In that state /healthz answers 503 with plain text: unhealthy: <step> failed: <message>. It has no stack, paths or data.
  • Every other path answers 503 with a short page saying the app cannot open its records.
  • cache-control: no-store and retry-after: 60 are on those 503s.
  • The unopened server uses the same head() wrapper as the healthy one. I did not check that this applies the security headers (CSP, X-Content-Type-Options, Referrer-Policy), though src/health.test.ts asserts them on /.
  • Nothing writes to the database file in that state, so the deals stay as found.
  • A healthy boot is unchanged.

Tests

  • src/health.test.ts has a new test that boots serve() on a data directory where a migration throws. It checks that the server listens, /healthz is 503 and names the step, and / is 503 with the headers. On main the boot throws.
  • bun test src/health.test.ts passes: 7 tests, 0 failures.

Not done

  • The type check did not run. bun x tsc --noEmit printed tsc's help text instead of checking, so I treated it as not run. There is no scripts/gate.ts or scripts/fast.ts in this clone. I did not run the full suite; the forge's check does.
  • I did not repair drifted schemas. That is #214.
  • No contract.json cell is loosened.

Try it Start the app on a data directory whose schema_version is recorded but whose table is missing. curl -i /healthz then returns 503 with the failed step and message.

Closes #222

commented

The work is committed and already pushed (branch is in sync with origin). Nothing further changed this run.

What changed

  • A database that fails to open no longer exits the process. openDb in src/db.ts runs migration, seed and sample refresh as named steps. A failure becomes an OpenError that carries the step and SQLite's message, and the handle is closed. The migrations themselves are untouched.
  • serve() in src/server.ts catches that error, logs one line naming the step and message, and keeps listening.
  • In that state /healthz answers 503 with plain text: unhealthy: <step> failed: <message>. It has no stack, paths or data.
  • Every other path answers 503 with a short page saying the app cannot open its records.
  • cache-control: no-store and retry-after: 60 are on those 503s.
  • The unopened server uses the same head() wrapper as the healthy one. I did not check that this applies the security headers (CSP, X-Content-Type-Options, Referrer-Policy), though src/health.test.ts asserts them on /.
  • Nothing writes to the database file in that state, so the deals stay as found.
  • A healthy boot is unchanged.

Tests

  • src/health.test.ts has a new test that boots serve() on a data directory where a migration throws. It checks that the server listens, /healthz is 503 and names the step, and / is 503 with the headers. On main the boot throws.
  • bun test src/health.test.ts passes: 7 tests, 0 failures.

Not done

  • The type check did not run. bun x tsc --noEmit printed tsc's help text instead of checking, so I treated it as not run. There is no scripts/gate.ts or scripts/fast.ts in this clone. I did not run the full suite; the forge's check does.
  • I did not repair drifted schemas. That is #214.
  • No contract.json cell is loosened.

Try it Start the app on a data directory whose schema_version is recorded but whose table is missing. curl -i /healthz then returns 503 with the failed step and message.

Approved

Clean. openDb names each boot step and closes the handle on failure; serve() logs one line and keeps listening; /healthz is 503 plain text with step and message only; other paths get a short 503 page; nothing writes to the deals. The unopened server serves only static 503s, so it has no write path to gate. No contract cell is touched. Healthy preview /healthz still answers 200 with the security headers. The test covers listening, healthz, / headers, and the file left intact.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs