fix: v0.15.4 — PgBouncer prepare:false for Supabase transaction pooler (closes #284, #286, #270)#301
Merged
Merged
Conversation
…ath` On bun-installed trees, process.execPath is the bun runtime itself. `bun extract links ...` got reinterpreted as `bun run extract` and crashed the upgrade mid-Phase B. The canonical shim on PATH already wraps the right runtime+entrypoint; trust it. Regression-guarded by test/migrations-v0_13_0.test.ts which greps the source for `process.execPath` and `bun` invocations. This was Bug 1 of tonight's v0.13 → v0.14 upgrade-night postmortem.
argv[1] check used to short-circuit on /cli.ts, so bun-source installs got a .ts path back. spawn() then failed EACCES because TypeScript source isn't executable, and autopilot silently lost its worker. Reordered probes: which gbrain (shim) first, then compiled execPath, then argv[1] only if it ends in /gbrain. Deleted the .ts branch entirely — no valid case exists. Rewrote the existing test that enshrined the buggy .ts return. Critical regression guard: resolver MUST NEVER return a .ts path across any combination of argv[1] + execPath + shim availability. This was Bug 4 of tonight's v0.13 → v0.14 upgrade-night postmortem.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ade-bugs # Conflicts: # CHANGELOG.md # package.json
Adds port-6543 auto-detect with a 4-level precedence chain: GBRAIN_PREPARE env var → ?prepare= URL param → port auto-detect → default. Wires into the module-singleton connect() so the main CLI path no longer hits "prepared statement does not exist" against Supabase transaction pooler. Returns boolean | undefined; undefined means omit the option and let postgres.js default (true) stand. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Without this, \`gbrain jobs work\` against a Supabase pooler URL hits "prepared statement does not exist" under load even after the module singleton was fixed in db.ts. Community PR #270 (@notjbg) caught this second path that #284 had missed. Reuses the shared helper, no regex duplication. Co-Authored-By: Jonah Berg <jonah.berg.g@gmail.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
URL-only check (no DB roundtrip) that reads the configured URL via loadConfig() and flags the footgun: port 6543 with prepared statements still enabled. Warns with the exact env override (GBRAIN_PREPARE=false) and URL-query alternative (?prepare=false). Works for both the module singleton and worker-instance engines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- test/resolve-prepare.test.ts: 11 cases covering env override, URL query param, port auto-detect, malformed URLs, postgres:// scheme, URL-encoded credentials. Uses bun:test — #284's original vitest file would never have run in this project. - test/postgres-engine.test.ts: new source-level grep case asserting the worker-pool connect() branch calls db.resolvePrepare(url) and includes a typeof prepare === 'boolean' check. Mirrors the existing SET LOCAL regression guard. If anyone rips out the wiring, the build fails before shipping starts dropping rows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Thanks! |
orendi84
added a commit
to orendi84/gbrain
that referenced
this pull request
Apr 22, 2026
Checks process.execPath before process.argv[1] so compiled Bun SFX binaries don't try to spawn the virtual /$bunfs/root/gbrain path that only exists inside the running process. Upstream garrytan/gbrain PR garrytan#301 (commit fcf40a1, v0.15.4) landed a canonical fix for the same bug - revert this commit after merging upstream/master. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Combines three open PRs (#284 Wintermute, #286 Codex one-liner, #270 community @notjbg) into one clean fix for the Supabase transaction-mode PgBouncer bug that was silently dropping rows during sync.
Problem: On port 6543, PgBouncer recycles the backend connection between queries. postgres.js caches prepared statements per-client, so a statement prepared on connection A fails when routed to connection B. Under sustained gbrain load (sync, extract, embed, autopilot,
gbrain jobs work) this surfaces asprepared statement "..." does not existin logs and 50-200 missing rows in 4,500-page syncs. Exit code is 0, so nobody notices for weeks.Fix:
resolvePrepare(url)helper with 4-level precedence (GBRAIN_PREPAREenv →?prepare=URL → port-6543 auto-detect → default). Wired into both connection paths: the module singleton insrc/core/db.tsAND the worker-instance pool insrc/core/postgres-engine.ts. Community PR #270 (@notjbg) caught the second path; #284 had missed it.This PR also carries the prior v0.15.3 commits on branch
The branch history includes the v0.15.3 ship from earlier today (Bug 1 migration shell-out + Bug 4 autopilot resolver). Reviewers: the v0.15.4 commits start at
b1beeffand end at2cdbcd7.Bisectable commits (v0.15.4)
b1beeff1a59c229a27b9430946952cdbcd7Test Coverage
Tests:
bun test→ 1826 pass, 179 skip (E2E DATABASE_URL not set), 0 fail. 17 new tests added.Pre-Landing Review
Two rounds:
/plan-eng-review(Claude eng subagent): 1 issue found, 1 resolved. Caught that addingpooler.supabase.comhostname detection from fix(db): disable prepared statements on Supabase pooler to prevent cross-connection statement-cache errors #270's regex would over-disable session-mode users (port 5432 on the pooler host). Plan changed to port-only detection./codex(plan review): 12 issues raised, 7 fixed in the plan before implementation. Caught the real landmine: CHANGELOG.md already had[0.15.3]dated today andpackage.jsonwas at0.15.3, so the plan (and this PR) target v0.15.4. Also pinnedresolvePreparereturn type, tightened doctor-check framing, added row-count parity to manual verification.Both reviews logged via gstack; diff matches the approved plan.
Plan Completion
All 7 tasks from the plan at
~/.claude/plans/system-instruction-you-are-working-gentle-goblet.mdare DONE:b1beeff)1a59c22)9a27b94)3094695)3094695)2cdbcd7)Supersedes
This PR supersedes three open PRs. Post-merge, close them with attribution:
prepare: falsewould cost direct-Postgres users plan caching.Co-Authored-By: Jonah Bergtrailer on1a59c22and the CHANGELOG entry.Test plan
bun test test/resolve-prepare.test.ts(11/11 pass)bun test test/postgres-engine.test.ts(6/6 pass, was 5 before)bun testfull suite (1826 pass, 0 fail)scripts/check-progress-to-stdout.sh+scripts/check-jsonb-pattern.sh(CI guards pass)gbrain doctorshowspgbouncer_prepare: okgbrain syncrow count matches source manifest (no silent drops)🤖 Generated with Claude Code