Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(cli): a remote MCP failure is not a database access error (Bun 1.4.3 fetch wording)
garrytanae4d5afd7a3c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9d6e099d5b..0544212bd8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,7 +14,7 @@ identifiers and attribution are available in the pre-removal Git revision**CI and the release build move to Bun 1.4.3, which carries the fix for the spawnSync hang that poisoned whole test shards (#6586).** On Bun 1.4.0 to 1.4.2, a garbage-collection finalizer that runs while `Bun.spawnSync` waits can leave the runtime's private spawnSync loop miscounted for the rest of the process (oven-sh/bun#34069). After that, a synchronous child spawn may never notice its child exit. A spawn with a timeout comes back `ETIMEDOUT` even though the child finished, and one without a timeout spins until the test deadline kills it. Run 38335527492 hit this twice: `test (2)` hung in `test/managed-sync-pinned-reads.test.ts` and was cancelled, while the identical code on the identical file order passed on master and on #6576. Bun 1.4.3 (released 2026-10-10) contains upstream commit 13a98b0. `compare/bun-v1.4.3...13a98b0` reports `behind`, which means the release already has the commit. The supported install floor stays at Bun 1.4.0.-Three gaps the hang exposed are fixed too. A managed sync no longer mistakes a timed-out `git` child for a lost database connection. CI names the signature as soon as it appears instead of only when the test process exits. And the pinned-reads test no longer keeps running behind the next test after it times out.+Three gaps the hang exposed are fixed too, plus one Bun 1.4.3 change in `fetch` error wording that made a thin client's unreachable remote host read as a database error. A managed sync no longer mistakes a timed-out `git` child for a lost database connection. CI names the signature as soon as it appears instead of only when the test process exits. And the pinned-reads test no longer keeps running behind the next test after it times out.### Itemized changes@@ -22,6 +22,7 @@ Three gaps the hang exposed are fixed too. A managed sync no longer mistakes a t- **`isConnectionDrop` (`src/core/persistence/sync-drain.ts`):** a child-process error is no longer a dropped database connection. That covers Node's `syscall: 'spawnSync git'` and any message of the form `spawn(Sync) <cmd> E…`. Before, the drain's git reads coming back `spawnSync git ETIMEDOUT` printed "database connection dropped", reconnected the database, and counted a strike toward `connection_lost`, which pointed the operator at the wrong component. Now the error takes the drain's ordinary transient retry, with no reconnect and no connection line. The test throws a real `spawnSync` timeout and a synthetic `spawnSync git ETIMEDOUT` through `runDrain`. It fails on the old code, where the first is classified as a drop.- **`scripts/capture-test-log.ts`:** two live notes, each printed once to stderr and appended to the job's step summary as soon as its evidence arrives. The first, `bun_spawnsync_poisoned?`, fires on the first `spawnSync <cmd> ETIMEDOUT` line and names its file. The second is the existing `bun_spawnsync_poisoned` verdict, the moment it holds. Before, the classifier ran only when the test process exited, so the cancelled #6578 job never named the signature. The tests replay that job's log shape and check a still-running capture's summary. Both fail on the old script.- **`test/managed-sync-pinned-reads.test.ts`:** `afterEach` aborts the running arm's sync (`performSync` now gets the arm's signal), waits up to 20 s for the arm to unwind so its PATH override is gone, and prints the arm's Git calls: how long each took and which never finished. Each counter wraps the Git and PATH the file loaded with, never another arm's shim. Before, a timed-out test left PATH on its counting `git` shim. It also kept spawning Git behind the next test and threw `ENOENT` into the temp home that `afterAll` had already removed. The shim now records a start and end line per call (`calls()` counts are unchanged). Forced probe: with the test deadline cut to 4 s and a `git` that sleeps 200 ms, a trailing test that checks PATH and the arm's Git log fails on the old file and passes on the new one.+- **A thin client's refused remote MCP host no longer reads as a database error on Bun 1.4.3 (`src/cli/cli-error.ts`).** Bun 1.4.3's `fetch` reports a refused connection as `ECONNREFUSED: Unable to connect…` with code `ECONNREFUSED`, where 1.4.2 said `Unable to connect…` with code `ConnectionRefused`. The fatal CLI seam ran every error through the database access classifier first. So on 1.4.3, a thin client whose remote host was down printed `GBRAIN_DB_ACCESS conn_refused` and "switch to the transaction pooler … Run: gbrain db-repair" instead of `Error [unavailable] … Fix: gbrain remote doctor`. The first full gate on 1.4.3 caught it in `test/cli-thin-client-refusal-matrix.test.ts`. A `RemoteMcpError` now skips the database classifier, and a refused Postgres connection still gets the marker and the db-repair line. `test/cli-fatal-remote-mcp-6586.test.ts` fails on the old seam on any Bun. The thin-client goldens (`test/fixtures/goldens/cli/thin-client-{cases,routing}.json`) take 1.4.3's `ECONNREFUSED: ` message prefix, and no other line changes. This affects anyone already running gbrain from source on Bun 1.4.3, not only CI.- `TODOS.md`: the P2 "Bump Bun when a release carries 13a98b0" item is done. `docs/TESTING.md`, `docs/RELEASING.md`, `docs/guides/authorization-upgrade.md` and `native/locks/README.md` name 1.4.3 as the CI and build runtime.## [0.60.192.0] - 2026-10-13diff --git a/src/cli/cli-error.ts b/src/cli/cli-error.tsindex 9052f56677..815a40ba9e 100644--- a/src/cli/cli-error.ts+++ b/src/cli/cli-error.ts@@ -23,6 +23,7 @@ import { redactConnectionInfo } from '../core/audit/redact-connection-info.ts';import { suggestNearest } from '../core/levenshtein.ts';import { isConsentRefusal, printConsentRefusal } from '../core/consent.ts';import { exclusiveFix, liveServeOwner } from '../core/exclusive-fix.ts';+import { RemoteMcpError } from '../core/remote-mcp-error.ts';export interface CliErrorWriteOpts {/** Raw argv (defaults to process.argv.slice(2)); decides `--json`. */@@ -144,7 +145,11 @@ export function unknownFlagError(command: string, flag: string, message: string,* The fatal seam (main() rejected). Same renderer, plus the two pre-v1* behaviours agents and skills depend on: the `pglite_busy` JSON keys* (`next_action`) and the `GBRAIN_DB_ACCESS` marker line skills/db-repair- * literal-matches, with the classifier's remediation.+ * literal-matches, with the classifier's remediation. A thin client's remote+ * MCP failure is never a database access error: Bun 1.4.3's fetch says+ * `ECONNREFUSED: Unable to connect…` where 1.4.2 said `Unable to connect…`,+ * which the database classifier would otherwise read as a refused Postgres+ * connection and send the user to `gbrain db-repair` (#6586).*/export function writeFatalCliError(e: unknown, opts: { argv?: readonly string[]; dbUrl?: string | null; brainId?: string } = {}): number {const argv = opts.argv ?? process.argv.slice(2);@@ -166,7 +171,7 @@ export function writeFatalCliError(e: unknown, opts: { argv?: readonly string[];});return writeCliError(err, command, { argv, legacy: { error: 'pglite_busy', retryable: true, reason: busy.reason, next_action: next } });}- if (!jsonRequested(argv)) {+ if (!jsonRequested(argv) && !(e instanceof RemoteMcpError)) {try {const d = classifyPgAccessError(e, { url: opts.dbUrl ?? null, brainId: opts.brainId });if (d.reason !== 'unknown') {diff --git a/test/cli-fatal-remote-mcp-6586.test.ts b/test/cli-fatal-remote-mcp-6586.test.tsnew file mode 100644index 0000000000..5ece62d497--- /dev/null+++ b/test/cli-fatal-remote-mcp-6586.test.ts@@ -0,0 +1,39 @@+/**+ * #6586: on Bun 1.4.3 a refused fetch reads `ECONNREFUSED: Unable to connect.+ * Is the computer able to access the url?` (1.4.2 said only `Unable to+ * connect…`). The fatal seam ran every error through the database access+ * classifier first, so a thin client whose remote MCP host was down printed+ * `GBRAIN_DB_ACCESS conn_refused` and "switch to the transaction pooler …+ * Run: gbrain db-repair". A remote MCP failure renders as itself; a real+ * refused Postgres connection still gets the marker and the db-repair line.+ */+import { describe, expect, spyOn, test } from 'bun:test';+import { writeFatalCliError } from '../src/cli/cli-error.ts';+import { RemoteMcpError } from '../src/core/remote-mcp-error.ts';++function stderrOf(run: () => number): { code: number; text: string } {+ const chunks: string[] = [];+ const spy = spyOn(process.stderr, 'write').mockImplementation(((chunk: string | Uint8Array) => { chunks.push(String(chunk)); return true; }) as typeof process.stderr.write);+ try { return { code: run(), text: chunks.join('') }; } finally { spy.mockRestore(); }+}++describe('the fatal seam on a refused connection', () => {+ test('a remote MCP discovery failure in Bun 1.4.3 wording is not a database access error', () => {+ const error = new RemoteMcpError('network', 'OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?', { mcp_url: 'http://127.0.0.1:9/mcp' });+ const { code, text } = stderrOf(() => writeFatalCliError(error, { argv: ['takes', 'list'] }));+ expect(code).toBe(1);+ expect(text).toContain('Error [unavailable]: OAuth discovery failed');+ expect(text).toContain('Fix: gbrain remote doctor');+ expect(text).not.toContain('GBRAIN_DB_ACCESS');+ expect(text).not.toContain('database_error');+ expect(text).not.toContain('db-repair');+ });++ test('a refused Postgres connection keeps the marker and the db-repair remediation', () => {+ const error = Object.assign(new Error('connect ECONNREFUSED 127.0.0.1:5432'), { code: 'ECONNREFUSED' });+ const { code, text } = stderrOf(() => writeFatalCliError(error, { argv: ['takes', 'list'], dbUrl: 'postgresql://[email protected]:5432/brain' }));+ expect(code).toBe(1);+ expect(text).toContain('Error [database_error]: connect ECONNREFUSED');+ expect(text).toContain('Run: gbrain db-repair');+ });+});diff --git a/test/fixtures/goldens/cli/thin-client-cases.json b/test/fixtures/goldens/cli/thin-client-cases.jsonindex 358b31df6b..cf77b584ec 100644--- a/test/fixtures/goldens/cli/thin-client-cases.json+++ b/test/fixtures/goldens/cli/thin-client-cases.json@@ -369,7 +369,7 @@"argv": "salience","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -379,7 +379,7 @@"argv": "anomalies","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -412,7 +412,7 @@" local-only — N/A on remote brain","","Warnings:",- " ! remote snapshot failed: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?"+ " ! remote snapshot failed: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?"]},{@@ -637,7 +637,7 @@"argv": "recall","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],diff --git a/test/fixtures/goldens/cli/thin-client-routing.json b/test/fixtures/goldens/cli/thin-client-routing.jsonindex 47b9f080dc..163e918336 100644--- a/test/fixtures/goldens/cli/thin-client-routing.json+++ b/test/fixtures/goldens/cli/thin-client-routing.json@@ -4,7 +4,7 @@"argv": "takes list","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -34,7 +34,7 @@"argv": "cache stats","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -55,7 +55,7 @@"argv": "quarantine list","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -76,7 +76,7 @@"argv": "jobs list","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -86,7 +86,7 @@"argv": "jobs get 1","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -96,7 +96,7 @@"argv": "jobs stats","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -117,7 +117,7 @@"argv": "search modes","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -160,7 +160,7 @@"argv": "capture hello","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: Retry the same operation and arguments with request_id <uuid>; do not generate a replacement ID.","Request: <uuid>"],@@ -219,7 +219,7 @@""," [✓] config_integrity: mcp_url=http://127.0.0.1:1/mcp, issuer_url=http://127.0.0.1:1"," [✓] oauth_credentials: client_id=cid, secret_source=config",- " [✗] oauth_discovery: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ " [✗] oauth_discovery: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","","Connectivity check FAILED — see error above.","Common fixes:",@@ -232,7 +232,7 @@"argv": "think q","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],@@ -242,7 +242,7 @@"argv": "recall q","exitCode": 1,"stderr": [- "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: Unable to connect. Is the computer able to access the url?",+ "Error [unavailable]: OAuth discovery failed: OAuth discovery network error: ECONNREFUSED: Unable to connect. Is the computer able to access the url?","Fix: gbrain remote doctor","Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#unavailable"],