Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(status): embed backlog reads the published generation only; freshness_by_source omits never-synced sources (doctor goldens unchanged); test engine via isolatedSharedSkillsEngine
garrytana6b0382b19d3
diff --git a/src/commands/doctor/checks/managed-sync-latency.ts b/src/commands/doctor/checks/managed-sync-latency.tsindex ed6ca3ae6a..182ef1f268 100644--- a/src/commands/doctor/checks/managed-sync-latency.ts+++ b/src/commands/doctor/checks/managed-sync-latency.ts@@ -9,8 +9,9 @@* synced commit, aged from the reflog entry that moved HEAD (or the commit notifier's persisted first_due_at), or* unknown when neither can date it (no reflog, rewritten history). A stalled source has no new samples, so this* is what keeps it from reading ok.- * Keyword-visible and embedded freshness are reported separately per source (details.freshness_by_source); the- * embedding backlog is reported, not graded (a keyless brain reads disabled).+ * Keyword-visible and embedded freshness are reported separately per source that has synced+ * (details.freshness_by_source, absent when none has); the embedding backlog is reported, not graded (a keyless brain+ * reads disabled).* It grades only a brain that asked for low latency, with `sync.on_commit` true or `sync.freshness_target_seconds` set: a* p95 or a waiting commit over the target (default 300 s) warns and one over max(1 h, target) fails; a waiting commit of* unknown age and synced commits it cannot date (not in this host's checkout) warn. Otherwise it reports ok with the@@ -61,11 +62,11 @@ async function runManagedSyncLatencyCheck(ctx: DoctorContext): Promise<Check[]>const freshness = managed ? await readSyncFreshness(engine, { sourceIds: scope }) : [];const backlog = await readEmbedBacklog(engine, roster.map(s => s.id));const samplesBy = new Map(freshness.map(f => [f.source_id, f]));- const freshnessBySource = roster.map((s, i) => ({ source_id: s.id, kind: s.managed ? 'managed' : 'classic',+ const freshnessBySource = roster.flatMap((s, i) => pending[i]!.state === 'never_synced' ? [] : [{ source_id: s.id, kind: s.managed ? 'managed' : 'classic',keyword_visible: { state: pending[i]!.state, oldest_unsynced: pending[i]!, samples: samplesBy.get(s.id)?.commit_to_searchable ?? null },- embedded: { state: embeddedState(pending[i]!, backlog.get(s.id)), backlog: backlog.get(s.id) ?? null, samples: samplesBy.get(s.id)?.commit_to_embedded ?? null } }));+ embedded: { state: embeddedState(pending[i]!, backlog.get(s.id)), backlog: backlog.get(s.id) ?? null, samples: samplesBy.get(s.id)?.commit_to_embedded ?? null } }]);const sampled = freshness.filter(f => f.commit_to_searchable.samples > 0);- const details = { graded, on_commit: onCommit, target_seconds: target.seconds, fail_seconds: failSeconds, sources: freshness, freshness_by_source: freshnessBySource, docs: DOCS };+ const details = { graded, on_commit: onCommit, target_seconds: target.seconds, fail_seconds: failSeconds, sources: freshness, ...(freshnessBySource.length ? { freshness_by_source: freshnessBySource } : {}), docs: DOCS };const behind = pending.filter(p => p.state === 'behind');const undatable = pending.filter(p => p.state === 'unknown');const waitFail = behind.filter(p => (p.age_seconds ?? 0) > failSeconds);diff --git a/src/core/sync-pending.ts b/src/core/sync-pending.tsindex 6604bd32ff..97224c4e77 100644--- a/src/core/sync-pending.ts+++ b/src/core/sync-pending.ts@@ -158,8 +158,8 @@ export interface EmbedBacklog {}/**- * The embedding backlog of each source: live chunks without a vector in the active embedding column (embed_skip pages- * excluded, as the doctor embeddings check counts them), aged from the oldest `content_chunks.embedding_pending_since`.+ * The embedding backlog of each source: live chunks of the published body generation without a vector in the active+ * embedding column (embed_skip pages excluded, as the doctor embeddings check counts them), aged from the oldest `content_chunks.embedding_pending_since`.*/export async function readEmbedBacklog(engine: BrainEngine, sourceIds: string[], opts: { nowMs?: number } = {}): Promise<Map<string, EmbedBacklog>> {const out = new Map<string, EmbedBacklog>();@@ -171,12 +171,13 @@ export async function readEmbedBacklog(engine: BrainEngine, sourceIds: string[],return out;}const { quoteIdentifier, resolveActiveEmbeddingColumnFromEngine } = await import('./search/embedding-column.ts');+ const { chunkGenerationFilter } = await import('./search/safe-chunks.ts');const column = quoteIdentifier((await resolveActiveEmbeddingColumnFromEngine(engine, { fallbackToLegacy: true })).name);const rows = await engine.executeRaw<{ source_id: string; pending: unknown; unaged: unknown; oldest: unknown }>(`SELECT p.source_id, count(*)::int AS pending, count(*) FILTER (WHERE cc.embedding_pending_since IS NULL)::int AS unaged,min(cc.embedding_pending_since) AS oldestFROM content_chunks cc JOIN pages p ON p.id = cc.page_id- WHERE cc.${column} IS NULL AND p.deleted_at IS NULL AND p.source_id = ANY($1::text[])+ WHERE cc.${column} IS NULL AND p.deleted_at IS NULL AND p.source_id = ANY($1::text[]) AND ${chunkGenerationFilter('p', 'cc')}AND NOT jsonb_exists(COALESCE(p.frontmatter, '{}'::jsonb), 'embed_skip')GROUP BY p.source_id`, [sourceIds]);const byId = new Map(rows.map(row => [row.source_id, row]));diff --git a/test/pathological/s-truthful-sync-status.test.ts b/test/pathological/s-truthful-sync-status.test.tsindex 9b7236b67b..8fecbe09fe 100644--- a/test/pathological/s-truthful-sync-status.test.ts+++ b/test/pathological/s-truthful-sync-status.test.ts@@ -21,13 +21,12 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import type { BrainEngine } from '../../src/core/engine.ts';-import { PGLiteEngine } from '../../src/core/pglite-engine.ts';import { claimWorktree } from '../../src/core/persistence/ownership.ts';import { disposePersistenceConsumer } from '../../src/core/persistence/service.ts';import { managedSyncLatencyEntry } from '../../src/commands/doctor/checks/managed-sync-latency.ts';import { computeAllSourceMetrics } from '../../src/core/source-health.ts';import { loadAllSources } from '../../src/core/sources-load.ts';-import { isolatedPersistencePostgres } from '../helpers/persistence-postgres.ts';+import { isolatedSharedSkillsEngine } from '../helpers/shared-skills-engine.ts';import { withEnv } from '../helpers/with-env.ts';import { pathologicalArms } from './harness.ts';@@ -53,10 +52,7 @@ interface Brain { engine: BrainEngine; home: string; root: string; synced: strinasync function withBrain(databaseUrl: string | undefined, opts: { managed: boolean }, run: (b: Brain) => Promise<void>): Promise<void> {const home = mkdtempSync(join(tmpdir(), 'gbrain-truthful-status-'));await withEnv({ GBRAIN_HOME: home, GBRAIN_NOTIFIER: '0' }, async () => {- let engine: BrainEngine;- let close: () => Promise<void>;- if (databaseUrl) ({ engine, close } = await isolatedPersistencePostgres(databaseUrl));- else { const lite = new PGLiteEngine(); await lite.connect({}); await lite.initSchema(); engine = lite; close = () => lite.disconnect(); }+ const { engine, close } = await isolatedSharedSkillsEngine(databaseUrl);try {const root = join(home, SOURCE);mkdirSync(join(root, 'notes'), { recursive: true });