Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): keep the pooler code as the log reason; add cause=pool_exhausted and the pool-sizing fix ahead of the writer-status pointer
garrytanfeb475cbf5c0
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 356097a7f0..c584f44180 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1083,7 +1083,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: 'TBD', text: 'A sync pass\'s checkpoint that its pass can no longer publish (the pass ended, or another pass started) is now refused `sync_pass_superseded` instead of `revision_conflict`: it records no managed-sync failure, reads `superseded` in `gbrain sources writer failures` and does not count as an unresolved terminal failure, and a pass that stops with its checkpoint still pending reports `managedWrite.disposition: superseded` instead of "Re-run the same sync options to resume this request".' },{ since: 'TBD', text: '`gbrain sync status` also reports `last_sync_at` (when the source last converged: every path of its target imported, deleted or held) and `last_committed_at` (when a managed sync write of the source last committed), and the human line says when the source is still importing since it last converged, so a long catch-up no longer reads as a day stale. Its `freshness` block adds `waiting_commits`, the commits on HEAD not synced yet; `unresolved_commits` still counts only synced commits that git cannot date on this host.' },{ since: 'TBD', text: 'A serve sync pass that stops short now names why on its `[serve-sync] done` line: `stop=<reason>`, the write that stopped it (`write_error`, `write_reason`, `request`), the failed files by code, or `cause=unrecorded` when the pass recorded none, followed by a `next` line with the command to run. Before, a blocked pass printed only `status=blocked_by_failures`.' },- { since: 'TBD', text: 'A managed write that meets a pooler\'s client cap (Supavisor `EMAXCONNSESSION` in session mode, "too many clients already") is now released as contention and retried, like SQLSTATE 53300, instead of failing terminally as `storage_error` and stopping the sync drain `blocked_by_failures`. The persistence log names it `reason=pool_exhausted`, with the pool-sizing fix in place of the generic writer-status pointer.' },+ { since: 'TBD', text: 'A managed write that meets a pooler\'s client cap (Supavisor `EMAXCONNSESSION` in session mode, "too many clients already") is now released as contention and retried, like SQLSTATE 53300, instead of failing terminally as `storage_error` and stopping the sync drain `blocked_by_failures`. The persistence log adds `cause=pool_exhausted` beside the code the pooler sent, with the pool-sizing fix in place of the generic writer-status pointer.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/persistence/consumer.ts b/src/core/persistence/consumer.tsindex 124f75df86..26b31b3938 100644--- a/src/core/persistence/consumer.ts+++ b/src/core/persistence/consumer.ts@@ -872,16 +872,16 @@ export class PersistenceConsumer implements PersistenceConsumerLike {return;}const code = (error as { code?: unknown })?.code;- // GBRA-133: a pooler's client cap names itself (and its fix) instead of the pooler's generic code.- this.lastError = { code: connectionCapFailure(error) ? 'pool_exhausted' : typeof code === 'string' && (/^[A-Z0-9]{5}$/.test(code) || isWriteErrorCode(code)) ? code : 'storage_error', at: new Date().toISOString(),+ this.lastError = { code: typeof code === 'string' && (/^[A-Z0-9]{5}$/.test(code) || isWriteErrorCode(code)) ? code : 'storage_error', at: new Date().toISOString(),...(this.lastPhaseError ? { phase: this.lastPhaseError } : {}) };if (this.opts.onError) this.opts.onError(error);- else this.log(this.lastPhaseError ?? 'execution', this.lastError.code, errorDetail(error), this.lastPhaseError ? this.lastPhaseTiming : undefined, row);+ // GBRA-133: a pooler's client cap names itself and its fix beside the code the pooler sent.+ else this.log(this.lastPhaseError ?? 'execution', this.lastError.code, errorDetail(error), this.lastPhaseError ? this.lastPhaseTiming : undefined, row, connectionCapFailure(error));this.lastPhaseError = undefined;this.lastPhaseTiming = undefined;}/** #6543 F1: a line about one request is throttled per request (30 s per phase and code); other lines keep the shared throttle. */- private log(phase: string, code: string, detail?: string, timing = '', row?: WriteRequest): void {+ private log(phase: string, code: string, detail?: string, timing = '', row?: WriteRequest, poolCap = false): void {const key = `${phase}:${code}`, at = Date.now();if (row) {const requestKey = `${key}:${row.id}`;@@ -893,9 +893,9 @@ export class PersistenceConsumer implements PersistenceConsumerLike {if (this.lastLog && (at - this.lastLog.at < 1000 || this.lastLog.key === key && at - this.lastLog.at < 30_000)) return;this.lastLog = { key, at };}- if (!this.opts.onError) process.stderr.write(`[persistence] phase=${phase} reason=${code}${detail ? ` message="${detail}"` : ''}${timing}${row ? requestLogFields(row) : ''}`- + `; unfinished work remains tracked; fix: ${code === 'pool_exhausted' ? 'every gbrain process on this database shares the pooler\'s client limit: run fewer long-running processes (share one gbrain serve --http) or raise the limit; docs: docs/ENGINES.md#pool-sizing'- : 'gbrain sources writer status --json; docs: docs/ENGINES.md#persistence-consumer-log'}\n`);+ if (!this.opts.onError) process.stderr.write(`[persistence] phase=${phase} reason=${code}${poolCap ? ' cause=pool_exhausted' : ''}${detail ? ` message="${detail}"` : ''}${timing}${row ? requestLogFields(row) : ''}`+ + `; unfinished work remains tracked; fix: ${poolCap ? 'every gbrain process on this database shares the pooler\'s client limit, so run fewer long-running ones (share one gbrain serve --http) or raise the limit (docs/ENGINES.md#pool-sizing), then ' : ''}`+ + 'gbrain sources writer status --json; docs: docs/ENGINES.md#persistence-consumer-log\n');}/** #5373: tracks work that outlived its claim until it settles; the returned promise never rejects. *//**diff --git a/test/persistence-consumer-log.test.ts b/test/persistence-consumer-log.test.tsindex 0ca4d9ecff..d181f95267 100644--- a/test/persistence-consumer-log.test.ts+++ b/test/persistence-consumer-log.test.ts@@ -47,6 +47,9 @@ describe('persistence consumer stderr line', () => {const line = stderr.find(entry => entry.startsWith('[persistence] phase='));expect(line).toBeDefined();expect(line).toContain('reason=53300');+ // GBRA-133: the pooler's client cap names itself and the pool-sizing fix ahead of the writer-status pointer.+ expect(line).toContain('reason=53300 cause=pool_exhausted ');+ expect(line).toContain('docs/ENGINES.md#pool-sizing), then gbrain sources writer status --json');expect(line).toContain('message="(EMAXCONNSESSION) max clients reached in session mode - pool_size: 15 for ');expect(line).not.toContain('secret-pw');expect(line).toContain('fix: gbrain sources writer status --json');