Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Slow-read heartbeat: skip refused thin-client commands; diag contract row; intentional golden updates

garrytan30c3478e320d
diff --git a/src/cli/command-table.ts b/src/cli/command-table.ts
index aa5055e461..069d897809 100644
--- a/src/cli/command-table.ts
+++ b/src/cli/command-table.ts
@@ -318,8 +318,7 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp
// selfHelp: v0.37 fix wave (Lane D.4 + CDX2-12): sync's --no-embed flag was unreachable via help
// because the dispatcher's generic CLI-only short-circuit fired before runSync could print its own
// usage block. Adding `sync` here routes `gbrain sync --help` into runSync.
- { name: 'sync', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, json: 'document', routes_source: true,
- slowRead: args => args.includes('status') ? `sync status for ${sourceArg(args) ? `source ${sourceArg(args)}` : 'the selected source'}` : null, load: () => import('./commands/sync.ts') },
+ { name: 'sync', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, json: 'document', routes_source: true, slowRead: args => args.includes('status') ? `sync status for ${sourceArg(args) ? `source ${sourceArg(args)}` : 'the selected source'}` : null, load: () => import('./commands/sync.ts') },
// selfHelp: #3834: extract ships detailed help for its mode-specific flags. Keep the generic
// CLI-only stub from hiding that contract.
{ name: 'extract', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, routes_source: '--source-id', load: () => import('./commands/extract.ts') },
diff --git a/src/cli/slow-read.ts b/src/cli/slow-read.ts
index d95c91117c..7cfe3f848d 100644
--- a/src/cli/slow-read.ts
+++ b/src/cli/slow-read.ts
@@ -2,7 +2,8 @@
* Which CLI invocations are slow whole-brain reads, and the start of their heartbeat (core/read-heartbeat.ts).
* Each command record names its reads with `slowRead` (command-table.ts).
*/
-import { findCliCommand } from './command-table.ts';
+import { findCliCommand, THIN_CLIENT_REFUSED_COMMANDS } from './command-table.ts';
+import { isThinClient, loadConfig } from '../core/config.ts';
import { beginSlowRead } from '../core/read-heartbeat.ts';
import { jsonRequested } from '../core/cli-force-exit.ts';
import { getCliOptions } from '../core/cli-options.ts';
@@ -14,10 +15,10 @@ export function flagValue(args: readonly string[], flag: string): string | undef
return args.find(a => a.startsWith(flag + '='))?.slice(flag.length + 1);
}
-/** Starts the heartbeat when `command args` is a slow read; returns the function that ends it (a no-op otherwise). */
+/** Starts the heartbeat when `command args` is a slow read this install runs (a thin client refuses or routes the refused ones); returns the function that ends it (a no-op otherwise). */
export function beginCommandRead(command: string, args: readonly string[]): () => void {
if (args.includes('--help') || args.includes('-h') || getCliOptions().quiet) return () => {};
const label = findCliCommand(command)?.slowRead?.(args);
- if (!label) return () => {};
+ if (!label || THIN_CLIENT_REFUSED_COMMANDS.has(command) && isThinClient(loadConfig())) return () => {};
return beginSlowRead(label, { json: jsonRequested(args) });
}
diff --git a/test/cli-contract.test.ts b/test/cli-contract.test.ts
index eacab51a9e..cec9c52c23 100644
--- a/test/cli-contract.test.ts
+++ b/test/cli-contract.test.ts
@@ -124,6 +124,8 @@ const JSON_ROWS: Record<string, JsonRow> = {
trust: { ok: ['trust', 'backfill', '--dry-run', '--json'], fail: ['trust', 'explain', 'f999999', '--json'], failOnBrain: true },
// W1 belief ledger: status is read-only; an unknown source is an invalid_params envelope.
beliefs: { ok: ['beliefs', 'status', '--source', 'notes', '--json'], fail: ['beliefs', 'status', '--source', 'no-such-source', '--json'], failOnBrain: true },
+ // GBRA-151: the bundle is read-only and bounded; a budget that is not a positive number is an invalid_params envelope.
+ diag: { ok: ['diag', '--json', '--budget-ms', '20000'], fail: ['diag', '--json', '--budget-ms', '0'], failOnBrain: true },
// D8: the dry run resolves and prints the target without writing; an unwired harness id is a coded refusal.
setup: { ok: ['setup', 'claude-code', '--dry-run', '--json', '--gbrain-bin', process.execPath], fail: ['setup', 'codex', '--json'], okOnEmpty: true },
};
diff --git a/test/cli-thin-client-refusal-matrix.test.ts b/test/cli-thin-client-refusal-matrix.test.ts
index 5551a90c67..456f4a6fb1 100644
--- a/test/cli-thin-client-refusal-matrix.test.ts
+++ b/test/cli-thin-client-refusal-matrix.test.ts
@@ -12,7 +12,7 @@
* against a remote brain), routes a host-bound subcommand, changes a hint or
* exit code, or moves a check across the connectEngine terminator.
* Why new: test/cli-dispatch-thin-client.test.ts asserts refusal for a
- * hand-picked subset by substring; nothing pins all 69 cases or the full
+ * hand-picked subset by substring; nothing pins all 70 cases or the full
* text. Seam: none.
*
* Nothing leaves the machine: issuer and MCP URLs point at 127.0.0.1:1
@@ -104,8 +104,8 @@ describe('A16b thin-client refusal matrix', () => {
routing = await run(ROUTING_ROWS);
}, 300_000);
- test('the matrix covers all 69 handleCliOnly cases', () => {
- expect(CASES.length).toBe(69);
+ test('the matrix covers all 70 handleCliOnly cases', () => {
+ expect(CASES.length).toBe(70);
});
test('every handleCliOnly case, run bare on a thin client, matches the golden', () => {
diff --git a/test/fixtures/goldens/cli/engine-free-db-down.json b/test/fixtures/goldens/cli/engine-free-db-down.json
index 7b8563f28b..3d41c7a430 100644
--- a/test/fixtures/goldens/cli/engine-free-db-down.json
+++ b/test/fixtures/goldens/cli/engine-free-db-down.json
@@ -339,11 +339,12 @@
"argv": "status",
"exitCode": 1,
"stderr": [
+ "[gbrain] reading the brain status snapshot; large brains can take minutes. Progress prints here every <dur>; the result prints on stdout when it is ready.",
"GBRAIN_DB_ACCESS conn_refused",
"Error [database_error]: Cannot connect to database: connect ECONNREFUSED <REDACTED:ipv4>:1. Fix: Check the database URL; `gbrain engine status --probe` names where it comes from (environment variable or the config file under GBRAIN_HOME)",
"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port. Run: gbrain db-repair"
],
- "stderrFirstLine": "GBRAIN_DB_ACCESS conn_refused",
+ "stderrFirstLine": "[gbrain] reading the brain status snapshot; large brains can take minutes. Progress prints here every <dur>; the result prints on stdout when it is ready.",
"stdout": [],
"stdoutFirstLine": null,
"url": "config"
diff --git a/test/fixtures/goldens/cli/thin-client-cases.json b/test/fixtures/goldens/cli/thin-client-cases.json
index ec962c9847..741cdbe854 100644
--- a/test/fixtures/goldens/cli/thin-client-cases.json
+++ b/test/fixtures/goldens/cli/thin-client-cases.json
@@ -334,6 +334,16 @@
],
"stdout": []
},
+ {
+ "argv": "diag",
+ "exitCode": 1,
+ "stderr": [
+ "Error [requires_local_engine]: `gbrain diag` requires a local engine. This install is a thin client of http://127.0.0.1:1/mcp.",
+ "Fix: gbrain diag",
+ "Docs: https://github.com/garrytan/gbrain/blob/master/docs/guides/error-codes.md#requires_local_engine"
+ ],
+ "stdout": []
+ },
{
"argv": "orphans",
"exitCode": 1,
@@ -379,6 +389,7 @@
"argv": "anomalies",
"exitCode": 1,
"stderr": [
+ "[gbrain] reading anomalous cohorts; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"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"
@@ -398,7 +409,9 @@
{
"argv": "status",
"exitCode": 0,
- "stderr": [],
+ "stderr": [
+ "[gbrain] reading the brain status snapshot; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready."
+ ],
"stdout": [
"",
"GBrain Status",
diff --git a/test/fixtures/goldens/cli/thin-client-routing.json b/test/fixtures/goldens/cli/thin-client-routing.json
index 163e918336..a6c15d9726 100644
--- a/test/fixtures/goldens/cli/thin-client-routing.json
+++ b/test/fixtures/goldens/cli/thin-client-routing.json
@@ -207,7 +207,9 @@
{
"argv": "doctor",
"exitCode": 1,
- "stderr": [],
+ "stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready."
+ ],
"stdout": [
"",
"GBrain Health Check (thin-client)",
diff --git a/test/fixtures/goldens/doctor/content-pglite-human.json b/test/fixtures/goldens/doctor/content-pglite-human.json
index 11214fc4be..f3ec2a5198 100644
--- a/test/fixtures/goldens/doctor/content-pglite-human.json
+++ b/test/fixtures/goldens/doctor/content-pglite-human.json
@@ -8,6 +8,7 @@
"exit_code": 1,
"report": null,
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[doctor.db_checks] start",
"[doctor.db_checks] done"
],
diff --git a/test/fixtures/goldens/doctor/content-pglite-json.json b/test/fixtures/goldens/doctor/content-pglite-json.json
index 97b0779ad3..afc685be48 100644
--- a/test/fixtures/goldens/doctor/content-pglite-json.json
+++ b/test/fixtures/goldens/doctor/content-pglite-json.json
@@ -4025,6 +4025,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late.",
"[backup] checked 2 asset(s): 1 without a git remote (computed_by=doctor)"
],
diff --git a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
index ee38d7e8af..cff7fc002e 100644
--- a/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-pglite-json.json
@@ -4558,6 +4558,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late.",
"[backup] checked 3 asset(s): 1 without a git remote (computed_by=doctor)"
],
@@ -9121,6 +9122,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late."
],
"stdout": "<json>"
diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
index 2f161b3316..09f2d1b770 100644
--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
@@ -4559,6 +4559,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late.",
"[backup] checked 3 asset(s): 1 without a git remote (computed_by=doctor)"
],
@@ -9123,6 +9124,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late."
],
"stdout": "<json>"
diff --git a/test/fixtures/goldens/doctor/json-no-config.json b/test/fixtures/goldens/doctor/json-no-config.json
index 12a97879e5..5e3dc0368a 100644
--- a/test/fixtures/goldens/doctor/json-no-config.json
+++ b/test/fixtures/goldens/doctor/json-no-config.json
@@ -17,6 +17,7 @@
"errors",
"no_brain"
],
+ "elapsed_ms": "<volatile>",
"error": "no_brain",
"fix": {
"actor": "agent",
@@ -37,6 +38,7 @@
"suggestion": "Run `gbrain init --pglite --no-embedding` for a local keyless brain, or `gbrain init --help` for hosted and Postgres options."
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"GBRAIN_DB_ACCESS no_url",
"Error [no_brain]: No brain configured. Run: gbrain init",
"Fix: gbrain init --pglite --no-embedding"
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index 817603cf0a..9046da3033 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -3506,6 +3506,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late."
],
"stdout": "<json>"
diff --git a/test/fixtures/goldens/doctor/json-pglite-fast.json b/test/fixtures/goldens/doctor/json-pglite-fast.json
index ade0597575..e41b800cec 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fast.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fast.json
@@ -431,6 +431,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late."
],
"stdout": "<json>"
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index 0575f2df63..bef578b13e 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -3579,6 +3579,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late.",
"[backup] checked 1 asset(s): 0 without a git remote (computed_by=doctor)"
],
diff --git a/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json b/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json
index 55251a5545..670a3155d3 100644
--- a/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json
+++ b/test/fixtures/goldens/doctor/json-postgres-unreachable-fast.json
@@ -383,6 +383,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[gbrain doctor] non-interactive run: the check run (not connect or migrations) is capped at 90000 ms (doctor.default_budget_ms); checks past it report health unknown. Off for one run: --budget-ms 0; off for good: gbrain config set doctor.default_budget_ms 0. On PGLite a statement already running cannot be stopped, so a check can finish late."
],
"stdout": "<json>"
diff --git a/test/fixtures/goldens/doctor/json-postgres-unreachable.json b/test/fixtures/goldens/doctor/json-postgres-unreachable.json
index c08e6c1ada..a5dda76785 100644
--- a/test/fixtures/goldens/doctor/json-postgres-unreachable.json
+++ b/test/fixtures/goldens/doctor/json-postgres-unreachable.json
@@ -388,6 +388,7 @@
"unknown_sections": []
},
"stderr": [
+ "[gbrain] reading doctor checks; large brains can take minutes. Progress prints here every 10 s; the result prints on stdout when it is ready.",
"[doctor] DB-backed doctor run failed (Cannot connect to database: connect ECONNREFUSED <REDACTED:ipv4>:1. Fix: Check the database URL; `gbrain engine status --probe` names where it comes from (environment variable or the config file under GBRAIN_HOME)) — falling back to filesystem-only checks",
"GBRAIN_DB_ACCESS conn_refused",
"Connection refused: nothing accepted the connection at the configured host and port. Check that the database server is running and that the URL names the right host and port. Run: gbrain db-repair",