Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(facts): atom pages stop feeding the facts backstop; null-entity facts leave the pending count; doctor names atom-derived facts (#5831)
garrytan8a03e4be8498
diff --git a/src/commands/doctor/checks/queue-assets.ts b/src/commands/doctor/checks/queue-assets.tsindex 0ed3ec6767..a58d352d43 100644--- a/src/commands/doctor/checks/queue-assets.ts+++ b/src/commands/doctor/checks/queue-assets.ts@@ -52,6 +52,12 @@ async function runQueueHealth(ctx: DoctorContext): Promise<Check[]> {.slice(0, 3).map(t => `${t.entity_slug}:${t.count}`).join(', ') || '—';+ // #5831: atom pages are no longer a fact source; name what earlier extraction left behind.+ // Fenced rows name their page in source_markdown_slug; DB-only rows lead their context with it.+ const [atoms] = await engine.executeRaw<{ n: number }>(+ `SELECT count(*)::int AS n FROM facts+ WHERE expired_at IS NULL AND (source_markdown_slug LIKE 'atoms/%' OR context LIKE 'atoms/%')`);+ const atomFacts = Number(atoms?.n ?? 0);checks.push({name: 'facts_health',status,@@ -59,7 +65,8 @@ async function runQueueHealth(ctx: DoctorContext): Promise<Check[]> {`facts_health(default): ${health.total_active} active, ` +`${health.total_today} today, ${health.total_week} this week, ` +`${health.total_consolidated} consolidated, ` +- `top entities ${top}`,+ `top entities ${top}` ++ (atomFacts > 0 ? `; ${atomFacts} active fact(s) came from atom pages, which are no longer extracted (they stay searchable; ones without an entity are not counted as pending consolidation)` : ''),});} else {checks.push({diff --git a/src/core/engine-sql/facts.ts b/src/core/engine-sql/facts.tsindex c875788f84..21d7426ed6 100644--- a/src/core/engine-sql/facts.ts+++ b/src/core/engine-sql/facts.ts@@ -462,9 +462,11 @@ export async function countUnconsolidatedFacts(exec: LegacyUnscopedRead, source_// Validity-lapsed rows are excluded too: the consolidator reads via// listFactsByEntity(activeOnly), which filters them at read time — counting// them here would report a backlog the consolidator can never drain.+ // So are facts with no entity: consolidate reads (source, entity) buckets only (#5831).const rows = (await exec.run<{ count: number }>(sqlFragment`SELECT COUNT(*)::int AS count FROM factsWHERE source_id = ${source_id}+ AND entity_slug IS NOT NULLAND consolidated_at IS NULLAND expired_at IS NULLAND (valid_until IS NULL OR valid_until > now())diff --git a/src/core/facts/eligibility.ts b/src/core/facts/eligibility.tsindex b884636d1b..721bb9f769 100644--- a/src/core/facts/eligibility.ts+++ b/src/core/facts/eligibility.ts@@ -51,7 +51,7 @@ const RESCUE_SLUG_PREFIXES = ['meetings/', 'personal/', 'daily/'] as const;// deferred pack-aware ELIGIBLE_TYPES to v0.43+; codex outside voice caught// it as a blocker — changing the default taxonomy to gbrain-base-v2 while// `eligibility.ts:49` hardcodes only gbrain-base's types means post-unify-// `media` (subtype: article), `tweet`, `atom`, `analysis` pages would+// `media` (subtype: article), `tweet`, `analysis` pages would// silently drop out of facts extraction.//// `concept` is DELIBERATELY excluded: v0.41.11 documented its `extractable:@@ -60,6 +60,10 @@ const RESCUE_SLUG_PREFIXES = ['meetings/', 'personal/', 'daily/'] as const;// pins `kind:concept` rejection. Concept extraction stays out of the// backstop; the schema-pack flag remains a forward-compatibility marker.//+// `atom` is DELIBERATELY excluded too (#5831): atom pages are a derived+// digest of pages that already went through the backstop, their facts carry+// no entity, and consolidate never reads null-entity facts.+//// The union here is safe for both packs:// - gbrain-base brains: all original types still eligible (back-compat)// - gbrain-base-v2 brains: post-unify canonical types also eligible@@ -71,8 +75,8 @@ const ELIGIBLE_TYPES: PageType[] = [// gbrain-base (legacy) types'note', 'meeting', 'slack', 'email', 'calendar-event', 'source', 'writing',// gbrain-base-v2 canonical types declared extractable in the pack- // (concept deliberately omitted — see above)- 'media', 'tweet', 'atom', 'analysis',+ // (concept and atom deliberately omitted — see above)+ 'media', 'tweet', 'analysis',];const MIN_BODY_CHARS = 80;diff --git a/test/doctor-atom-facts-5831.test.ts b/test/doctor-atom-facts-5831.test.tsnew file mode 100644index 0000000000..a05f5aeaff--- /dev/null+++ b/test/doctor-atom-facts-5831.test.ts@@ -0,0 +1,30 @@+/**+ * #5831: atom pages are no longer a facts-backstop source. Doctor's+ * facts_health names how many active facts earlier extraction derived from+ * atom pages, so an operator can see what the change leaves behind.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { queueHealthEntry } from '../src/commands/doctor/checks/queue-assets.ts';+import type { DoctorContext } from '../src/commands/doctor/context.ts';++let engine: PGLiteEngine;+beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); }, 60_000);+afterAll(async () => { await engine.disconnect(); });++const factsHealth = async () => {+ const ctx = { engine, progress: { heartbeat() {} }, args: [] } as unknown as DoctorContext;+ return (await queueHealthEntry.run(ctx) as Array<{ name: string; message: string }>).find(c => c.name === 'facts_health')!;+};++describe('facts_health reports atom-derived facts (#5831)', () => {+ test('silent when no atom page fed facts, counts them when one did', async () => {+ await engine.putPage('notes/plain-example', { type: 'note', title: 'Plain', compiled_truth: 'Plain note.' }, { sourceId: 'default' });+ await engine.putPage('atoms/2026-10-01/lesson-example', { type: 'atom', title: 'Lesson', compiled_truth: 'Small teams ship faster.' }, { sourceId: 'default' });+ await engine.insertFact({ fact: 'a note fact', kind: 'fact', entity_slug: 'acme-example', source: 'test', context: 'notes/plain-example' }, { source_id: 'default' });+ expect((await factsHealth()).message).not.toContain('atom pages');+ await engine.insertFact({ fact: 'small teams ship faster', kind: 'fact', entity_slug: null, source: 'test', context: 'atoms/2026-10-01/lesson-example' }, { source_id: 'default' });+ await engine.insertFact({ fact: 'written decisions help', kind: 'fact', entity_slug: null, source: 'test', context: 'atoms/2026-10-01/lesson-example' }, { source_id: 'default' });+ expect((await factsHealth()).message).toContain('2 active fact(s) came from atom pages, which are no longer extracted');+ });+});diff --git a/test/facts-eligibility.test.ts b/test/facts-eligibility.test.tsindex db4f087561..dd6028df2f 100644--- a/test/facts-eligibility.test.ts+++ b/test/facts-eligibility.test.ts@@ -122,7 +122,7 @@ describe('isFactsBackstopEligible — eligible-types coverage', () => {});}- for (const t of ['person', 'company', 'deal', 'concept', 'project', 'image', 'code'] as PageType[]) {+ for (const t of ['person', 'company', 'deal', 'concept', 'atom', 'project', 'image', 'code'] as PageType[]) {test(`type=${t} on non-rescued slug → rejected with kind:${t}`, () => {const f = fixture({ slug: 'wiki/whatever/x', type: t });const r = isFactsBackstopEligible(f.slug, f.parsed);diff --git a/test/facts-recall-audit-rows.test.ts b/test/facts-recall-audit-rows.test.tsindex c2d310d1c7..dec05f75c2 100644--- a/test/facts-recall-audit-rows.test.ts+++ b/test/facts-recall-audit-rows.test.ts@@ -307,4 +307,11 @@ describe('countUnconsolidatedFacts excludes audit checkpoint rows', () => {test('pending count is the one real fact, not real + audit checkpoints', async () => {expect(await engine3.countUnconsolidatedFacts('default')).toBe(1);});++ // #5831: consolidate reads (source, entity) buckets only, so a fact with no+ // entity is never drained and must not count as pending backlog.+ test('a fact with no entity is not pending consolidation backlog', async () => {+ await engine3.insertFact({ fact: 'small teams ship faster with written decisions', kind: 'fact', entity_slug: null, source: 'test' }, { source_id: 'default' });+ expect(await engine3.countUnconsolidatedFacts('default')).toBe(1);+ });});