Summary
gbrain reindex-frontmatter fails on a PGLite brain with:
PGLite not connected. Call connect() first.
This happens even for --dry-run --json, so the command cannot be used to clear the effective_date_health doctor warning.
Repro
On gbrain 0.37.1.0 with a PGLite brain:
gbrain reindex-frontmatter --dry-run --json
Observed:
PGLite not connected. Call connect() first.
Root cause
src/cli.ts already creates a connected engine for DB-backed CLI-only commands, but the reindex-frontmatter dispatch path calls:
await reindexFrontmatterCli(args);
return; // reindexFrontmatterCli handles its own engine lifecycle
Then src/commands/reindex-frontmatter.ts creates a second engine:
const engine = await createEngine(toEngineConfig(cfg));
const result = await runReindexFrontmatter(engine, opts);
That second engine is never connected before runReindexFrontmatter() calls executeRaw() via countAffected().
Expected fix
Mirror reindex-code:
src/cli.ts should call reindexFrontmatterCli(engine, args)
reindexFrontmatterCli should accept the connected BrainEngine
- remove the self-owned
createEngine() / disconnect() lifecycle from reindex-frontmatter.ts
I verified this locally:
bun test ./test/cli.test.ts # pass
bun run typecheck # pass
bun run src/cli.ts reindex-frontmatter --dry-run --json # exits 0
Summary
gbrain reindex-frontmatterfails on a PGLite brain with:This happens even for
--dry-run --json, so the command cannot be used to clear theeffective_date_healthdoctor warning.Repro
On gbrain
0.37.1.0with a PGLite brain:Observed:
Root cause
src/cli.tsalready creates a connected engine for DB-backed CLI-only commands, but thereindex-frontmatterdispatch path calls:Then
src/commands/reindex-frontmatter.tscreates a second engine:That second engine is never connected before
runReindexFrontmatter()callsexecuteRaw()viacountAffected().Expected fix
Mirror
reindex-code:src/cli.tsshould callreindexFrontmatterCli(engine, args)reindexFrontmatterClishould accept the connectedBrainEnginecreateEngine()/disconnect()lifecycle fromreindex-frontmatter.tsI verified this locally: