Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
extract_facts: cycle summary names the pages the guard skipped and keeps the reconcile counts (#6278)
garrytan7ad093e4d2dc
diff --git a/src/core/cycle.ts b/src/core/cycle.tsindex 2cc292e6ab..d27cbcd801 100644--- a/src/core/cycle.ts+++ b/src/core/cycle.ts@@ -1471,23 +1471,6 @@ async function runPhaseExtractFacts(signal,});- // Empty-fence guard: unfenced rows the phase's own fence step could not- // fence this run. Surface as 'warn' so doctor + the cycle report can see- // it; the warnings name each page and why.- if (result.guardTriggered) {- return {- phase: 'extract_facts',- status: 'warn',- duration_ms: 0,- summary: `extract_facts skipped: ${result.legacyRowsPending} unfenced fact row(s) could not be fenced`,- details: {- legacyRowsPending: result.legacyRowsPending,- unfencedRowsFenced: result.unfencedRowsFenced,- warnings: result.warnings,- },- };- }-// v0.35.5: phantom-redirect counters bubble up alongside the existing// fact-reconcile counts. We summarize the phantom counters in the// human-readable summary line when any non-zero phantom work happened@@ -1512,12 +1495,20 @@ async function runPhaseExtractFacts(`destructive full walk may have wiped non-fence facts (#1928).`,);}+ // Empty-fence guard (per page, #6278): unfenced rows the phase's own fence+ // step could not fence this run keep their pages out of reconciliation+ // while the other pages reconcile. The summary names those pages and keeps+ // the reconcile counts; the warnings name each page and why.+ const listed = result.legacyPages.slice(0, 3).join(', ') + (result.legacyPages.length > 3 ? `, +${result.legacyPages.length - 3} more` : '');+ const guardSummary = result.guardTriggered+ ? `; skipped ${result.legacyPages.length} page(s) holding ${result.legacyRowsPending} unfenced fact row(s) that could not be fenced: ${listed}`+ : '';const decideConflict = dryRun ? undefined : await (await import('./ai/decide/sweep.ts')).conflictSweepTail(engine, sourceId, signal);return {phase: 'extract_facts',status: result.warnings.length > 0 ? 'warn' : 'ok',duration_ms: 0,- summary: `${result.factsInserted} fact(s) reconciled across ${result.pagesScanned} page(s)${phantomSummary}` ++ summary: `${result.factsInserted} fact(s) reconciled across ${result.pagesScanned} page(s)${phantomSummary}` + guardSummary +(result.warnings.length > 0 ? ` (${result.warnings.length} warning(s))` : ''),details: {pagesScanned: result.pagesScanned,@@ -1525,8 +1516,10 @@ async function runPhaseExtractFacts(factsInserted: result.factsInserted,factsDeleted: result.factsDeleted,unfencedRowsFenced: result.unfencedRowsFenced,+ legacyRowsPending: result.legacyRowsPending,+ legacyPages: result.legacyPages,pagesFailed: result.pagesFailed,- warnings: result.warnings.slice(0, 5),+ warnings: result.guardTriggered ? result.warnings : result.warnings.slice(0, 5),// v0.35.5: phantom counters surfaced so extractTotals() can lift// them to CycleReport.totals and the daily report makes the// cleanup visible.diff --git a/src/core/cycle/extract-facts.ts b/src/core/cycle/extract-facts.tsindex c7ec901bd2..bebef311b3 100644--- a/src/core/cycle/extract-facts.ts+++ b/src/core/cycle/extract-facts.ts@@ -360,6 +360,8 @@ export interface ExtractFactsResult {factsDeleted: number;/** Unfenced rows (`row_num IS NULL`, live entity page) still pending after this run's fence step. */legacyRowsPending: number;+ /** Pages (sorted slugs) that still hold those rows; they skip reconciliation while the other pages reconcile (#6278). */+ legacyPages: string[];/** Unfenced rows this run appended to their page's fence and stamped with a row number (#5299). */unfencedRowsFenced: number;/** Active fence-owned rows expired because their page was soft-deleted. */@@ -506,6 +508,7 @@ export async function runExtractFacts(factsUpdated: 0,factsDeleted: 0,legacyRowsPending: 0,+ legacyPages: [],unfencedRowsFenced: 0,factsExpiredForDeletedPages: 0,pagesFailed: 0,@@ -543,6 +546,7 @@ export async function runExtractFacts(// the destructive reconciliation pass; the other pages reconcile.const { count: legacyCount, slugs: legacySlugs } = await pendingLegacyRows(engine, sourceId);result.legacyRowsPending = legacyCount;+ result.legacyPages = [...legacySlugs].sort();if (legacyCount > 0) {result.guardTriggered = true;result.warnings.push(diff --git a/test/extract-facts-unfenced-rows.test.ts b/test/extract-facts-unfenced-rows.test.tsindex c9abd0ce7e..6435d224ba 100644--- a/test/extract-facts-unfenced-rows.test.ts+++ b/test/extract-facts-unfenced-rows.test.ts@@ -169,6 +169,7 @@ for (const backend of testBackends()) {const first = await extractFactsPhase(engine, root);expect(first.status).toBe('warn');expect(first.details).toMatchObject({ legacyRowsPending: 4, unfencedRowsFenced: 5 });+ expect(first.summary).toMatch(new RegExp(`^[1-9]\\d* fact\\(s\\) reconciled across [1-9]\\d* page\\(s\\); skipped 1 page\\(s\\) holding 4 unfenced fact row\\(s\\) that could not be fenced: ${SLUG} `));const warnings = (first.details as { warnings: string[] }).warnings;expect(warnings).toContain(UNADOPTABLE_TOKEN(SLUG));// Location only: no rejected claim text reaches the warnings.@@ -317,7 +318,7 @@ for (const backend of testBackends()) {const before = await factState(engine);const result = await extractFactsPhase(engine, root);expect(result.status).toBe('warn');- expect(result.summary).toBe('extract_facts skipped: 2 unfenced fact row(s) could not be fenced');+ expect(result.summary).toBe(`0 fact(s) reconciled across 0 page(s); skipped 1 page(s) holding 2 unfenced fact row(s) that could not be fenced: ${SLUG} (2 warning(s))`);const warnings = (result.details as { warnings: string[] }).warnings;expect(warnings.some(w => w.startsWith(`FACTS_FENCE_FAILED: ${SLUG} (canonical file `) && w.includes('does not exist on this host'))).toBe(true);expect(warnings.some(w => w.includes('v0.31') || w.includes('force-retry'))).toBe(false);