Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(doctor): raw_provenance accepts attributable extract_atoms atoms (#6537)

time-attack25db6311dbf9
diff --git a/src/commands/doctor/checks/core-health.ts b/src/commands/doctor/checks/core-health.ts
index 8096aaa319..883221a200 100644
--- a/src/commands/doctor/checks/core-health.ts
+++ b/src/commands/doctor/checks/core-health.ts
@@ -532,6 +532,10 @@ export async function childTableOrphansCheck(engine: BrainEngine): Promise<Check
* - an attached `raw_data` row
* - `synthesis_evidence` rows (think-op citations)
* - explicit `raw_trace_exempt: true` (reason in `raw_trace_exempt_reason`)
+ * - an extract_atoms atom (`type: atom`, `extracted_by: extract_atoms-*`)
+ * naming its origin: `source_slug` (page origin) or `source_path`
+ * (transcript origin), as the writer stamps them (#6537). Other pages
+ * carrying `source_slug` do not count.
*
* v1 is deliberately warn-only — no write path is blocked. Escalation to
* fail-closed enforcement in the synthesis/import write paths is the v2
@@ -545,6 +549,9 @@ export async function rawProvenanceCheck(engine: BrainEngine): Promise<Check> {
p.deleted_at IS NULL
AND (COALESCE(p.frontmatter->>'dream_generated', '') = 'true' OR p.type = 'synthesis')
AND NOT (COALESCE(p.frontmatter, '{}'::jsonb) ?| ARRAY['raw_trace', 'raw_source', 'source_uri', 'raw_trace_exempt'])
+ AND NOT (p.type = 'atom'
+ AND COALESCE(p.frontmatter->>'extracted_by', '') LIKE 'extract\\_atoms%'
+ AND COALESCE(p.frontmatter, '{}'::jsonb) ?| ARRAY['source_slug', 'source_path'])
AND NOT EXISTS (SELECT 1 FROM raw_data rd WHERE rd.page_id = p.id)
AND NOT EXISTS (SELECT 1 FROM synthesis_evidence se WHERE se.synthesis_page_id = p.id)`;
try {
diff --git a/test/doctor-raw-provenance.test.ts b/test/doctor-raw-provenance.test.ts
index 93397d56fa..32b5ec3e88 100644
--- a/test/doctor-raw-provenance.test.ts
+++ b/test/doctor-raw-provenance.test.ts
@@ -108,3 +108,56 @@ describe('rawProvenanceCheck (#1978, warn-only v1)', () => {
expect(categorizeCheck('raw_provenance')).toBe('brain');
});
});
+
+describe('rawProvenanceCheck accepts attributable extract_atoms atoms (#6537)', () => {
+ const atomFm = {
+ atom_type: 'insight', source_hash: 'a1b2c3d4e5f60718', extracted_by: 'extract_atoms-v0.41.2.1',
+ extracted_at: '2026-10-12T00:00:00Z', dream_generated: true,
+ };
+ let atoms: PGLiteEngine;
+ beforeAll(async () => {
+ atoms = new PGLiteEngine();
+ await atoms.connect({});
+ await atoms.initSchema();
+ });
+ afterAll(async () => { await atoms.disconnect(); });
+
+ const flagged = async (): Promise<string> => {
+ const result = await rawProvenanceCheck(atoms as unknown as BrainEngine);
+ return result.status === 'ok' ? '' : result.message;
+ };
+
+ test('page-origin and transcript-origin atoms pass', async () => {
+ await atoms.putPage('wiki/source-page', { type: 'note', title: 'S', compiled_truth: 'body', timeline: '' });
+ await atoms.putPage('atoms/2026-10-12/a-page-atom', {
+ type: 'atom' as never, title: 'A', compiled_truth: 'x', timeline: '',
+ frontmatter: { ...atomFm, source_slug: 'wiki/source-page' },
+ });
+ await atoms.putPage('atoms/2026-10-12/a-transcript-atom', {
+ type: 'atom' as never, title: 'B', compiled_truth: 'y', timeline: '',
+ frontmatter: { ...atomFm, source_path: '/home/u/transcripts/2026-10-12.jsonl' },
+ });
+ expect(await flagged()).toBe('');
+ });
+
+ test('origin keys count only on extract_atoms atoms', async () => {
+ await atoms.putPage('wiki/derived/pattern-with-source-slug', {
+ type: 'note', title: 'P', compiled_truth: 'x', timeline: '',
+ frontmatter: { dream_generated: true, extracted_by: 'extract_atoms-v0.41.2.1', source_slug: 'wiki/source-page' },
+ });
+ await atoms.putPage('atoms/2026-10-12/lookalike-extractor', {
+ type: 'atom' as never, title: 'L', compiled_truth: 'x', timeline: '',
+ frontmatter: { ...atomFm, extracted_by: 'extractXatoms-v1', source_slug: 'wiki/source-page' },
+ });
+ await atoms.putPage('atoms/2026-10-12/no-origin', {
+ type: 'atom' as never, title: 'N', compiled_truth: 'x', timeline: '', frontmatter: atomFm,
+ });
+ const message = await flagged();
+ expect(message).toContain('3 synthesized page(s)');
+ expect(message).toContain('atoms/2026-10-12/lookalike-extractor');
+ expect(message).toContain('atoms/2026-10-12/no-origin');
+ expect(message).toContain('wiki/derived/pattern-with-source-slug');
+ expect(message).not.toContain('a-page-atom');
+ expect(message).not.toContain('a-transcript-atom');
+ });
+});