Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(e2e): Supavisor engine read-pool E2E behind GBRAIN_SUPAVISOR_URL; docs name v0.60.186.0 and the PgBouncer opt-back-in cost (#6543)
garrytan5685edc35d6c
diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex dc4183f10d..efe9766fcc 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -781,7 +781,7 @@ transaction-mode pooler (port 6543, `?prepare=false`) a build failure usuallymeans a misrouted answer: the statement bound a value read from a row thatbelonged to another statement, so earlier reads on that pool are suspect too.Check `/health?deep=1` `transport.max_pipeline` (gbrain sends `0` there since-v0.60.185.0; `PGMAX_PIPELINE=0` forces it) and audit the window with+v0.60.186.0; `PGMAX_PIPELINE=0` forces it) and audit the window with[the pooler misroute audit](guides/pooler-misroute-audit.md). Elsewhere thecall site that bound `undefined` is a gbrain bug, so report the line.`getPoolDiagnostics().buildFailures` counts them.@@ -836,8 +836,14 @@ session_timeouts_not_applied, fix?, application_name? }`. `prepare` and(`transaction_pooler_port`, `url_prepare_false`, `gbrain_prepare_off`,`url_max_pipeline`, `env_pgmax_pipeline` or `default`): gbrain builds the readpools with `max_pipeline: 0` for a transaction-mode URL (port 6543 or-`?prepare=false`) or `GBRAIN_PREPARE=0` since v0.60.185.0, and a URL+`?prepare=false`) or `GBRAIN_PREPARE=0` since v0.60.186.0, and a URL`?max_pipeline=` or a non-empty `PGMAX_PIPELINE` always wins.+PgBouncer in transaction mode carries pipelined statements correctly, so a+PgBouncer deployment on port 6543 or with `?prepare=false` can opt back in with+`?max_pipeline=100`: on a 3-connection pool with 8 concurrent workers at about+40 ms round trip, pipelining off measured about 37% fewer statements per second+(1185 vs 1890 in 30 s); at localhost latency there was no measurable cost. Do+not opt back in behind Supavisor.`application_name: "Supavisor"` appears when the backend names Supavisor.`session_timeouts_not_applied: true` means gbrain configured a`statement_timeout` but it reads `0` through the pool (a transaction-modediff --git a/docs/architecture/postgres-cancellation.md b/docs/architecture/postgres-cancellation.mdindex a6a559ba86..6dd7598f31 100644--- a/docs/architecture/postgres-cancellation.md+++ b/docs/architecture/postgres-cancellation.md@@ -28,7 +28,7 @@ Direct PostgreSQL closes the cancellation connection after handling the request.`test/e2e/persistence-chaos.test.ts` exercises active, queued, delayed and failed cancellation; transaction siblings; stale ownership; atomic reservation settlement; reconnects; completed cursors; and real socket backpressure in both module formats. Its optional PgBouncer case requires `GBRAIN_PGBOUNCER_URL` and `GBRAIN_PGBOUNCER_DIRECT_URL`, uses a dedicated test database, and verifies another client can reuse the same server backend without receiving a late cancellation.-Keep the response-mapping, actual-settlement and unchanged persistence latency checks alongside these protocol tests. Global `max_pipeline: 1`, serializer fallbacks and blind retries are not substitutes for ownership isolation. The one place pipelining is off is transport, not cancellation: since v0.60.185.0 the read pools of a transaction-mode pooler URL (port 6543, `?prepare=false`, `GBRAIN_PREPARE=0`) are built with `max_pipeline: 0`, because a transaction pooler cannot carry pipelined statements across transaction boundaries (#6543; `db.resolveReadPoolPipeline`, the reason is in `/health?deep=1` `transport`). A URL `?max_pipeline=` or a non-empty `PGMAX_PIPELINE` still wins, and the direct pool keeps the driver default.+Keep the response-mapping, actual-settlement and unchanged persistence latency checks alongside these protocol tests. Global `max_pipeline: 1`, serializer fallbacks and blind retries are not substitutes for ownership isolation. The one place pipelining is off is transport, not cancellation: since v0.60.186.0 the read pools of a transaction-mode pooler URL (port 6543, `?prepare=false`, `GBRAIN_PREPARE=0`) are built with `max_pipeline: 0`, because a transaction pooler cannot carry pipelined statements across transaction boundaries (#6543; `db.resolveReadPoolPipeline`, the reason is in `/health?deep=1` `transport`). A URL `?max_pipeline=` or a non-empty `PGMAX_PIPELINE` still wins, and the direct pool keeps the driver default.## Worker admission and configuration shutdowndiff --git a/docs/guides/pooler-misroute-audit.md b/docs/guides/pooler-misroute-audit.mdindex 22e4e1b996..c51209698d 100644--- a/docs/guides/pooler-misroute-audit.md+++ b/docs/guides/pooler-misroute-audit.md@@ -2,7 +2,7 @@A brain whose `gbrain serve` read pool pipelined statements through atransaction-mode pooler (Supavisor or PgBouncer on port 6543, or a URL with-`?prepare=false`) before v0.60.185.0 could hand a statement another+`?prepare=false`) before v0.60.186.0 could hand a statement anotherstatement's rows (#6543). Most of the time that failed loudly(`pg_statement_build_failed` with `error=UNDEFINED_VALUE`, `pg_connection_stuck`),but a statement that bound a value from someone else's row and succeededdiff --git a/llms-full.txt b/llms-full.txtindex acc071e374..c446c3ce32 100644--- a/llms-full.txt+++ b/llms-full.txt@@ -5947,7 +5947,7 @@ transaction-mode pooler (port 6543, `?prepare=false`) a build failure usuallymeans a misrouted answer: the statement bound a value read from a row thatbelonged to another statement, so earlier reads on that pool are suspect too.Check `/health?deep=1` `transport.max_pipeline` (gbrain sends `0` there since-v0.60.185.0; `PGMAX_PIPELINE=0` forces it) and audit the window with+v0.60.186.0; `PGMAX_PIPELINE=0` forces it) and audit the window with[the pooler misroute audit](guides/pooler-misroute-audit.md). Elsewhere thecall site that bound `undefined` is a gbrain bug, so report the line.`getPoolDiagnostics().buildFailures` counts them.@@ -6002,8 +6002,14 @@ session_timeouts_not_applied, fix?, application_name? }`. `prepare` and(`transaction_pooler_port`, `url_prepare_false`, `gbrain_prepare_off`,`url_max_pipeline`, `env_pgmax_pipeline` or `default`): gbrain builds the readpools with `max_pipeline: 0` for a transaction-mode URL (port 6543 or-`?prepare=false`) or `GBRAIN_PREPARE=0` since v0.60.185.0, and a URL+`?prepare=false`) or `GBRAIN_PREPARE=0` since v0.60.186.0, and a URL`?max_pipeline=` or a non-empty `PGMAX_PIPELINE` always wins.+PgBouncer in transaction mode carries pipelined statements correctly, so a+PgBouncer deployment on port 6543 or with `?prepare=false` can opt back in with+`?max_pipeline=100`: on a 3-connection pool with 8 concurrent workers at about+40 ms round trip, pipelining off measured about 37% fewer statements per second+(1185 vs 1890 in 30 s); at localhost latency there was no measurable cost. Do+not opt back in behind Supavisor.`application_name: "Supavisor"` appears when the backend names Supavisor.`session_timeouts_not_applied: true` means gbrain configured a`statement_timeout` but it reads `0` through the pool (a transaction-modediff --git a/test/e2e/supavisor-read-pool.test.ts b/test/e2e/supavisor-read-pool.test.tsnew file mode 100644index 0000000000..1fc676824c--- /dev/null+++ b/test/e2e/supavisor-read-pool.test.ts@@ -0,0 +1,61 @@+/**+ * #6543 (A3): through Supavisor's transaction mode, pipelined statements that+ * span transaction boundaries come back with another statement's rows or hang+ * (lane A: 13-22 wrong-row answers in 20 s on 8 workers over a pool of 3).+ * gbrain's engine read pool on a port-6543 URL is built with+ * `max_pipeline: 0`; this file drives that engine pool with concurrent+ * autocommit and transaction statements and requires every statement to read+ * its own rows with no connection errors.+ *+ * Runs only when GBRAIN_SUPAVISOR_URL names a Supavisor transaction-mode URL+ * (port 6543) for a test database; scripts/run-e2e.sh passes it through.+ */+import { describe, expect, test } from 'bun:test';+import { PostgresEngine } from '../../src/core/postgres-engine.ts';+import { assertSafeE2eDatabaseUrl } from '../helpers/db-guard.ts';+import { withEnv } from '../helpers/with-env.ts';++const supavisor = process.env.GBRAIN_SUPAVISOR_URL;++describe.skipIf(!supavisor)('#6543 engine read pool through Supavisor transaction mode', () => {+ test('the read pool does not pipeline, and concurrent statements each read their own rows', async () => {+ assertSafeE2eDatabaseUrl(supavisor!);+ await withEnv({ PGMAX_PIPELINE: undefined, GBRAIN_PREPARE: undefined, GBRAIN_DISABLE_DIRECT_POOL: '1' }, async () => {+ const engine = new PostgresEngine();+ await engine.connect({ engine: 'postgres', database_url: supavisor!, poolSize: 3 });+ try {+ const sql = engine.sql;+ expect((sql as unknown as { options: { max_pipeline: number } }).options.max_pipeline).toBe(0);+ let ok = 0;+ const wrong: string[] = [];+ const errors: string[] = [];+ const check = async (label: string, run: () => Promise<boolean>) => {+ try { if (await run()) ok++; else wrong.push(label); } catch (e) { errors.push(String((e as { code?: string }).code ?? (e as Error).message)); }+ };+ const deadline = Date.now() + 8_000;+ await Promise.all(Array.from({ length: 8 }, async (_, w) => {+ for (let i = 0; Date.now() < deadline; i++) {+ const tag = `w${w}-${i}`;+ const n = (w * 1_000_003 + i) % 2_000_000_000;+ await Promise.all([+ check('param', async () => { const [r] = await sql`SELECT ${tag}::text AS who, ${n}::int AS n`; return r?.who === tag && r?.n === n; }),+ check('shape', async () => { const [r] = await sql.unsafe(`SELECT $1::text AS who, ${i} AS shape`, [tag]); return r?.who === tag && Number(r?.shape) === i; }),+ check('tx', async () => {+ const rows = await sql.begin(async t => {+ const [a] = await t`SELECT ${tag}::text AS who`;+ if (a?.who !== tag) return null;+ return t`SELECT ${tag + 'b'}::text AS who`;+ });+ return Array.isArray(rows) && rows[0]?.who === tag + 'b';+ }),+ ]);+ }+ }));+ expect({ wrong: wrong.length, errors }).toEqual({ wrong: 0, errors: [] });+ expect(ok).toBeGreaterThan(100);+ } finally {+ await engine.disconnect();+ }+ });+ }, 60_000);+});diff --git a/test/helpers/operator-env-policy.ts b/test/helpers/operator-env-policy.tsindex ca5fc2abb9..da491843c3 100644--- a/test/helpers/operator-env-policy.ts+++ b/test/helpers/operator-env-policy.ts@@ -22,6 +22,7 @@ export const KEEP_EXACT: ReadonlySet<string> = new Set(['GBRAIN_NO_SNAPSHOT', // cold-path opt-out must survive this preload and reach CLI children'GBRAIN_PGBOUNCER_URL', // explicit pooled test target supplied by ci-local'GBRAIN_PGBOUNCER_DIRECT_URL', // admin connection used to create the isolated pooler test DB+ 'GBRAIN_SUPAVISOR_URL', // explicit Supavisor transaction-mode test target (#6543 supavisor-read-pool E2E)'GBRAIN_COMPILED_BIN', // heavy-lane compile-once binary (agent-harness.ts ensureCompiledGbrain)'GBRAIN_AUDIT_DIR', // audit-dir-preload honors a wrapper pre-set (inspect audit output after a run)'GBRAIN_SYNC_FAILURES_DIR', // same wrapper pre-set contract in sync-failures-preload