mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-21 09:10:11 +02:00
fix: detect PgBouncer transaction-mode pooler and set GBRAIN_PREPARE=true (#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 #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>
This commit is contained in:
+18
-6
@@ -905,13 +905,25 @@ Capability check (per /plan-eng-review §6):
|
||||
|
||||
```bash
|
||||
SLUG="_capability_check_$$"
|
||||
CAPABILITY_OK=0
|
||||
if [ -f ~/.gbrain/config.json ] && \
|
||||
gbrain --version 2>/dev/null | grep -q '^gbrain ' && \
|
||||
echo "ping" | gbrain put "$SLUG" >/dev/null 2>&1 && \
|
||||
gbrain search "ping" 2>/dev/null | grep -q "$SLUG"; then
|
||||
CAPABILITY_OK=1
|
||||
else
|
||||
CAPABILITY_OK=0
|
||||
gbrain --version 2>/dev/null | grep -q '^gbrain '; then
|
||||
# GBRAIN_PREPARE=true ensures prepared statements stay enabled when
|
||||
# connecting through a PgBouncer transaction-mode pooler (port 6543).
|
||||
# Without it, search silently returns no results (#1435).
|
||||
export GBRAIN_PREPARE=true
|
||||
if echo "ping" | gbrain put "$SLUG" >/dev/null 2>&1; then
|
||||
# Retry search up to 3 times with 1s delay — under transaction-mode
|
||||
# pooling the search index may not be visible on the next connection
|
||||
# immediately after the put.
|
||||
for _attempt in 1 2 3; do
|
||||
if gbrain search "ping" 2>/dev/null | grep -q "$SLUG"; then
|
||||
CAPABILITY_OK=1
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
fi
|
||||
gbrain delete "$SLUG" 2>/dev/null || true
|
||||
```
|
||||
|
||||
@@ -185,13 +185,25 @@ Capability check (per /plan-eng-review §6):
|
||||
|
||||
```bash
|
||||
SLUG="_capability_check_$$"
|
||||
CAPABILITY_OK=0
|
||||
if [ -f ~/.gbrain/config.json ] && \
|
||||
gbrain --version 2>/dev/null | grep -q '^gbrain ' && \
|
||||
echo "ping" | gbrain put "$SLUG" >/dev/null 2>&1 && \
|
||||
gbrain search "ping" 2>/dev/null | grep -q "$SLUG"; then
|
||||
CAPABILITY_OK=1
|
||||
else
|
||||
CAPABILITY_OK=0
|
||||
gbrain --version 2>/dev/null | grep -q '^gbrain '; then
|
||||
# GBRAIN_PREPARE=true ensures prepared statements stay enabled when
|
||||
# connecting through a PgBouncer transaction-mode pooler (port 6543).
|
||||
# Without it, search silently returns no results (#1435).
|
||||
export GBRAIN_PREPARE=true
|
||||
if echo "ping" | gbrain put "$SLUG" >/dev/null 2>&1; then
|
||||
# Retry search up to 3 times with 1s delay — under transaction-mode
|
||||
# pooling the search index may not be visible on the next connection
|
||||
# immediately after the put.
|
||||
for _attempt in 1 2 3; do
|
||||
if gbrain search "ping" 2>/dev/null | grep -q "$SLUG"; then
|
||||
CAPABILITY_OK=1
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
fi
|
||||
gbrain delete "$SLUG" 2>/dev/null || true
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user