Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(cli-socket): count GBRAIN_HOME and GBRAIN_BRAIN_ID by what they resolve to (GBRA-156)

garrytanebead383f8f1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62c6b818c5..8dc7b318a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,26 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [0.60.353.0] - 2026-10-21
+
+**The warm CLI socket now matches a serve that exports `GBRAIN_HOME` with a CLI that doesn't.** After v0.60.350.0, a serve started with `GBRAIN_HOME=$HOME` still refused every CLI that relied on `HOME` alone, with `refused (identity_mismatch): env GBRAIN_HOME`. Both sides resolved to the same home, but the identity compared whether the variable was set. `GBRAIN_HOME` and `GBRAIN_BRAIN_ID` now count by the config home and brain they resolve to, which the identity already compares.
+
+### What changed
+
+| Situation | Before | Now |
+|---|---|---|
+| Serve exports `GBRAIN_HOME`, CLI reaches the same home through `HOME` | refused (`env GBRAIN_HOME`) | answered warm |
+| Serve sets `GBRAIN_BRAIN_ID=host`, CLI leaves it unset | refused | answered warm |
+| A different resolved config home or brain | refused | still refused (`config home`, `brain`) |
+
+### What to watch for after you upgrade
+
+- Restart the serve after upgrading, as before: a serve and a CLI on different gbrain versions never match.
+
+### Itemized changes
+
+- `READ_BEHAVIOR_ENV` drops `GBRAIN_HOME`, `GBRAIN_BRAIN_ID`, `GBRAIN_MOUNTS_PATH` (mount brains, which the socket never serves) and `GBRAIN_CWD_ENV_QUARANTINED` (a re-run marker whose effect already shows in the environment it left). The classification test lists them with the reason.
+
## [0.60.352.0] - 2026-10-21
**Reading the timeline of a very large page uses less memory.** When gbrain rebuilds a page's timeline links, it keeps track of the timeline lines it has already seen, so it never writes one twice. On a page with tens of thousands of dated lines, that tracking took about 80 bytes per line, roughly a third of an 8 MiB page's own size. It now takes about 25 bytes per line, and the results are exactly the same.
diff --git a/docs/guides/cli-socket.md b/docs/guides/cli-socket.md
index c10acf9fc7..47b9705ae8 100644
--- a/docs/guides/cli-socket.md
+++ b/docs/guides/cli-socket.md
@@ -95,7 +95,9 @@ The CLI falls back to its normal path, silently, when:
Connection sizing and driver settings (`GBRAIN_POOL_SIZE`,
`GBRAIN_DIRECT_POOL_SIZE`, `GBRAIN_PREPARE`, ...), the database URL
variables and `GBRAIN_SOURCE` (which every request carries and the serve
- resolves for that call) may differ. Editing `config.json`, changing a listed
+ resolves for that call) may differ. `GBRAIN_HOME` and `GBRAIN_BRAIN_ID`
+ count by the config home and brain they resolve to, so a serve that exports
+ `GBRAIN_HOME` matches a CLI that reaches the same home through `HOME`. Editing `config.json`, changing a listed
variable or upgrading gbrain while a serve runs sends CLI calls to the normal
path until the serve restarts with the same settings. The refusal names the
part that differed, never its value: `refused (identity_mismatch): database
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index c2a5693721..212cd8b8fe 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1084,6 +1084,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.350.0', text: 'The warm CLI socket now answers CLI calls whose connection setup differs from the serve\'s only in ways that cannot change an answer: connection sizing and driver settings (`GBRAIN_POOL_SIZE`, `GBRAIN_DIRECT_POOL_SIZE`, `GBRAIN_PREPARE` and the like), the database URL variables, driver-only URL parameters (`prepare=`, `sslmode`, `application_name`), and, on a Supabase Supavisor pooler host, the port, so a serve on the session lane (5432) answers CLI calls made on the transaction lane (6543). Only an explicit list of read-behavior `GBRAIN_*` settings must still match; on any other host another port is still refused. A refusal now names the part that differed (`refused (identity_mismatch): database port`, `env GBRAIN_MODEL`), never its value, and the serve logs each distinct one once. Guide: docs/guides/cli-socket.md.' },
{ since: '0.60.351.0', text: 'Remote (MCP and HTTP) page reads now hide a page marked private only by a privacy alias (`access: private|restricted|confidential` or `confidentiality: confidential|secret|private|restricted`, with no `visibility`), as they hide `visibility: private` pages; local CLI reads are unchanged. To keep showing such pages to remote callers: `gbrain config set visibility.honor_aliases false`.' },
{ since: '0.60.351.0', text: '`gbrain repair visibility` previews one class at a time, in the order remote callers are exposed: world facts from a private page (remotely readable ones first), Life Chronicle events, alias-only pages, then atoms and concepts; only that last class (`--class lineage`) reads concept-provenance links, and `--class facts|events|aliases|lineage` previews one. A preview lists one window (1,000 items, `--limit` up to 10,000), reports progress on stderr and prints `--apply --expect <hash>`, which applies exactly that window and resumes after its last applied item; apply it, then preview again for the next window. A bare `--apply` (`--all`, the remediation plan) still applies every class. Each plan statement is bounded at 120 s; a class that overruns is reported and skipped while the others are listed. The fact and concept-lineage plans are set-based now (a large brain timed out on them), and doctor `derived_visibility` counts facts first and reports derived-page counts as unknown when they overrun the same bound. A doctor rerun hint capped to fit an agent tool call also names the uncapped `--budget-ms` to use in a terminal.' },
+ // GBRA-156 (warm CLI socket: location variables by what they resolve to). `since` is restamped at the merge slot.
+ { since: 'TBD', text: 'The warm CLI socket no longer refuses a CLI only because the serve exports `GBRAIN_HOME` (or `GBRAIN_BRAIN_ID`) and the CLI does not: those count by the config home and brain they resolve to, which the socket already compares, so a serve started with `GBRAIN_HOME=$HOME` answers a CLI that relies on `HOME`. A different resolved home or brain is still refused.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/cli-socket/identity.ts b/src/core/cli-socket/identity.ts
index 2ef6927823..b58788f9b6 100644
--- a/src/core/cli-socket/identity.ts
+++ b/src/core/cli-socket/identity.ts
@@ -17,14 +17,15 @@ import { listRecipes } from '../ai/recipes/index.ts';
* The GBRAIN_* variables that can change what a socket read (search, query,
* get, recall) answers or where its text goes. An explicit allow-list:
* connection sizing and driver tuning (GBRAIN_POOL_SIZE, GBRAIN_PREPARE, ...)
- * never change an answer, so a serve and a CLI may differ there. The database
- * URL variables are compared as a database target instead (`DatabaseTarget`),
- * and GBRAIN_SOURCE travels in every request and is resolved per call.
+ * never change an answer, so a serve and a CLI may differ there. Variables that
+ * only choose a location are compared by what they resolve to, never by whether
+ * they are set: GBRAIN_HOME as the config home, GBRAIN_BRAIN_ID as the brain id,
+ * the database URL variables as the database target (`DatabaseTarget`). GBRAIN_SOURCE
+ * travels in every request and is resolved per call.
* test/cli-socket.test.ts classifies every GBRAIN_* name in src, so a new one
* cannot skip this decision.
*/
export const READ_BEHAVIOR_ENV: readonly string[] = [
- 'GBRAIN_HOME', 'GBRAIN_BRAIN_ID', 'GBRAIN_MOUNTS_PATH', 'GBRAIN_CWD_ENV_QUARANTINED',
'GBRAIN_SEARCH_EXCLUDE', 'GBRAIN_SEARCH_SALVAGE', 'GBRAIN_SEARCH_DEBUG', 'GBRAIN_SOURCE_BOOST', 'GBRAIN_RECENCY_DECAY',
'GBRAIN_FTS_LANGUAGE', 'GBRAIN_HNSW_ITERATIVE_SCAN', 'GBRAIN_VECTOR_LEGACY_GUARD', 'GBRAIN_PROJECTION_READINESS_CACHE',
'GBRAIN_REMOTE_PRIVATE_PAGES', 'GBRAIN_RLS_SCOPE_BINDING', 'GBRAIN_STALENESS_CEILING_HOURS', 'GBRAIN_SERVE_DEGRADED',
diff --git a/test/cli-socket.test.ts b/test/cli-socket.test.ts
index 5c277d4517..39d0fbc76d 100644
--- a/test/cli-socket.test.ts
+++ b/test/cli-socket.test.ts
@@ -67,7 +67,10 @@ function homeWithConfig(name: string, body = '{"engine":"postgres"}'): { dir: st
* its text goes: writes, sync, jobs, workers, locks, doctor, setup and hooks,
* other transports (HTTP, MCP surface, thin client), the database URL variables
* (compared as a database target), connection sizing and driver tuning,
- * diagnostics, settings only the CLI's own renderer reads (GBRAIN_FAIL_ON_EMPTY:
+ * location variables compared by what they resolve to (GBRAIN_HOME as the config
+ * home, GBRAIN_BRAIN_ID as the brain id, GBRAIN_MOUNTS_PATH for mount brains the
+ * socket never serves, GBRAIN_CWD_ENV_QUARANTINED whose effect is already in the
+ * env it left), diagnostics, settings only the CLI's own renderer reads (GBRAIN_FAIL_ON_EMPTY:
* the warm path renders and sets the exit code in the CLI, with the CLI's
* environment), and constants that only share the prefix. Families are listed
* by prefix only where no member reads; anything else is named.
@@ -80,6 +83,7 @@ const NOT_READ_BEHAVIOR_PREFIXES = [
'GBRAIN_PROGRESSIVE_BATCH_', 'GBRAIN_QUEUE_', 'GBRAIN_SETUP_', 'GBRAIN_STOP_PUSH', 'GBRAIN_SUPERVIS', 'GBRAIN_SWEEP', 'GBRAIN_SYNC', 'GBRAIN_WORKER_',
];
const NOT_READ_BEHAVIOR = new Set([
+ 'GBRAIN_HOME', 'GBRAIN_BRAIN_ID', 'GBRAIN_MOUNTS_PATH', 'GBRAIN_CWD_ENV_QUARANTINED',
'GBRAIN_FAIL_ON_EMPTY', 'GBRAIN_CLI_SOCKET', 'GBRAIN_DEBUG', 'GBRAIN_SQL_TRACE', 'GBRAIN_SQL_TRACE_LABEL', 'GBRAIN_LME_DEBUG', 'GBRAIN_SOURCE',
'GBRAIN_DATABASE_URL', 'GBRAIN_DIRECT_DATABASE_URL', 'GBRAIN_DIRECT_POOL_SIZE', 'GBRAIN_DISABLE_DIRECT_POOL', 'GBRAIN_PREPARE',
'GBRAIN_IDLE_TX_TIMEOUT', 'GBRAIN_MAX_CONNECTIONS', 'GBRAIN_NO_RETRY_CONNECT', 'GBRAIN_DB_ACCESS',
@@ -160,7 +164,7 @@ describe('identity', () => {
expect(cliSocketIdentityMismatch(base, identity())).toBe('config contents');
});
- test('a sizing or driver variable may differ; a read-behavior variable may not, and is named without its value', () => {
+ test('a sizing or driver variable may differ, and so may a location variable that resolves to the same home and brain (one side exporting GBRAIN_HOME, the other relying on HOME); a read-behavior variable may not, and is named without its value', () => {
homeWithConfig('a');
const base = identity({ env: { HOME: '/home/alice-example', GBRAIN_HOME: '/home/alice-example' } });
for (const env of [{ GBRAIN_POOL_SIZE: '10' }, { GBRAIN_DIRECT_POOL_SIZE: '4' }, { GBRAIN_PREPARE: 'true' }, { GBRAIN_POOL_MAX_LIFETIME_S: '60' },
@@ -169,7 +173,9 @@ describe('identity', () => {
}
const contributor = identity({ env: { GBRAIN_HOME: '/home/alice-example', GBRAIN_CONTRIBUTOR_MODE: '1' } });
expect(cliSocketIdentityMismatch(base, contributor)).toBe('env GBRAIN_CONTRIBUTOR_MODE');
- expect(cliSocketIdentityMismatch(base, identity({ env: { GBRAIN_HOME: '/home/bob-example' } }))).toBe('env GBRAIN_HOME');
+ expect(cliSocketIdentityMismatch(base, identity({ env: { HOME: '/home/alice-example' } }))).toBeNull();
+ expect(cliSocketIdentityMismatch(base, identity({ env: { GBRAIN_HOME: '/home/alice-example', GBRAIN_BRAIN_ID: 'host', GBRAIN_MOUNTS_PATH: '/home/alice-example/.gbrain/mounts.json' } }))).toBeNull();
+ expect(cliSocketIdentityMismatch(base, identity({ env: { GBRAIN_HOME: '/home/alice-example', GBRAIN_MODEL: 'model-a' } }))).toBe('env GBRAIN_MODEL');
expect(JSON.stringify(identity({ env: { GBRAIN_MODEL: 'model-secretish' } }))).not.toContain('model-secretish');
});
diff --git a/test/e2e/cli-socket-postgres.test.ts b/test/e2e/cli-socket-postgres.test.ts
index 5fe3b298f8..c39dfca669 100644
--- a/test/e2e/cli-socket-postgres.test.ts
+++ b/test/e2e/cli-socket-postgres.test.ts
@@ -239,6 +239,14 @@ describe.skipIf(!DATABASE_URL)('warm CLI socket (postgres)', () => {
expect({ stdout: run.stdout, exitCode: run.exitCode }).toEqual({ stdout: cold.get('search')!.stdout, exitCode: 0 });
}, 90_000);
+ test('a CLI that resolves the same home through HOME, without the serve\'s GBRAIN_HOME, is answered warm', async () => {
+ const trace = traceFile();
+ const run = await cli(READS.search!, { GBRAIN_DEBUG: '1', GBRAIN_SQL_TRACE: trace, GBRAIN_HOME: '' });
+ expect(run.stderr).not.toContain('[cli-socket] cold path');
+ expect(roundTrips(trace)).toBe(0);
+ expect({ stdout: run.stdout, exitCode: run.exitCode }).toEqual({ stdout: cold.get('search')!.stdout, exitCode: 0 });
+ }, 90_000);
+
test('a CLI with its own GBRAIN_SOURCE is answered warm, with that source applied', async () => {
const coldB = await cli(['search', WORD], { GBRAIN_CLI_SOCKET: '0', GBRAIN_SOURCE: 'source-b' });
expect(coldB.stdout).toContain('notes/gamma-example');