Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(health): get_health names the embedding column it measured (#4732)

garrytana926bcce03b4
diff --git a/docs/architecture/key-files/core-services-2.md b/docs/architecture/key-files/core-services-2.md
index 252fb91347..601d71d4f5 100644
--- a/docs/architecture/key-files/core-services-2.md
+++ b/docs/architecture/key-files/core-services-2.md
@@ -22,7 +22,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/core/ops/` — the operations contract's module directory (the meat behind the `operations.ts` façade). `contract.ts` is the foundation contract: the error envelope (`ErrorCode`/`OperationError`/`verbError`), the shared param/logger/auth/context types, and the `Operation` interface — re-exported wholesale by the façade. `context.ts` carries the context validators + scope resolvers: the upload/slug/filename validators, the subagent and bound-client slug fences, and the source-scope resolution ladder (some internal helpers are exported only here and deliberately NOT re-exported from the façade — import those from `context.ts` directly). The remaining modules are one-per-op-domain (`pages.ts`, `search.ts`, `takes.ts`, `tags.ts`, `links.ts`, `timeline.ts`, `admin.ts`, `skills-catalog.ts`, `sync-status.ts`, `raw-data.ts`, `chunks.ts`, `ingest-log.ts`, `files.ts`, `jobs.ts`, `orphans.ts`, `calibration.ts`, `salience.ts`, `facts.ts`, `sources.ts`, `transcripts.ts`, `insights.ts`, `image.ts`, `extraction.ts`, `code-intel.ts`, `chronicle.ts`, `embedding-migration.ts`, `request-tools.ts`, `schema-packs.ts`, `skillopt.ts`), each exporting a `<domain>Operations` map that the façade spreads into the single `operations` export. Add a new op in the matching domain module — an existing domain needs no façade change; a brand-new domain module gets one spread line in `operations.ts`. `facadeExpansion` in `scripts/generate-flag-registry.ts` maps the façade to this whole directory so every module's `--flag` text stays on the command flag-scan surface.
-- `src/core/ops/admin.ts` — the admin/diagnostics domain module (`get_stats`, `get_health`, `get_brain_identity`, …). `get_versions` filters protected facts/takes from both canonical body and timeline, preserves legacy missing timeline fields, and retains engine-side current/historical page privacy predicates for every snapshot field. All three aggregate ops confine remote callers via the same ladder reads use: `ctx.remote === false` keeps the trusted brain-wide view; every other caller gets `sourceScopeOpts(ctx)` (federated array > scalar > the unmatchable `__all__` sentinel, which fail-closes to zeros) threaded into `engine.getStats(scope)`/`getHealth(scope)` — aggregates leak by subtraction, so they scope exactly like reads, and read-scope `get_brain_identity` is confined the same way. `get_health`'s `migrations {pending, partial, wedged, skipped_future}` block stays GLOBAL for scoped callers by decision: it is a host filesystem ledger with no per-source semantics, a wedged host migration is exactly what a remote agent needs to see to explain degraded behavior, and it is composed at the op layer (not in `BrainEngine.getHealth` — growing the engine interface would force both engines to duplicate a file read).
+- `src/core/ops/admin.ts` — the admin/diagnostics domain module (`get_stats`, `get_health`, `get_brain_identity`, …). `get_health` adds `embedding_column`, the registry-active vector column its coverage counts were measured on (legacy `embedding` when the registry is unreadable), on both engines (`test/get-health-embedding-column.test.ts` + its Postgres arm). `get_versions` filters protected facts/takes from both canonical body and timeline, preserves legacy missing timeline fields, and retains engine-side current/historical page privacy predicates for every snapshot field. All three aggregate ops confine remote callers via the same ladder reads use: `ctx.remote === false` keeps the trusted brain-wide view; every other caller gets `sourceScopeOpts(ctx)` (federated array > scalar > the unmatchable `__all__` sentinel, which fail-closes to zeros) threaded into `engine.getStats(scope)`/`getHealth(scope)` — aggregates leak by subtraction, so they scope exactly like reads, and read-scope `get_brain_identity` is confined the same way. `get_health`'s `migrations {pending, partial, wedged, skipped_future}` block stays GLOBAL for scoped callers by decision: it is a host filesystem ledger with no per-source semantics, a wedged host migration is exactly what a remote agent needs to see to explain degraded behavior, and it is composed at the op layer (not in `BrainEngine.getHealth` — growing the engine interface would force both engines to duplicate a file read).
- `src/core/ops/context.ts` (source-id confinement helpers) — `assertSourceInCallerScope(ctx, id)` is the READ-scope confinement for an explicitly named source id (`sources_status`): untrusted callers may only name an id inside the `sourceScopeOpts` ladder. `assertSourceInCallerWriteScope(ctx, id)` is its WRITE-authority twin for destructive source ops (`sources_remove`): federation (`ctx.auth.allowedSources`) is read authority and confers no removal right, so a bound untrusted caller (write source `ctx.auth.sourceId ?? ctx.sourceId`, and/or any federated grant) may name only its own write source; a bound caller with no write source (or the `__all__` sentinel) may name nothing; an unbound untrusted caller keeps full authority; trusted local passes. Both answer `OperationError('not_found', 'Unknown source: <id>')`. `resolveRequestedScope(ctx, sourceId, allSources, explicitReads?)` takes an optional explicit-read admission set (#5081) that only `federatedSearchScope` passes: a granted token admits nothing extra, a stdio connection bound by `GBRAIN_SOURCE`/`.gbrain-source` admits `ctx.explicitReadBinding.sourceIds`, and an unbound connection admits its own `localFederatedSourceIds`; its denial hint names why (token grant, binding, opted-out source) with `docs/guides/multi-source-brains.md#explicit-reads-from-a-bound-agent-connection`. Image, loops and code-intel pass nothing and keep the original denial (`test/explicit-read-admission-5081.test.ts`, `test/serve-stdio-bound-explicit-read.test.ts`).
diff --git a/scripts/e2e-test-map.ts b/scripts/e2e-test-map.ts
index 2fcac0478c..849dd50e1d 100644
--- a/scripts/e2e-test-map.ts
+++ b/scripts/e2e-test-map.ts
@@ -107,6 +107,7 @@ export const E2E_TEST_MAP: Record<string, string[]> = {
// Concrete content and derived-information read policy parity.
"src/core/remote-body.ts": ["test/e2e/engine-content-privacy.test.ts", "test/e2e/legacy-chunk-privacy.test.ts", "test/e2e/chunk-canonical-text-privacy.test.ts"],
"src/core/entity-identity.ts": ["test/e2e/engine-content-privacy.test.ts"],
+ "src/core/ops/admin.ts": ["test/e2e/get-health-embedding-column-postgres.test.ts"],
"src/core/ops/**": ["test/e2e/engine-content-privacy.test.ts", "test/e2e/read-enrichment-privacy.test.ts", "test/e2e/legacy-chunk-privacy.test.ts", "test/e2e/chunk-canonical-text-privacy.test.ts", "test/e2e/put-page-persistence-postgres.test.ts", "test/e2e/deep-research-source-id.test.ts", "test/e2e/deep-research-http.test.ts", "test/e2e/derived-page-visibility.test.ts"],
"src/commands/whoknows.ts": ["test/e2e/read-enrichment-privacy.test.ts"],
"src/commands/orphans.ts": ["test/e2e/engine-content-privacy.test.ts"],
diff --git a/src/core/ops/admin.ts b/src/core/ops/admin.ts
index 461c043b89..d0c12cecc8 100644
--- a/src/core/ops/admin.ts
+++ b/src/core/ops/admin.ts
@@ -15,6 +15,7 @@ import { sanitizeRemoteBody } from '../remote-body.ts';
import type { Operation, OperationContext } from './contract.ts';
import { enforceClientSlugFence, sourceScopeOpts } from './context.ts';
import { VERSION } from '../../version.ts';
+import { resolveActiveEmbeddingColumnFromEngine } from '../search/embedding-column.ts';
// --- Admin ---
@@ -66,7 +67,11 @@ const get_health: Operation = {
} catch {
migrations = { error: 'ledger_unreadable' };
}
- return { ...health, migrations };
+ // #4732: name the column embed_coverage and missing_embeddings measured
+ // (the same resolution getHealth uses), so a 0% coverage on an embedded
+ // brain points at a mis-routed column instead of a paid re-embed.
+ const { name: embedding_column } = await resolveActiveEmbeddingColumnFromEngine(ctx.engine, { fallbackToLegacy: true });
+ return { ...health, embedding_column, migrations };
},
scope: 'admin',
cliHints: { name: 'health' },
diff --git a/test/e2e/get-health-embedding-column-postgres.test.ts b/test/e2e/get-health-embedding-column-postgres.test.ts
new file mode 100644
index 0000000000..e073af6516
--- /dev/null
+++ b/test/e2e/get-health-embedding-column-postgres.test.ts
@@ -0,0 +1,16 @@
+/** #4732 Postgres arm: get_health names the registry-active embedding column. */
+import { afterAll, beforeAll, describe, test } from 'bun:test';
+import { hasDatabase, setupDB, teardownDB } from './helpers.ts';
+import { assertHealthNamesActiveColumn } from '../helpers/health-embedding-column.ts';
+import type { PostgresEngine } from '../../src/core/postgres-engine.ts';
+
+describe.skipIf(!hasDatabase())('get_health embedding_column (Postgres)', () => {
+ let engine: PostgresEngine;
+ beforeAll(async () => { engine = await setupDB(); });
+ afterAll(async () => {
+ await engine.executeRaw('ALTER TABLE content_chunks DROP COLUMN IF EXISTS embedding_reg8');
+ await teardownDB();
+ });
+
+ test('names the registry-active column coverage was measured on', () => assertHealthNamesActiveColumn(engine));
+});
diff --git a/test/get-health-embedding-column.test.ts b/test/get-health-embedding-column.test.ts
new file mode 100644
index 0000000000..f73e6b3168
--- /dev/null
+++ b/test/get-health-embedding-column.test.ts
@@ -0,0 +1,22 @@
+/**
+ * #4732: get_health reported 0% embed coverage on a fully embedded brain
+ * because coverage was measured on a different vector column than the one
+ * holding the vectors, and nothing in the payload said which column that was.
+ * `embedding_column` now names the column coverage and missing_embeddings
+ * were measured on (the same registry resolution getHealth uses).
+ *
+ * Regression that fails it: dropping the field, or naming a column other than
+ * the registry-active one. The Postgres arm is
+ * test/e2e/get-health-embedding-column-postgres.test.ts.
+ */
+import { afterAll, beforeAll, describe, test } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { assertHealthNamesActiveColumn } from './helpers/health-embedding-column.ts';
+
+describe('get_health embedding_column (PGLite)', () => {
+ let engine: PGLiteEngine;
+ beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); });
+ afterAll(async () => { await engine.disconnect(); });
+
+ test('names the registry-active column coverage was measured on', () => assertHealthNamesActiveColumn(engine));
+});
diff --git a/test/helpers/health-embedding-column.ts b/test/helpers/health-embedding-column.ts
new file mode 100644
index 0000000000..b099022c64
--- /dev/null
+++ b/test/helpers/health-embedding-column.ts
@@ -0,0 +1,26 @@
+/** #4732 scenario shared by the PGLite unit arm and the Postgres E2E arm. */
+import { expect } from 'bun:test';
+import { dispatchToolCall } from '../../src/mcp/dispatch.ts';
+import type { BrainEngine } from '../../src/core/engine.ts';
+
+export async function assertHealthNamesActiveColumn(engine: BrainEngine): Promise<void> {
+ const health = async () => {
+ const res = await dispatchToolCall(engine, 'get_health', {}, { remote: true, transport: 'stdio' as const, sourceId: 'default' });
+ expect(res.isError ?? false).toBe(false);
+ return JSON.parse(res.content[0].text) as { embedding_column?: string };
+ };
+ await engine.unsetConfig('search_embedding_column');
+ await engine.unsetConfig('embedding_columns');
+ expect((await health()).embedding_column).toBe('embedding');
+ await engine.executeRaw('ALTER TABLE content_chunks ADD COLUMN IF NOT EXISTS embedding_reg8 vector(8)');
+ await engine.setConfig('embedding_columns', JSON.stringify({
+ embedding_reg8: { provider: 'openai:text-embedding-3-small', dimensions: 8, type: 'vector' },
+ }));
+ await engine.setConfig('search_embedding_column', 'embedding_reg8');
+ try {
+ expect((await health()).embedding_column).toBe('embedding_reg8');
+ } finally {
+ await engine.unsetConfig('search_embedding_column');
+ await engine.unsetConfig('embedding_columns');
+ }
+}