Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): GBRAIN_CONSUMER_DIRECT_LANE=0 keeps the consumer's scans on the ordinary pool; the phase-liveness BEGIN cases set it (#6317)

garrytaneb363d7e2807
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37e22d9c78..2f83a962bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ gbrain config set persistence.single_consumer false # brain-wide: every p
| `gbrain sources status` and `writer status --json` | `data_moving`, `not_moving_since` and `movement_state` per managed source (`parked` for a cursor left between cron runs with no live consumer), `sync_running` beside them, and the exact writer-status command printed beside `data_moving: false`. `writer status` ends each running claim in one `claim.next` (`claim_running`, `claim_overdue`, `claim_lapsed`) and lists `host.consumers` (pid, kind, mode, age, pool `{checked_out, max, waiters}`); a stalled claim carries `last_sql {label, age_ms}` (first keyword plus table, never text). |
| `gbrain doctor` | `managed_sync_not_moving` (warn, counted against the score; `parked` is not), `two_consumers_on_host` (two resident kinds both alive over 30 s), `consumers_without_heartbeat` (a claim owner from an older release), `host_identity_mismatch` (this process's `host.json` differs from the binding owner's on the same machine; names both files, the `HOME`/`GBRAIN_HOME` each was minted under, and the `GBRAIN_HOME` to set). Each has a structured fix, `gbrain errors <code>` and a troubleshooting row. |
| `gbrain upgrade` and `post-upgrade` | End by printing the supervisor's step: restart `serve` and the workers, then `gbrain sources writer movement`. The new command waits `max(300 s, preparation budget + 60 s)` and judges each source `moved`, `current`, `held` (exit 0 with the hold's route), `within_allowance` (exit 0, `retry_after_ms`), `not_moving` (exit 1, `managed_sync_not_moving`) or `unknown`. `/health` stays liveness-only. |
+| The consumer's own round-trips | With `GBRAIN_DIRECT_DATABASE_URL` (or the Supabase-derived direct URL) set, the consumer's tick statements run on the direct/session-mode route beside the claims, renewals and heartbeat, so a transaction-mode pooler never sits between the owner and its bookkeeping; `writer status --json` shows `connection.lane` and `pooler_mode`, one loud `[persistence] phase=start reason=transaction_pooler` line prints when only a `prepare=false` URL exists, and `GBRAIN_CONSUMER_DIRECT_LANE=0` keeps the scans on the ordinary pool. |
| `[persistence]` log lines | The `preparation` deadline, ceiling and hold lines, the `owner_lapsed promoted_to_consumer` line and the drain's `drain_stalled` summary print the same step / waiting_on / last_sql triple, so a log tail names a stall without a command. |
| `host.json` | Stays `version: 1`; a file minted from now on carries `minted_under: {home, gbrain_home, hostname, machine_id}`. Existing files are never rewritten. |
diff --git a/docs/ENGINES.md b/docs/ENGINES.md
index 7117ae0cc0..6feb4e2ce6 100644
--- a/docs/ENGINES.md
+++ b/docs/ENGINES.md
@@ -602,6 +602,14 @@ long-running processes x GBRAIN_POOL_SIZE
When the sum does not fit, run fewer long-running processes (for example one
shared `gbrain serve --http` instead of one stdio `serve` per agent session),
or raise the pooler's limit. Do not lower a long-running process below 6.
+
+With a direct route configured, the persistence consumer's own tick
+statements (idle probe, switch read, recovery and expired-claim scans,
+capacity marking) take the direct pool beside the claims, renewals and the
+heartbeat, so a transaction-mode pooler never sits between the owner and its
+bookkeeping (#6317; `gbrain sources writer status --json` shows
+`connection.lane: direct`). `GBRAIN_CONSUMER_DIRECT_LANE=0` keeps those scans
+on the ordinary pool when the direct pool is too small for them.
`pool_exhausted` errors (SQLSTATE `53300`) and the
[serve boot timeout](#serve-boot-timeout) print this guidance.
diff --git a/llms-full.txt b/llms-full.txt
index 25ae03c50a..33de39b663 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -5649,6 +5649,14 @@ long-running processes x GBRAIN_POOL_SIZE
When the sum does not fit, run fewer long-running processes (for example one
shared `gbrain serve --http` instead of one stdio `serve` per agent session),
or raise the pooler's limit. Do not lower a long-running process below 6.
+
+With a direct route configured, the persistence consumer's own tick
+statements (idle probe, switch read, recovery and expired-claim scans,
+capacity marking) take the direct pool beside the claims, renewals and the
+heartbeat, so a transaction-mode pooler never sits between the owner and its
+bookkeeping (#6317; `gbrain sources writer status --json` shows
+`connection.lane: direct`). `GBRAIN_CONSUMER_DIRECT_LANE=0` keeps those scans
+on the ordinary pool when the direct pool is too small for them.
`pool_exhausted` errors (SQLSTATE `53300`) and the
[serve boot timeout](#serve-boot-timeout) print this guidance.
diff --git a/src/core/persistence/consumer-lane.ts b/src/core/persistence/consumer-lane.ts
index 88d6ed0392..a3d7b7a527 100644
--- a/src/core/persistence/consumer-lane.ts
+++ b/src/core/persistence/consumer-lane.ts
@@ -21,6 +21,12 @@
* the consumer logs one loud line at start and `status()` reports
* `connection.pooler_mode: 'transaction'`, so an operator sees the exposure in
* `gbrain sources writer status --json` before the first stall.
+ *
+ * `GBRAIN_CONSUMER_DIRECT_LANE=0` keeps the tick statements on the ordinary
+ * pool even with a direct route (the claims, renewals and heartbeat still take
+ * it): the escape hatch when the direct pool is too small for the scans, and
+ * what the phase-liveness tests set to exercise the claim's BEGIN as the first
+ * direct statement.
*/
import type { BrainEngine } from '../engine.ts';
import { registerEngineView, viewedEngine } from './switches.ts';
@@ -43,7 +49,7 @@ export function consumerConnectionRoute(engine: BrainEngine): ConsumerConnection
if (engine.kind !== 'postgres') return { lane: 'pool', pooler_mode: 'not_postgres' };
const routed = engine as RoutedEngine;
let direct = false, directHost: string | undefined, prepare: boolean | undefined;
- try { direct = routed.connectionManager?.isDualPoolActive() === true; directHost = direct ? routed.connectionManager?.describeMode().direct_host : undefined; } catch { direct = false; }
+ try { direct = process.env.GBRAIN_CONSUMER_DIRECT_LANE !== '0' && routed.connectionManager?.isDualPoolActive() === true; directHost = direct ? routed.connectionManager?.describeMode().direct_host : undefined; } catch { direct = false; }
try { prepare = routed.sql?.options?.prepare; } catch { prepare = undefined; }
return { lane: direct ? 'direct' : 'pool', pooler_mode: prepare === false ? 'transaction' : prepare === undefined ? 'unknown' : 'session_or_direct', ...(directHost ? { direct_host: directHost } : {}) };
}
diff --git a/test/e2e/persistence-phase-liveness.test.ts b/test/e2e/persistence-phase-liveness.test.ts
index 0f5f3e62e8..6d20da05fc 100644
--- a/test/e2e/persistence-phase-liveness.test.ts
+++ b/test/e2e/persistence-phase-liveness.test.ts
@@ -376,7 +376,8 @@ describe.skipIf(!url)('PostgreSQL persistence phase cancellation', () => {
}), 30000);
test('a queued direct-pool BEGIN stays tracked and cannot prepare after shutdown', () => fixture(async ({ engine, databaseUrl }, config) => {
- await withEnv({ GBRAIN_DIRECT_DATABASE_URL: databaseUrl, GBRAIN_DISABLE_DIRECT_POOL: '0', GBRAIN_DIRECT_POOL_SIZE: '1' }, async () => {
+ // #6317: the tick's scans would otherwise take the direct lane first (consumer-lane.ts); this case is about the claim's BEGIN.
+ await withEnv({ GBRAIN_DIRECT_DATABASE_URL: databaseUrl, GBRAIN_DISABLE_DIRECT_POOL: '0', GBRAIN_DIRECT_POOL_SIZE: '1', GBRAIN_CONSUMER_DIRECT_LANE: '0' }, async () => {
const worker = new PostgresEngine();
await worker.connect({ database_url: databaseUrl, poolSize: 4 });
const direct = await worker.connectionManager!.ddl();
@@ -446,7 +447,7 @@ describe.skipIf(!url)('PostgreSQL persistence phase cancellation', () => {
directUrl.port = String((gateway.address() as { port: number }).port);
const release = () => { released = true; for (const resume of pending.splice(0)) resume(); };
try {
- await withEnv({ GBRAIN_DIRECT_DATABASE_URL: directUrl.toString(), GBRAIN_DISABLE_DIRECT_POOL: '0', GBRAIN_DIRECT_POOL_SIZE: '1' }, async () => {
+ await withEnv({ GBRAIN_DIRECT_DATABASE_URL: directUrl.toString(), GBRAIN_DISABLE_DIRECT_POOL: '0', GBRAIN_DIRECT_POOL_SIZE: '1', GBRAIN_CONSUMER_DIRECT_LANE: '0' }, async () => {
const worker = new PostgresEngine();
await worker.connect({ database_url: databaseUrl, poolSize: 4 });
expect(connections).toBe(0);