Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(doctor): 1-4 entity pages are not applicable for coverage checks (#5379)

time-attackf1d1c65f99f8
diff --git a/src/commands/doctor/checks/graph-health.ts b/src/commands/doctor/checks/graph-health.ts
index f2c8318326..e5cfa2ee9c 100644
--- a/src/commands/doctor/checks/graph-health.ts
+++ b/src/commands/doctor/checks/graph-health.ts
@@ -9,6 +9,7 @@
import { startHeartbeat } from '../../../core/progress.ts';
import { quarantineFilterFragment } from '../../../core/quarantine.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../../../core/types.ts';
import type { Check } from '../../doctor.ts';
import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';
import { brainScorePlanFix, checkError } from '../check-fix.ts';
@@ -85,6 +86,8 @@ async function runGraphCoverage(ctx: DoctorContext): Promise<Check[]> {
status: 'ok',
message: `Only code/test fixture entity pages found (${entityCount}); graph_coverage not applicable`,
});
+ } else if (eligibleEntityCount < MIN_ENTITY_PAGES_FOR_COVERAGE) {
+ checks.push({ name: 'graph_coverage', status: 'ok', message: `Only ${eligibleEntityCount} eligible entity page${eligibleEntityCount === 1 ? '' : 's'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale` });
} else if (linkCoverage >= 0.7 && timelineCoverage >= 0.5) {
checks.push({ name: 'graph_coverage', status: 'ok', message: `Entity connected coverage (in/out) ${linkPct}%, entity timeline coverage ${timelinePct}%` });
} else {
diff --git a/src/core/onboard/checks.ts b/src/core/onboard/checks.ts
index c325dbba66..8c70a50bc4 100644
--- a/src/core/onboard/checks.ts
+++ b/src/core/onboard/checks.ts
@@ -25,6 +25,7 @@ import type { Action } from '../agent-output.ts';
import { embeddingEnablement, type ReadinessState } from '../readiness.ts';
import { embeddingsDisabled } from '../embedding-disabled.ts';
import { loadConfig } from '../config.ts';
+import { MIN_ENTITY_PAGES_FOR_COVERAGE } from '../types.ts';
/** Shared shape returned by all four checks. */
export interface OnboardCheckResult {
@@ -273,6 +274,16 @@ export async function checkEntityLinkCoverage(
remediations: [],
};
}
+ if (totalEntities < MIN_ENTITY_PAGES_FOR_COVERAGE) {
+ return {
+ check: {
+ name: 'entity_link_coverage',
+ status: 'ok',
+ message: `Only ${totalEntities} entity page${totalEntities === 1 ? '' : 's'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`,
+ },
+ remediations: [],
+ };
+ }
// Decide TABLESAMPLE policy (PG only, when >50K entities)
const useSample = engine.kind === 'postgres' && totalEntities > 50_000;
@@ -360,6 +371,16 @@ export async function checkTimelineCoverage(
remediations: [],
};
}
+ if (totalEntities < MIN_ENTITY_PAGES_FOR_COVERAGE) {
+ return {
+ check: {
+ name: 'timeline_coverage',
+ status: 'ok',
+ message: `Only ${totalEntities} entity page${totalEntities === 1 ? '' : 's'} (< ${MIN_ENTITY_PAGES_FOR_COVERAGE}) — coverage ratio not meaningful at this scale`,
+ },
+ remediations: [],
+ };
+ }
const useSample = engine.kind === 'postgres' && totalEntities > 50_000;
const samplePct = useSample
diff --git a/test/doctor-graph-coverage-inbound.test.ts b/test/doctor-graph-coverage-inbound.test.ts
index b3f03fd7d8..0a3549745a 100644
--- a/test/doctor-graph-coverage-inbound.test.ts
+++ b/test/doctor-graph-coverage-inbound.test.ts
@@ -34,7 +34,7 @@ beforeEach(async () => {
});
/**
- * Two entity pages that are LINKED TO (inbound only) from note pages, each
+ * Five entity pages that are LINKED TO (inbound only) from note pages, each
* with a timeline entry so the timeline half of the check stays green and
* the assertion isolates the link-direction predicate.
*/
@@ -45,6 +45,9 @@ async function seedInboundOnlyEntities(eng: PGLiteEngine): Promise<void> {
VALUES
('alice-example', 'default', 'person', 'Alice', '', '{}', 'in1', now(), now()),
('acme-example', 'default', 'company', 'Acme', '', '{}', 'in2', now(), now()),
+ ('bob-example', 'default', 'person', 'Bob', '', '{}', 'in4', now(), now()),
+ ('carol-example', 'default', 'person', 'Carol', '', '{}', 'in5', now(), now()),
+ ('dave-example', 'default', 'person', 'Dave', '', '{}', 'in6', now(), now()),
('meetings/2026-04-03', 'default', 'note', 'Standup', '', '{}', 'in3', now(), now())
`;
// Inbound-only: the note links TO both entities; the entities link to nothing.
@@ -52,11 +55,11 @@ async function seedInboundOnlyEntities(eng: PGLiteEngine): Promise<void> {
INSERT INTO links (from_page_id, to_page_id, link_type)
SELECT n.id, e.id, 'mentions'
FROM pages n, pages e
- WHERE n.slug = 'meetings/2026-04-03' AND e.slug IN ('alice-example', 'acme-example')
+ WHERE n.slug = 'meetings/2026-04-03' AND e.slug IN ('alice-example', 'acme-example', 'bob-example', 'carol-example', 'dave-example')
`;
await sql`
INSERT INTO timeline_entries (page_id, date, summary)
- SELECT id, '2026-04-03', 'met at standup' FROM pages WHERE slug IN ('alice-example', 'acme-example')
+ SELECT id, '2026-04-03', 'met at standup' FROM pages WHERE slug IN ('alice-example', 'acme-example', 'bob-example', 'carol-example', 'dave-example')
`;
}
@@ -66,7 +69,7 @@ describe('graph_coverage counts inbound-connected entities (#4191)', () => {
const checks = await buildChecks(engine, [], null);
const graph = checks.find((c) => c.name === 'graph_coverage');
expect(graph, 'graph_coverage check must be present').toBeDefined();
- // Both entities have inbound links → 100% connected coverage, ok.
+ // All five entities have inbound links → 100% connected coverage, ok.
expect(graph!.status).toBe('ok');
expect(graph!.message).toContain('connected coverage (in/out)');
expect(graph!.message).toContain('100%');
@@ -78,7 +81,10 @@ describe('graph_coverage counts inbound-connected entities (#4191)', () => {
INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
VALUES
('bob-example', 'default', 'person', 'Bob', '', '{}', 'un1', now(), now()),
- ('widget-co', 'default', 'company', 'Widget Co', '', '{}', 'un2', now(), now())
+ ('widget-co', 'default', 'company', 'Widget Co', '', '{}', 'un2', now(), now()),
+ ('carol-example', 'default', 'person', 'Carol', '', '{}', 'un3', now(), now()),
+ ('dave-example', 'default', 'person', 'Dave', '', '{}', 'un4', now(), now()),
+ ('erin-example', 'default', 'person', 'Erin', '', '{}', 'un5', now(), now())
`;
const checks = await buildChecks(engine, [], null);
const graph = checks.find((c) => c.name === 'graph_coverage');
@@ -86,4 +92,17 @@ describe('graph_coverage counts inbound-connected entities (#4191)', () => {
expect(graph!.message).toContain('connected coverage (in/out) 0%');
expect(graph!.message).toContain('target 70%');
});
+
+ test('one eligible entity page is not applicable without a coverage warning', async () => {
+ const sql = sqlQueryForEngine(engine);
+ await sql`
+ INSERT INTO pages (slug, source_id, type, title, compiled_truth, frontmatter, content_hash, created_at, updated_at)
+ VALUES ('one-example', 'default', 'person', 'One', '', '{}', 'one', now(), now())
+ `;
+ const checks = await buildChecks(engine, [], null);
+ const graph = checks.find((c) => c.name === 'graph_coverage');
+ expect(graph!.status).toBe('ok');
+ expect(graph!.message).toContain('Only 1 eligible entity page (< 5)');
+ expect(graph!.message).not.toContain('target 70%');
+ });
});
diff --git a/test/doctor-graph-coverage-soft-deleted.test.ts b/test/doctor-graph-coverage-soft-deleted.test.ts
index 016be9ad2c..e079684baf 100644
--- a/test/doctor-graph-coverage-soft-deleted.test.ts
+++ b/test/doctor-graph-coverage-soft-deleted.test.ts
@@ -37,7 +37,7 @@ beforeEach(async () => {
await resetPgliteState(engine);
});
-/** Two entity pages plus a plain note; the entity pages are then soft-deleted. */
+/** Five eligible entity pages plus a plain note; the entities are then soft-deleted. */
async function seedSoftDeletedEntities(eng: PGLiteEngine): Promise<void> {
const sql = sqlQueryForEngine(eng);
await sql`
@@ -45,9 +45,12 @@ async function seedSoftDeletedEntities(eng: PGLiteEngine): Promise<void> {
VALUES
('acme-example', 'default', 'company', 'Acme', '', '{}', 'sd1', now(), now()),
('alice-example', 'default', 'person', 'Alice', '', '{}', 'sd2', now(), now()),
+ ('people/filler-example-1', 'default', 'person', 'Filler 1', '', '{}', 'sd4', now(), now()),
+ ('people/filler-example-2', 'default', 'person', 'Filler 2', '', '{}', 'sd5', now(), now()),
+ ('people/filler-example-3', 'default', 'person', 'Filler 3', '', '{}', 'sd6', now(), now()),
('technical-a', 'default', 'note', 'Tech A', '', '{}', 'sd3', now(), now())
`;
- await sql`UPDATE pages SET deleted_at = now() WHERE slug IN ('acme-example', 'alice-example')`;
+ await sql`UPDATE pages SET deleted_at = now() WHERE slug IN ('acme-example', 'alice-example', 'people/filler-example-1', 'people/filler-example-2', 'people/filler-example-3')`;
}
/** Same shape, but the entity pages stay live — the control. */
@@ -58,6 +61,9 @@ async function seedLiveEntities(eng: PGLiteEngine): Promise<void> {
VALUES
('acme-example', 'default', 'company', 'Acme', '', '{}', 'lv1', now(), now()),
('alice-example', 'default', 'person', 'Alice', '', '{}', 'lv2', now(), now()),
+ ('people/filler-example-1', 'default', 'person', 'Filler 1', '', '{}', 'lv4', now(), now()),
+ ('people/filler-example-2', 'default', 'person', 'Filler 2', '', '{}', 'lv5', now(), now()),
+ ('people/filler-example-3', 'default', 'person', 'Filler 3', '', '{}', 'lv6', now(), now()),
('technical-a', 'default', 'note', 'Tech A', '', '{}', 'lv3', now(), now())
`;
}
@@ -94,9 +100,8 @@ describe('graph_coverage counts live entity pages only (#3754, doctor surface)',
const checks = await buildChecks(engine, [], null);
const graph = checks.find((c) => c.name === 'graph_coverage');
expect(graph, 'graph_coverage check must be present').toBeDefined();
- // 2 live entity pages + 1 soft-deleted. The count doctor reports — and
- // divides its percentages by — must be the live 2.
- expect(graph!.message).toContain('(2 entity pages)');
- expect(graph!.message).not.toContain('(3 entity pages)');
+ // 5 live entity pages + 1 soft-deleted. The reported denominator excludes it.
+ expect(graph!.message).toContain('(5 entity pages)');
+ expect(graph!.message).not.toContain('(6 entity pages)');
});
});
diff --git a/test/onboard-coverage-invariants.test.ts b/test/onboard-coverage-invariants.test.ts
index bf02717d38..f7754fbde8 100644
--- a/test/onboard-coverage-invariants.test.ts
+++ b/test/onboard-coverage-invariants.test.ts
@@ -33,12 +33,11 @@ beforeEach(async () => {
});
async function seedVisibleAndQuarantinedEntities(): Promise<void> {
- await engine.putPage('people/visible-example', {
- type: 'person',
- title: 'Visible Example',
- compiled_truth: 'A visible synthetic entity.',
- timeline: '',
- });
+ for (let i = 0; i < 5; i++) {
+ await engine.putPage(`people/visible-example-${i}`, {
+ type: 'person', title: `Visible Example ${i}`, compiled_truth: 'A visible synthetic entity.', timeline: '',
+ });
+ }
await engine.putPage('people/quarantined-example', {
type: 'person',
title: 'Quarantined Example',
@@ -114,6 +113,28 @@ describe('onboard entity coverage invariants', () => {
expect(result.check.message).not.toContain('50%');
});
+ test('one entity page is not applicable for link coverage', async () => {
+ await engine.putPage('people/one-example', {
+ type: 'person', title: 'One Example', compiled_truth: 'A synthetic entity.', timeline: '',
+ });
+ const result = await checkEntityLinkCoverage(engine);
+ expect(result.check.status).toBe('ok');
+ expect(result.check.message).toContain('Only 1 entity page (< 5)');
+ expect(result.check.message).not.toContain('Coverage 0%');
+ expect(result.remediations).toHaveLength(0);
+ });
+
+ test('five entities with zero inbound links still warn', async () => {
+ for (let i = 0; i < 5; i++) {
+ await engine.putPage(`people/unlinked-${i}`, {
+ type: 'person', title: `Unlinked ${i}`, compiled_truth: 'A synthetic entity.', timeline: '',
+ });
+ }
+ const result = await checkEntityLinkCoverage(engine);
+ expect(result.check.status).toBe('warn');
+ expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
+ });
+
test('timeline coverage applies the same visible-sample invariant', async () => {
await seedVisibleAndQuarantinedEntities();
await engine.addTimelineEntry('people/quarantined-example', {
@@ -127,4 +148,26 @@ describe('onboard entity coverage invariants', () => {
expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
expect(result.check.message).not.toContain('50%');
});
+
+ test('one entity page is not applicable for timeline coverage', async () => {
+ await engine.putPage('people/one-example', {
+ type: 'person', title: 'One Example', compiled_truth: 'A synthetic entity.', timeline: '',
+ });
+ const result = await checkTimelineCoverage(engine);
+ expect(result.check.status).toBe('ok');
+ expect(result.check.message).toContain('Only 1 entity page (< 5)');
+ expect(result.check.message).not.toContain('Coverage 0%');
+ expect(result.remediations).toHaveLength(0);
+ });
+
+ test('five entities with zero timeline entries still warn', async () => {
+ for (let i = 0; i < 5; i++) {
+ await engine.putPage(`people/no-timeline-${i}`, {
+ type: 'person', title: `No Timeline ${i}`, compiled_truth: 'A synthetic entity.', timeline: '',
+ });
+ }
+ const result = await checkTimelineCoverage(engine);
+ expect(result.check.status).toBe('warn');
+ expect(result.check.message).toMatch(/^Coverage 0% ± 0\.0%/);
+ });
});
diff --git a/test/onboard-phantom-rec-gates.test.ts b/test/onboard-phantom-rec-gates.test.ts
index 9ea26f19b1..52e3e633ac 100644
--- a/test/onboard-phantom-rec-gates.test.ts
+++ b/test/onboard-phantom-rec-gates.test.ts
@@ -186,7 +186,7 @@ describe('checkEntityLinkCoverage — NER capability gate', () => {
});
it('low coverage + pack WITHOUT NER rules → WARN but NO extract-ner rec, with a reason', async () => {
- await seedEntities(3); // entity pages, zero inbound links → coverage 0%
+ await seedEntities(5); // eligible entity pages, zero inbound links → coverage 0%
await withPack(REGEXLESS_PACK, async () => {
const { check, remediations } = await checkEntityLinkCoverage(engine);
expect(check.status).toBe('warn');
@@ -199,7 +199,7 @@ describe('checkEntityLinkCoverage — NER capability gate', () => {
it('low coverage + pack WITH NER rules → recommends extract-ner', async () => {
// The positive direction. Without this case, "no rec emitted" passes for
// any reason at all — including a pack that never resolved.
- await seedEntities(3);
+ await seedEntities(5);
await withPack('gbrain-base', async () => {
const { check, remediations } = await checkEntityLinkCoverage(engine);
expect(check.status).toBe('warn');
@@ -212,7 +212,7 @@ describe('checkEntityLinkCoverage — NER capability gate', () => {
it('unresolvable pack → rec withheld, but the message says so distinctly', async () => {
// Fail-closed must stay VISIBLE. A pack that cannot be resolved is an
// operator problem, and must not read as "your pack declares no NER rules".
- await seedEntities(3);
+ await seedEntities(5);
await withPack('no-such-pack-e2e-fixture', async () => {
const { check, remediations } = await checkEntityLinkCoverage(engine);
expect(check.status).toBe('warn');
@@ -233,7 +233,7 @@ describe('recommender / handler parity (the anti-drift invariant)', () => {
// either side that breaks the pairing fails here.
for (const [pack, expectRec] of [['gbrain-base', true], [REGEXLESS_PACK, false]] as const) {
it(`agree on ${pack}: rec emitted=${expectRec} ⇔ handler can run`, async () => {
- await seedEntities(3);
+ await seedEntities(5);
await withPack(pack, async () => {
const { extractNerLinks } = await import('../src/core/extract-ner.ts');
const { remediations } = await checkEntityLinkCoverage(engine);
@@ -257,7 +257,7 @@ describe('recommender / handler parity (the anti-drift invariant)', () => {
// handler resolves the tier-7 default gbrain-base and would happily run —
// a MISSED recommendation, the phantom bug's mirror image. (The home must
// be regexlessHome so the DB-named pack resolves from disk at all.)
- await seedEntities(3);
+ await seedEntities(5);
await engine.setConfig('schema_pack', REGEXLESS_PACK);
await withEnv({ GBRAIN_HOME: regexlessHome, GBRAIN_SCHEMA_PACK: undefined }, async () => {
const { extractNerLinks } = await import('../src/core/extract-ner.ts');
@@ -274,7 +274,7 @@ describe('checkTimelineCoverage — datable-meetings gate', () => {
// Pack-independent: this gate counts dated meeting pages, it never loads a
// pack. Pinned anyway so the whole file is hermetic by construction.
it('low coverage + zero dated meetings → WARN but NO rec, with a reason', async () => {
- await seedEntities(3); // entity pages with no timeline entries → coverage 0%
+ await seedEntities(5); // eligible entity pages with no timeline entries → coverage 0%
await withPack('gbrain-base-v2', async () => {
const { check, remediations } = await checkTimelineCoverage(engine);
expect(check.status).toBe('warn');
@@ -285,7 +285,7 @@ describe('checkTimelineCoverage — datable-meetings gate', () => {
});
it('low coverage + a dated meeting present → recommends extract-timeline-from-meetings', async () => {
- await seedEntities(3);
+ await seedEntities(5);
await engine.putPage('m0', {
title: 'Standup', type: 'meeting' as never,
compiled_truth: 'body that is long enough to pass any minimum-length guards in the codebase',