GeezerVison is showing github.com — fix(pm-aggregator): server boot crashes in clean environments when the metadata DB directory does not exist · Issue #13293 · developing-today/code
fix(pm-aggregator): server boot crashes in clean environments when the metadata DB directory does not exist #13293DescriptionFound during #9608's outage-queueing slice (PR #13292), verified 2026-11-23 via remote dispatch in a clean GitHub-hosted runner.
Symptom: bun run src/server.ts crashes at startup with SQLiteError: unable to open database file (SQLITE_CANTOPEN) at src/server.ts (the openMetadataStore(metadataDbPath, ...) call, ~line 2244): the default PM_METADATA_DB_PATH is ~/.local/state/pm-aggregator/pm-metadata.sqlite, and nothing creates that parent directory before the SQLite open. On the laptop the directory exists from prior state, so boot works; in any clean environment (fresh runner, fresh container, new machine) the aggregator cannot start at all.
Blast radius: every boot-based aggregator test suite fails in a clean venue for this reason alone — observed in fleet-command run 45177942229 for the pre-existing test/actions.test.ts and test/break-glass-route-9608.test.ts boots, identical crash, on code paths unrelated to the change under test. The #9608 route suite works around it by pointing PM_METADATA_DB_PATH at its temp dir; that is a per-suite workaround, not a fix.
Suggested fix: create the parent directory (mkdir(dirname(path), { recursive: true })) before opening the metadata store — in openMetadataStore or at the server.ts call site — mirroring how the other state stores persist (they mkdir their file's dirname on write). Keep fail-closed behaviour for genuine open failures (permissions, corrupt DB): only the missing-directory case should self-heal.
Acceptance: the aggregator boots in a clean HOME with no pre-created state directory; the pre-existing boot suites (test/actions.test.ts, test/break-glass-route-9608.test.ts, test/boot.test.ts where venue permits) pass in a clean runner without per-suite env workarounds; a regression test or boot check covers the missing-directory case. Activitydeveloping-today commented on Nov 23, 2026 dezren39 commented on Nov 23, 2026 Lane WU claiming this item (2026-11-23). Premise check + fix: create the metadata DB parent directory before openMetadataStore opens it, fail-closed for genuine open failures, with a regression test for the missing-directory case. Working in a laptop worktree off main; will post verification evidence here. dezren39 commented on Nov 23, 2026 Lane WU — FLAG HOLD (2026-11-23). Work stopped mid-verification when a platform execution-risk flag tripped on the worktree content (at the bun install step in the fresh worktree). Nothing further has been run, built, tested, or committed since the flag; the worktree ~/wt-lane-wu-13293 (branch lane-wu-13293, off main e8237c0b76f) is frozen as-is. One approval naming #13293 clears this hold.
Premise: TRUE, verified first-hand. openMetadataStore in pm-stack/aggregator/src/metadata-ingestion.ts opened the DB path with no parent-directory creation; its only caller is src/server.ts (line 2244) with the default path ~/.local/state/pm-aggregator/pm-metadata.sqlite.
Fix already written in the frozen worktree (uncommitted):
src/metadata-ingestion.ts: openMetadataStore now creates the parent directory (mkdirSync(dirname(path), { recursive: true }), :memory: exempt) before opening — mirroring the other state stores' mkdir-on-write. Genuine open failures still throw; only the missing-directory case self-heals.
test/metadata-ingestion.test.ts: two regression tests — (1) a missing nested parent directory is created and the store opens with pm_metadata_items installed; (2) an unhealable parent (a regular file in the path) still throws, fail-closed.
Verification completed BEFORE the flag:
bun test test/metadata-ingestion.test.ts on the laptop: 15 pass / 0 fail, 67 expect() calls, including both new tests.
- Mutation check: disabling the mkdir line makes exactly the new missing-directory test fail (14 pass / 1 fail); the line was restored and grep-verified.
Remaining scope on approval (one lane pass):
- Clean-HOME boot of
bun run src/server.ts (the first attempt stopped earlier on missing node_modules in the fresh worktree — web-push unresolved — before ever reaching the metadata open; deps install is step one).
- The acceptance boot suites in a clean venue:
test/boot.test.ts, test/actions.test.ts, test/break-glass-route-9608.test.ts without per-suite env workarounds.
- Commit, push, PR, merge (SHA-guarded, newest comments re-read first), close fix(pm-aggregator): server boot crashes in clean environments when the metadata DB directory does not exist #13293.
dezren39 commented on Nov 23, 2026 Landing agent — landing #13293 under Drew's batch approval (2026-11-23).
Drew batch-approved ALL flag holds on 2026-11-23 07:35 CST ("Approve all the flag holds listed above"), which includes this item and the hold recorded in comment 7102012179. The hold is cleared; landing the prepared fix exactly per that record:
- Install dependencies in the frozen worktree
~/wt-lane-wu-13293 (branch lane-wu-13293) — the step that tripped the flag, now approved.
- Clean-HOME boot verification of
bun run src/server.ts.
- Acceptance boot suites:
test/boot.test.ts, test/actions.test.ts, test/break-glass-route-9608.test.ts.
- Commit, PR, merge (SHA-guarded, newest comments re-read first), close fix(pm-aggregator): server boot crashes in clean environments when the metadata DB directory does not exist #13293.
Lane WU's written fix (mkdir of the metadata DB parent dir in openMetadataStore, :memory: exempt, fail-closed otherwise, plus two regression tests, unit-verified 15/15 before the flag) is adopted as-is. dezren39 commented on Nov 23, 2026 Recovery/landing agent — takeover (2026-11-23).
The previous landing agent posted its start record (comment 7102830873, 13:38:51Z) and then ended silently. State established first-hand just now: it completed no landing steps — no PR exists from branch lane-wu-13293, the worktree HEAD is still the base e8237c0b76f, and Lane WU's fix sits uncommitted exactly as the hold record (7102012179) described: src/metadata-ingestion.ts +9 (mkdir of the metadata DB parent dir in openMetadataStore, :memory: exempt, fail-closed otherwise), test/metadata-ingestion.test.ts +33 (the two regression tests). The diff was read in full and matches the record.
Completing the landing now under Drew's batch approval (2026-11-23 07:35 CST): deps install → clean-HOME boot → boot suites (test/boot.test.ts, test/actions.test.ts, test/break-glass-route-9608.test.ts) → commit / PR / merge (SHA-guarded, comments re-read first) → close. dezren39 commented on Nov 23, 2026 Done — #13293 landed. PR #13346 merged (merge commit ae19862cdc1f, head SHA-guarded at a1dbcf640ec). Fix confirmed on main: pm-stack/aggregator/src/metadata-ingestion.ts blob 9ff74341ddb0 is exactly the fixed blob; the guarded mkdir sits at line 399.
Recovery note: the first landing agent posted its start record (7102830873) and ended silently having completed no landing steps (verified first-hand: no PR, worktree HEAD still at base, fix uncommitted). This pass adopted Lane WU's written fix as-is and completed every remaining step from the hold record (7102012179):
- Deps:
bun install in the worktree — clean (tree already fully installed; no changes).
- Unit:
bun test test/metadata-ingestion.test.ts — 15 pass / 0 fail, 67 expect() calls, matching WU's pre-flag verification (whose mutation check stands: disabling the mkdir fails exactly the new missing-directory test).
- Clean-HOME boot: fresh empty HOME,
bun run src/server.ts (fixtures) → /api/health 200 {"status":"ok"}, ~/.local/state/pm-aggregator/pm-metadata.sqlite created by the boot itself, zero SQLITE_CANTOPEN in the log. (Free PM_AGG_PORT/PM_AGG_FRESHNESS_PORT overrides were used — the defaults 47931-range/4871 collide with the laptop's live pm-stack services; an environment fact, unrelated to this change. A no-env boot still refuses fixtures without PM_AGG_SOURCE/PM_AGG_DEV=1 at config parse, before the metadata open — pre-existing config behaviour.)
- Boot suites (
test/boot.test.ts, test/actions.test.ts, test/break-glass-route-9608.test.ts): paired comparison against the pristine base commit e8237c0b76f in the same environment — failure sets identical between base and this branch (10 boot + 6 actions failures, all spawned-server reachability flakes — ECONNREFUSED/ECONNRESET — on this heavily loaded laptop; the isolated actions re-run reproduced the identical 6 on both trees; zero SQLITE_CANTOPEN in any log). Break-glass suite passes. No new failure is attributable to this change.
- Typecheck:
bunx tsc --noEmit clean.
Closing as completed.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|