Skip to content

fix: detect PgBouncer transaction-mode pooler and set GBRAIN_PREPARE=true#1591

Open
mikeangstadt wants to merge 1 commit into
garrytan:mainfrom
closedloop-ai:fix/1435-pgbouncer-transaction-mode-search
Open

fix: detect PgBouncer transaction-mode pooler and set GBRAIN_PREPARE=true#1591
mikeangstadt wants to merge 1 commit into
garrytan:mainfrom
closedloop-ai:fix/1435-pgbouncer-transaction-mode-search

Conversation

@mikeangstadt
Copy link
Copy Markdown

Summary

Fixes #1435/sync-gbrain capability check fails under PgBouncer transaction mode because gbrain search silently returns no results when prepared statements are disabled.

  • lib/gbrain-exec.ts: buildGbrainEnv() now detects port 6543 in DATABASE_URL and auto-sets GBRAIN_PREPARE=true in the env for all gbrain spawns. Single chokepoint fix — every gstack-originated gbrain call inherits it. Callers can override with GBRAIN_PREPARE=false.
  • sync-gbrain/SKILL.md{,.tmpl}: Capability check exports GBRAIN_PREPARE=true and retries search up to 3x with 1s delay for async index propagation under connection pooling.
  • bin/gstack-gbrain-detect: Surfaces gbrain_pooler_mode ("transaction" | "session" | null) in the preamble probe JSON for downstream skill visibility.

Test plan

  • New unit tests for isTransactionModePooler() — port 6543, 5432, no-port, unparseable, postgres:// scheme
  • New unit tests for buildGbrainEnv() GBRAIN_PREPARE auto-detection — pooler URL sets it, session URL doesn't, caller opt-out respected, already-matching URL still sets it
  • Existing buildGbrainEnv tests still pass (DATABASE_URL seeding behavior unchanged)
  • Manual: on a PgBouncer transaction-mode setup, run /sync-gbrain and verify the capability check passes and ## GBrain Search Guidance block is written to CLAUDE.md

Continuous collaboration, powered by ClosedLoop.AI (GitHub)

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

…true (garrytan#1435)

When gbrain connects through a PgBouncer transaction-mode pooler (port
6543), it auto-disables prepared statements. This breaks `gbrain search`
silently — the /sync-gbrain capability check fails and the GBrain Search
Guidance block never gets written to CLAUDE.md.

Three-layer fix:

1. **lib/gbrain-exec.ts** — `buildGbrainEnv()` now detects port 6543 in
   the effective DATABASE_URL and sets `GBRAIN_PREPARE=true` in the env
   passed to every gbrain spawn. This is the single chokepoint — all
   gstack gbrain invocations inherit the fix. Caller can opt out with
   `GBRAIN_PREPARE=false`.

2. **sync-gbrain/SKILL.md{,.tmpl}** — capability check now exports
   `GBRAIN_PREPARE=true` explicitly and retries search up to 3x with 1s
   delay for async index propagation under connection pooling.

3. **bin/gstack-gbrain-detect** — surfaces `gbrain_pooler_mode` field
   ("transaction" | "session" | null) in the preamble probe JSON so
   /setup-gbrain and /sync-gbrain can advise users about pooler state.

Closes garrytan#1435

Built with [ClosedLoop.AI](https://closedloop.ai) | [GitHub](https://github.com/closedloop-ai/claude-plugins)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/sync-gbrain capability check fails under PgBouncer transaction mode (put succeeds, search returns 'No results')

1 participant