fix(migrate v0.29.1 Phase B): force poolSize:1 for explicit BEGIN/COMMIT path#917
fix(migrate v0.29.1 Phase B): force poolSize:1 for explicit BEGIN/COMMIT path#917jeremyknows wants to merge 1 commit into
Conversation
…MIT path phaseBBackfill calls backfillEffectiveDate which uses explicit BEGIN/COMMIT for PGLite portability. postgres.js rejects manual transactions with UNSAFE_TRANSACTION when the pool's max > 1, so on multi-pool postgres installs the migration wedges mid-batch after the first batch. Fix: pass poolSize:1 to engine.connect() in Phase B only. Phase C (read-only verify, no manual transactions) keeps the default pool size. The cast pattern matches src/core/brain-registry.ts:406 — poolSize is accepted by postgres-engine's connect() implementation but isn't surfaced on the generic BrainEngine.connect() interface, so the cast is the documented way to thread it. Observed on a developer postgres install (May 11, 2026): migration wedged after 3 consecutive partials. Unblocks MINIONS half-install check in gbrain doctor.
|
Closing — superseded by PR #740 (already in master) which solved this differently and better. What I missed: PR #740 rewrote I observed the original wedge on 2026-05-11 against a pre-#740 base on my local fork ( Verified on current No explicit BEGIN/COMMIT remain. Apologies for the noise. Thanks for the work on #740. |
Summary
phaseBBackfillinsrc/commands/migrations/v0_29_1.tscallsbackfillEffectiveDatewhich uses explicitBEGIN/COMMITper-batch for PGLite portability.postgres.jsrejects manual transactions withUNSAFE_TRANSACTIONwhenever the connection pool'smax > 1— so on multi-pool Postgres installs the migration wedges after the first batch.Phase C (verify, read-only, no manual transactions) is unaffected and keeps the default pool size.
Diff scope
One-line behavioral change: pass
poolSize: 1toengine.connect()inphaseBBackfillonly. Type-cast pattern lifted fromsrc/core/brain-registry.ts:406, which is the documented way to threadpoolSizethroughBrainEngine.connect()(the field is accepted byPostgresEngine.connect()atsrc/core/postgres-engine.ts:109but isn't surfaced on the generic interface inengine.ts:420).Verification
Real-behavior proof (observed, not reproduced this session)
Pre-fix observation — May 11, 2026 on a developer Postgres install (postgres.js with default
max > 1):gbrain migrate run v0.29.1started, completed Phase A (schema), advanced into Phase B, completed batch 1.UNSAFE_TRANSACTION: Manual transactions are not allowed when connection pool max > 1.partialstate. Re-running picked up resume token frombackfill.effective_date.last_id, hit the same failure on the next batch, partial again. Three consecutive partials before root-causing.gbrain doctorreported MINIONS half-install —effective_date_healthwas warning on rows the partial backfill never reached.Why pglite users haven't seen this — PGLite ignores
poolSizeand always runs single-connection. The bug only surfaces on a postgres-engine multi-pool setup.What was NOT tested in this session
migrate run v0.29.1. The fix is one line, the bug pattern is well-documented in postgres.js docs (UNSAFE_TRANSACTIONwhen manual transactions cross a connection pool), and the typecheck path matches the existingbrain-registry.ts:406precedent, so I'm comfortable submitting on those grounds — but flagging the gap for reviewers who may want to validate against their own postgres setup before merge.test/migrations/*) covers happy-path orchestration; reproducing theUNSAFE_TRANSACTIONinteraction would need either a Postgres harness or a postgres.js mock that enforces the same pool-size invariant — both out of scope for a one-line fix.Test plan
gbrain migrate run v0.29.1on a brain with NULLeffective_daterows; Phase B completes withoutUNSAFE_TRANSACTION.gbrain migrate run v0.29.1still completes normally (poolSize is ignored by PGLite perbrain-registry.ts:403comment).Commits
6a91912fix(migrate v0.29.1 Phase B): force poolSize:1 for explicit BEGIN/COMMIT path — one-line behavioral fix + import + cast pattern matchingbrain-registry.ts:406.Need help on this PR? Tag
@codesmithwith what you need.