Skip to content

gbrain reindex-frontmatter creates an unconnected PGLite engine and fails before dry-run #1225

@oudouusa

Description

@oudouusa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions