Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(engine-open): refuse a multi-host URL without per-host ports too
garrytancc4ccfb8fee1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ef72118d6f..9f48f4d6c5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,7 +20,7 @@ identifiers and attribution are available in the pre-removal Git revision- `src/core/persistence/identity.ts`: `hostIdFor(engine)` and `setEngineHostId`, resolved through `engineKey`. Every host-id read in `src/core` goes through it or `existingHostIdFor(engine)` (publication, admission, the consumer, worktree ownership and refresh, topology, effects, repair and the writer stamp), except `gbrain migrate`'s engine graduation; an unmarked engine still gets `localHostId()`, so the CLI's behavior is unchanged. An embedded engine never reads or mints `host.json`, and its consumer heartbeat records `embedded:<host-id>`, which doctor and writer status read as an identity given at open. `registerLocalWriterValue` registers a writer the host holds as a value, and an embedded engine's writes use it instead of a `<brain>.<lane>.json` file. It never widens past the settings. The lane is the one given, a new registration gets the default read/write ceiling, and an existing registration keeps its own.- `initSchema()` on an embedded engine seeds the embedding model and width from `settings.embedding` and refuses `engine_embedding_mismatch` on a database that records another one. Postgres `initSchema()` reads the recorded identity again once it holds the schema lock, so two hosts initializing one fresh database can no longer both pass the check.- A settings URL must be one single-host URL that names its host, user and database, and an embedded engine's pools pass every connection field to the driver explicitly, so `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD` and `PGDATABASE` never choose its server or credentials.-- `PostgresEngine.reconnect()` now ends the superseded connection manager's direct pool once its in-flight work finishes (#8478), so a long hold such as `CREATE INDEX CONCURRENTLY` or the schema lock completes first. Before, every reconnect on an engine with a direct route left that pool open past `disconnect()`; this affected every Postgres engine, not only embedded ones.+- `PostgresEngine.reconnect()` now ends the superseded connection manager's direct pool once its in-flight work finishes (#8478), so a long hold such as `CREATE INDEX CONCURRENTLY` or the schema lock held on the direct pool completes first. Before, every reconnect on an engine with a direct route left that pool open past `disconnect()`; this affected every Postgres engine, not only embedded ones.- The decide receipt and spend buffers write rows buffered for one brain to that brain when the next row names another, even while a flush is in flight. Before, those rows landed in the next brain's database.- The decide spend cache is keyed by engine and held weakly, and a drained feedback queue no longer keeps its engine alive.- File storage and AI provider settings are not engine settings yet; they stay process-wide until Wave C.diff --git a/src/core/embedded-engine.ts b/src/core/embedded-engine.tsindex 5db14f2520..0a84bf0eb3 100644--- a/src/core/embedded-engine.ts+++ b/src/core/embedded-engine.ts@@ -40,7 +40,7 @@ const parseConnectionUrl = (url: string) => new URL(url.replace(/^postgres(ql)?:/** Why openEngine refuses a settings URL (not one parseable single-host URL, or no host, user or database name), or undefined. */export function connectionUrlProblem(url: string): string | undefined {let parsed: URL;- try { parsed = parseConnectionUrl(url); } catch { return 'is not a parseable single-host connection URL (openEngine reads no multi-host URL)'; }+ try { parsed = parseConnectionUrl(url); if (parsed.hostname.includes(',')) throw new Error('multi-host'); } catch { return 'is not a parseable single-host connection URL (openEngine reads no multi-host URL)'; }const missing = !parsed.hostname ? 'host' : !parsed.username ? 'user' : parsed.pathname.length <= 1 ? 'database name' : undefined;return missing && `names no ${missing}, and the driver would fill it from PG* environment variables`;}diff --git a/test/engine-open.test.ts b/test/engine-open.test.tsindex b0e3488fb1..a37a4c1a7a 100644--- a/test/engine-open.test.ts+++ b/test/engine-open.test.ts@@ -89,8 +89,10 @@ describe('openEngine refusals', () => {test('a settings URL keeps the port it names, and a multi-host URL is refused as one openEngine cannot read', async () => {expect(settingsConnectionOptions(pgUrl('app:secret', 'db-a.example.internal:80/brain_a')).port).toBe(80);- const refusal = await openEngine(settingsFor({ engine: 'postgres', database: { url: pgUrl('app:secret', 'db-a.example.internal:5432,db-b.example.internal:5433/brain_a') } })).catch((error: { code?: string; suggestion?: string }) => error);- expect(refusal).toMatchObject({ code: 'engine_settings_invalid', suggestion: expect.stringContaining('multi-host') });+ for (const hosts of ['db-a.example.internal:5432,db-b.example.internal:5433', 'db-a.example.internal,db-b.example.internal', 'db-a.example.internal,db-b.example.internal:5433']) {+ const refusal = await openEngine(settingsFor({ engine: 'postgres', database: { url: pgUrl('app:secret', `${hosts}/brain_a`) } })).catch((error: { code?: string; suggestion?: string }) => error);+ expect(refusal).toMatchObject({ code: 'engine_settings_invalid', suggestion: expect.stringContaining('multi-host') });+ }});});