Repository navigation
feat(dev): run local PostgreSQL in Apple container per checkout and test run - #42
Conversation
…est run The old setup used one Docker container for every checkout. Checkouts shared the development database. Parallel test runs shared the e2e database, the e2e port, the Playwright output, and the SQLx database name. scripts/caltodo-pg now owns the local PostgreSQL containers (ADR 0006): - Each checkout has its own development container and named volume. The physical checkout path identifies the checkout. - Each independent test run starts a temporary container on tmpfs. Nested tasks reuse it only through the CALTODO_PG_RUN_* variables. - Labels and the run process id let a later run delete the containers of dead runs of the checkout. No task runs a general prune. - A busy port fails the start, and the script tries another port. - The readiness check sends a PostgreSQL SSLRequest through the published port. The port forwarder accepts TCP before the server is reachable, so a plain TCP check passed too early. test:e2e gives each run its own client build, database, port, and output directory, and stops its test server at exit. build and the SQLx prepare step use a checkout lock. dev ignores DATABASE_URL from .env; CALTODO_DEV_DATABASE_URL overrides it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonikanerva
left a comment
There was a problem hiding this comment.
Verdict: FAIL
Independent review in a separate context. The full mise run verify passes on the integrated result. Two implementation defects block acceptance. Both are small to fix. Neither defect gives a false pass.
Reviewed version
- PR head:
8f104620e1e56e6ef685c4513545a4109a892c00 - Base:
origin/main8b4f11d7e196840819c2f06e9d81341812369491. The base moved after the PR body was written (PR #41, tower-http 0.7). The PR body cites2478fcaand a verify run on1686f3c. Both are stale. - Integration: a local synthetic merge commit
396fd1aa125b84cbd861308582f8305731afe96e(treec778a10c55e6262defef04e42e788e2297ac25e8). The merge was automatic with no conflicts. The commit was not published. - Environment: Apple silicon Mac, Darwin 27.2.0, Apple
container1.0.0 (ee848e3), imagepostgres:18, mise toolchain pins from the integrated tree. An isolatedgit worktreewas used in a temporary directory, outside the command sandbox (thecontainerCLI needs XPC). Other agents used the same Mac.
Reviewer verification
| Command | Result |
|---|---|
mise run verify on 396fd1a |
exit 0, 295 s (14:20:22Z to 14:25:17Z). nextest 208 passed, doctests ok, Vitest 19 + 4 passed, Playwright 67 passed. git status clean after the run. No test container left. |
db:start, db:migrate, insert a canary row, db:stop, db:start |
The canary row survived stop and start. |
db:dump, then db:reset, then db:restore |
Fails: "the development database is not empty; run 'mise run db:reset' first" (finding 1). |
scripts/caltodo-pg reset (no migrate), then db:restore, then db:migrate |
The canary row is restored. |
Stop the dev container, bind its port 40170 with a listener, then db:start |
Fails loudly (errno 48) and names db:recreate. db:recreate takes port 39654. The data stays. |
Three parallel test:e2e runs in one checkout: A runs normally, B gets SIGTERM on its mise process, C gets SIGKILL on its caltodo-pg wrapper |
A: 67 passed, exit 0. B: exit 143, its container is deleted, and the PostgreSQL log is written. C: the orphan container stays, and db:reap deletes it ("process 69385 ended"). No e2e_server process stays. The global start lock serialised the starts. |
Loop contract:generate (15 times) against contract-check and the api-client typecheck (8 times each), in one checkout |
contract-check: 6 ok, 1 failed ("client.gen.ts: missing from the committed tree"). typecheck: 6 ok, 1 failed (TS2307 "Cannot find module './generated/sdk.gen.js'"). This is an amplified test (finding 2). |
shasum -a 256 -c for both SHA256SUMS files in ~/Backups/caltodo/2026-11-15-pg-migration/ |
All 9 files OK. final/source-inventory.txt shows PG 18.6 and only the _sqlx_test tables (12 rows). This agrees with the inventory in the PR body. |
git grep for 55473, 47411, CALTODO_PG_URL, CALTODO_PG_VOLUME, CALTODO_PG_CONTAINER, test-results, docker |
Only the history in ADR 0006 and the image reference docker.io/library/ remain. Two stale entries remain: /e2e/test-results in .gitignore and e2e/test-results/** in .oxlintrc.json. The new output directory is target/e2e/<run>. |
The reviewer deleted its own dev container and volume (caltodo-dev-00aa163bd52a, caltodo-dev-00aa163bd52a-pg18). The reviewer did not touch other containers or volumes.
Blocking findings
1. The documented restore path cannot succeed
- Location:
mise.toml[tasks."db:reset"](it runsscripts/caltodo-pg resetand thendb:migrate).scripts/caltodo-pgdev_restore(line 335: it refuses a database with any table, and its message says "run 'mise run db:reset' first"). The PR body "Recovery" section has the same steps. - Evidence:
mise run db:resetfollowed bymise run db:restore -- FILEfails with "the development database is not empty".db:resetapplies the migrations, so the database is never empty. The script's own error message sends the user to the same dead end. - Impact: the owner asked for a restore path of the development data. The PR records this procedure as the recovery path of the migration (criterion 11). The procedure fails.
db:cloneworks because it calls the unmigrateddev_resetdirectly. - Minimum fix: give the user a supported way to get an empty database before a restore. For example, let
db:restoredrop and create the database itself (likeclonedoes), or add a task that resets without migrating. Then make the error text, README, STACK §1, and the PR body name the working sequence. Restore, then rundb:migrate. - Verify: run
db:start,db:migrate,db:dump -- F, then the documented reset, thendb:restore -- F. The restore must pass and keep a canary row.db:migratemust apply nothing new.
2. Same-checkout build writes collide with unlocked readers (criterion 10)
- Location:
mise.tomlbuild/build:steps.scripts/checkout-lockserialises onlybuildagainstbuild.packages/api-client/scripts/generator-config.mjssetsclean: true, socontract:generatedeletes and rewritespackages/api-client/src/generated/.contract:exportrewritescontract/openapi.json. The readers take no lock. Readers ofsrc/generated/:contract:check; thetypecheckoflint(the api-client andweb, which imports@caltodo/api-client); Oxlint onpackages/api-client/src; the api-client and web Vitest; and the per-run e2e Vite build inscripts/e2e-run.contract.rsdoes not readcontract/openapi.jsonat run time (grep). - Evidence: in the amplified loop above, both readers failed once while the generator ran. Two
verifyruns in one checkout reach this overlap when one run is inbuildand the other is inlint,contract:check, or Vitest. - Impact: the owner asked to check same-worktree build write collisions and to use per-run targets or narrow locks. The owner listed
verifyamong the runs that get their own isolated environment. The PR says criterion 10 is handled. The Limitations section does not mention this collision. The failure is a spurious verify failure, not a false pass. Under the doctrine, flaky gates still need a fix. - Minimum fix: one of these options:
- Make the readers and the generator writer share a narrow checkout lock, for example
generatedaroundcontract:export/contract:generateand aroundcontract:check, the api-client typecheck, and Vitest. - Make
buildgenerate into a scratch directory and replace the tracked files only when they differ. Inverifythey never differ, because verify must not change tracked files. - Serialise
verifyper checkout. The owner said "do not serialize everything", so this option needs an owner decision. A reviewed exception is not enough.
- Make the readers and the generator writer share a narrow checkout lock, for example
- Verify: repeat the loop from the table, with the generator against contract-check and typecheck. Expect 0 failures.
Non-blocking observations
scripts/caltodo-pgcleanuprunsrm -f "$global_lock"at the end of every run. At that time the lock can belong to another run in its count-and-create step. A third run can then get pastCALTODO_PG_MAX_TEST_RUNSin a race. The cap is soft, but the removal should depend on ownership.random_portgives 20000–39999. The dev fallback port therefore falls in the range that the comment reserves for tests (observed: 39654). Either the comment is wrong or a dev range is missing.- No task finds the dev containers and volumes of removed worktrees. They stay until somebody deletes them by hand. The data is kept by design.
db:infoshows only its own checkout. target/e2e/<run>/resultsandtarget/caltodo-pg/runs/<run>/accumulate without a cleanup.db:psqluses--interactivewithout--tty, so an interactive psql session has no prompt or line editing.- README: the new "Local databases" heading splits the Commands list. The
contract:*andstartbullets now sit under "Local databases".
Criteria traceability (owner request to evidence)
- Reviewer ran: no Docker in the tasks; PostgreSQL tools in containers; dev container and volume per checkout; stop keeps data; a separate container per test run; busy port fails and recovers; readiness check (verify and the challenges did not start early); own-resource cleanup and later reap after SIGKILL; interrupt of one run does not break another; global start lock (observed "waiting for the lock"); per-run e2e port, database, build, output, and auth state; full verify passes; backups exist and match their checksums.
- Code read only: nested reuse only through
CALTODO_PG_RUN_*(one container for all verify steps);DATABASE_URLandE2E_DATABASE_URLremoved for test runs;127.0.0.1binds; theCALTODO_PG_MAX_TEST_RUNScap (three runs against the default 4 did not reach it; see the lock-ownership observation). - Narrative only (not repeated by the reviewer): the old Docker containers and volumes are unchanged; trial restore and the final restore into the main checkout's volume; independent migrations in two worktrees;
/readyz92/92 while tests ran; start-time and memory measurements in ADR 0006; "keep keys" (no encrypted tokens existed in the inventoried data). - Pending owner action: main's
.envlacksACTION_TOKEN_SECRETandTOKEN_ENCRYPTION_KEY(PR Limitations). So "the app works with the migrated dev data" stays unverified until the owner adds them. The reviewer did not read.env. - Dependency freshness skip: the lead relayed the owner instruction to the reviewer. The deps PRs #38, #39, and #41, merged today, support it. The reviewer did not see the owner instruction directly.
- Record: the PR body's Verification section binds to
1686f3c/2478fca. Update it to the final head and the current base.
Other required evidence
- CI: the repository has no CI pipeline (STACK §14). The PR has no status checks. Nothing is pending there.
- Release (STACK §14, P7): the PR has no Railpack plan (
railpack info .with the latest Railpack release). The diff changesmise.toml([env]and tasks;[tools]is unchanged). The diff does not changerailpack.json, the Rust sources, or the web sources. Record the plan in round 2, or record why it does not apply. - Owner-only: the
.envsecrets above. No other owner test is required before merge.
Approved exceptions
None proposed, none approved.
Review of PR #42 found two defects. db:reset runs the migrations, so db:restore always found tables and refused. db:restore and db:clone now replace the development database. They first write the old database to target/caltodo-pg, and then they apply the migrations. contract:generate deleted and rewrote src/generated while a parallel type check or contract:check read it. The generator and the OpenAPI export now write to scratch files and replace a tracked file only when it changes, with an atomic rename. Smaller fixes: the test start lock is released only by its holder, a development container falls back to the development port range, db:psql uses a TTY when one exists, and db:reap --all reports the development containers of removed checkouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-container-migration-e73889
Oxlint requires the explicit node:process import, like contract-check.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonikanerva
left a comment
There was a problem hiding this comment.
Verdict: PASS
Independent review, round 2, in a separate context. The two blocking findings of round 1 are fixed. The full mise run verify passes on the integrated result. No new blocking finding.
Reviewed version
- PR head:
d4d20400e5478e57edffee94263fcc76fb36e088 - Base:
origin/main8b4f11d7e196840819c2f06e9d81341812369491 - Integration: the base is an ancestor of the head (merge commit
cebde13). The head is the tested integration commit. No synthetic merge was necessary. - Environment: Apple silicon Mac, Darwin 27.2.0, Apple
container1.0.0 (ee848e3), imagepostgres:18, mise 2026.11.8 with the pins of the head. A fresh detachedgit worktreein a temporary directory (checkout idd27daf7801b1), run outside the command sandbox (thecontainerCLI needs XPC).
Reviewer verification
| Command | Result |
|---|---|
mise run setup, then mise run verify on d4d2040 |
exit 0. Setup ended 14:44:11Z; verify (with scan:deps) ran from then to 14:53:56Z. nextest 208 passed (0 skipped), doctests ok, Vitest 19 + 4 passed, Playwright 67 passed. git status --porcelain empty after the run. No test container left. |
Round-1 repro: db:migrate, canary row, db:dump -- FILE, db:reset, then db:restore -- FILE |
exit 0. The task wrote target/caltodo-pg/before-restore-<time>.dump, restored FILE, and ran db:migrate. Canary row back. _sqlx_migrations = 1,2,3. Round-1 finding 1 is fixed. |
Undo: db:restore of the before-restore dump |
exit 0. The state before the restore came back (no canary table, 3 migrations). Then db:restore of FILE again: canary back. |
db:restore of a non-empty garbage file |
exit 1. A backup was written first. pg_restore failed: "input file does not appear to be a valid archive (too short?)". The db:migrate step did not run. The database was empty after the failure. db:restore of the new backup gave the canary row back. |
db:restore without a file; with a missing file |
exit 1 each ("restore FILE"; "no dump at …"). No change to the data. |
db:clone -- DIR from a second reviewer worktree (its own dev container, a table without migrations) |
Success output ("restored …", migrate "applied":3). Backup written. Source table present. Old data replaced. Migrations 1,2,3 applied. The temporary clone dump was deleted. db:clone of the same checkout is refused (exit 1). |
Argument passing of a mise run array ["script", { task = "x" }] (mise 2026.11.8, toy project) |
mise run t -- '/a b/c.dump' appends the quoted argument to the script step only. The task step gets no argument. A failed script step stops the array (exit 3). |
Race loop in one checkout with the committed contract (no file changes), all at the same time: 40 × contract:export, 40 × contract:generate, 25 × contract:check, 25 × api-client typecheck |
0 failures in each group. git status clean. Round 1 saw 1/7 failures each. |
Generator write path, functional (second worktree): append a line to types.gen.ts, delete sdk.gen.ts, add stray.ts and sub/deep.ts, then contract:generate |
Tracked tree restored (git status clean), no *.tmp left. Only the empty directory sub/ stayed. |
Generator write path, concurrent: 30 × (append a comment to types.gen.ts and zod.gen.ts, then contract:generate) beside 30 × api-client typecheck and 15 × api-client Vitest |
0 failures in each group. So every generate replaced two files with the temporary file and rename path. Round-1 finding 2 is fixed. (A first variant of this loop also deleted client.gen.ts in the test itself; its reader failures came from that test deletion, not from the generator.) |
db:restore -- ~/Backups/caltodo/2026-11-15-pg-migration/final/caltodo.dump (the recovery command of the PR body) into a new empty dev container of a reviewer worktree; shasum -a 256 -c SHA256SUMS before |
Checksums OK. exit 0. No backup (the database was empty). Tables users, user_settings, action_tokens, app_sessions, _sqlx_migrations, _sqlx_test.databases (12 rows). Migrations 1,2,3. |
railpack info . --format json with Railpack 0.43.0, on base 8b4f11d and head d4d2040 |
The two plans are identical (the same steps, the start command ./bin/caltodo migrate && exec ./bin/caltodo serve, and runtime image railpack-runtime:mise-2026.10.14). |
git grep for docker, 55473, caltodo-pg-18, CALTODO_PG_VOLUME |
Only the intended mentions remain: the "never use docker" rules in AGENTS.md and STACK.md, the default docker.io/library/ registry prefix in scripts/caltodo-pg, and the digits 55473 inside a timestamp of find_slot.golden.json. |
Cleanup: the reviewer deleted only its own containers and volumes caltodo-dev-d27daf7801b1 and caltodo-dev-157369d358a3 (with the -pg18 volumes), and caltodo-dev-e7537f6148eb of a third worktree (each with its -pg18 volume), and removed the three worktrees. No other container was touched.
Round-1 non-blocking items
- The start lock is now released only by its holder (
holdingflag). - Development ports fall back inside 40000–47999.
db:psqladds--ttyonly for a terminal. The non-terminal use in the test above works.db:reap -- --allreports the dev containers of removed checkouts and never deletes them.- README: the
contract:*andstartlines moved from "Local databases" to the command list. - Still open (non-blocking):
/e2e/test-resultsin.gitignoreande2e/test-results/**in.oxlintrc.jsonare stale;target/e2e/<run>/resultsandtarget/caltodo-pg/runs/<run>/still accumulate without a cleanup. - The Railpack plan is now recorded and reproduced (see above).
Non-blocking observations (no change required for this PR)
contract:exportwritescontract/openapi.json.<pid>.tmpinsidecontract/on each run.contract-check.mjscompares the wholecontract/tree, so a check that lists the files in the few milliseconds between the write and the rename or delete reports drift. The race loop above did not hit this window. Minimum fix: write the temporary file outsidecontract/on the same volume (for example undertarget/).generate.mjshas the same pattern insrc/generated, but only when a file changes.db:restorevalidates the dump only throughpg_restoreafter the database is dropped. A bad file leaves an empty database until the backup is restored, as the test above shows.pg_restore --listbeforedev_resetwould reject the file without a drop.- The backups stay under
target/, socargo cleandeletes them. The backup name has one-second resolution, so two restores in the same second overwrite one backup. In practice a restore with its migration step takes longer than one second. mise run db:restore -- FILEresolves a relative FILE against the repository root, not against the current directory of the caller.
Evidence and authority notes
- Dependency freshness: this task PR does not run its own check. The PR body states an owner instruction to the lead to skip it. The reviewer cannot verify that owner instruction. Recorded facts: PR #36 (merged 2026-11-15T11:15Z) records the §3 freshness check of 2026-11-15 on
main2f14d8cand lists the retained majors. The follow-up deps PRs #38, #39, and #41 merged today, and each PR body refers to that check. STACK.md §14 accepts the check result in the task PR through links to the deps PRs. Suggestion: link #36 in the PR body. - The repository has no CI pipeline and no required checks (
statusCheckRollupis empty). - No owner-only test is required for this change. The data migration on the main checkout and the backups in
~/Backups/caltodo/2026-11-15-pg-migration/were checked in round 1. This round repeated the checksum offinal/and the restore offinal/caltodo.dump(above). The old Docker volumes were not inspected. - This PASS is not owner approval. The lead owns acceptance and merge.
|
Release check for merge commit 7f88026 (2026-11-15):
🤖 Generated with Claude Code |
Summary
The local PostgreSQL servers of development and tests move from one shared Docker container to Apple
container(ADR 0006).scripts/caltodo-pgowns the container lifecycle. The mise task names stay.test,test:e2e,sqlx:check,sqlx:prepare,verify) starts its own temporary container (tmpfs, fsync off) and deletes it at the end.test:e2eruns have their own client build, database, server port, and Playwright output directory.db:info,db:psql,db:dump,db:restore,db:clone,db:recreate,db:reap.db:restoreanddb:clonereplace the development database, keep a backup of the old one intarget/caltodo-pg/, and apply the migrations.contract:exportandcontract:generatereplace a tracked file only when it changes, with an atomic rename, so parallel readers never see a partial file.Acceptance criteria (from the owner request)
container)psql,pg_dump,pg_restorerun in containers; no Docker command inmise.tomldb:stopkeeps data_sqlx_testrows)CALTODO_PG_RUN_*)testlog: nextest andtest:e2eused run772f9a9f; a second separate run got its own containerDATABASE_URLwith-test-dbunsetsDATABASE_URLandE2E_DATABASE_URL;devignoresDATABASE_URL(CALTODO_DEV_DATABASE_URLoverrides)127.0.0.1onlyshlocklock; a busy port failscontainer run(errno 48) and the script tries another port;lsofshows127.0.0.1bindskill -9of one run: the next run of the checkout deleted its container; the parallel live run continuedtarget/caltodo-pg/runs/<run>/postgres.log;CALTODO_PG_KEEP=failurekeeps the containerCALTODO_PG_MAX_TEST_RUNS(default 4)scripts/checkout-lockforbuildandcargo sqlx prepare(it writestarget/sqlx-*and touches sources). Generator and export write scratch files and rename only changed files: 8 generate/export runs beside 7contract-checkand 7typecheckruns gave 0 failures (review round 1 saw 1/7 each before the fix)verifypassesValidation
caltodo serveon the main checkout's development database answered/readyz200 for 92 of 92 polls whilesqlx:checkand nextest (198 passed) ran beside it.0004; this checkout kept versions 1–3 and no probe table.db:clonecopied this checkout's data into the second worktree.test:e2e(67 passed) and twosqlx:checkran at the same time; onetest:e2egot SIGTERM during Playwright and exited 143; the others passed; no test container or e2e server stayed.Data migration
Inventory (2026-11-15): the Docker PG 18.6
caltododatabase had no application tables, only the_sqlx_testbookkeeping of test runs (12 rows). The old PG 17.9 volumecaltodo-pghad empty or synthetic databases (example.come2e user). The Homebrewpostgresql@18data directory (thelocalhost:5432of.env) held nocaltododatabase, and its binaries are not installed. No real development data existed.pg_dumpall --globals-only, run in containers) with SHA-256 sums:~/Backups/caltodo/2026-11-15-pg-migration/.mise.toml), which write only_sqlx_testbookkeeping. The final dump came from the live server withpg_dump(one consistent snapshot) instead of stopping their runs.caltodo migrate: passed.caltodo-dev-7c5c590d5372-pg18, thencaltodo migrate(versions 1–3).Recovery: in the main checkout,
mise run db:restore -- ~/Backups/caltodo/2026-11-15-pg-migration/final/caltodo.dump. The task replaces the database, keeps a backup of the old one, and applies the migrations. Tested on a development database: the probe row came back, migrations 1–3. The old Docker data stays in the volumescaltodo-pg-18andcaltodo-pg.Limitations
containerCLI fails inside a command sandbox; agents run the database and test tasks outside it.mise run dev.db:reap..envhas aDATABASE_URLto the removed Homebrew server and lacksACTION_TOKEN_SECRETandTOKEN_ENCRYPTION_KEY.devnow ignores theDATABASE_URL; the owner adds the two secrets.railpack info ., Railpack 0.43.0): unchanged. Rust provider, Node 26.13.1, pnpm 12.21.0, Rust 1.100.0, the same build steps and start command.db:reap -- --allreports them and never deletes them.containerinstall or runs a prune. caltodo uses host ports 20000–47999; spot-price uses 48000–53999.Verification
mise run verifyond4d2040(the head, which merges baseorigin/main8b4f11d): exit 0 in 403 s. Nextest 208 passed, Vitest 19 + 4 passed, Playwright 67 passed; no tracked file changed; no test container left.Review round 1 (FAIL on
8f10462): the restore path and the generator read race are fixed inf986c0d; the lint fix isd4d2040.🤖 Generated with Claude Code