Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(extract): --dry-run must not write extract_rollup_7d (#2994)

Anton Senkovskiy6498b872ea54
diff --git a/src/commands/extract-conversation-facts.ts b/src/commands/extract-conversation-facts.ts
index f1d04e4e3b..65e8a4ac42 100644
--- a/src/commands/extract-conversation-facts.ts
+++ b/src/commands/extract-conversation-facts.ts
@@ -1069,7 +1069,8 @@ export async function runExtractConversationFactsCore(
}
// Fall through to receipt+rollup write so the partial run is
// still observable in extract_health doctor + extracts/ pages.
- await writeRunReceiptAndRollup(engine, sourceId, result, /* halted */ true);
+ // ...but not under --dry-run: a preview must not persist cache state.
+ if (!dryRun) await writeRunReceiptAndRollup(engine, sourceId, result, /* halted */ true);
// Return partial result — caller (CLI / Minion) decides how to
// surface. NOT a thrown failure.
return result;
@@ -1081,7 +1082,9 @@ export async function runExtractConversationFactsCore(
// (queryable + citable per D-EXTRACT-17/19) AND UPSERTs the per-day
// rollup row (best-effort cache per F-OUT-19). Both are best-effort —
// failures stderr-warn but never fail the parent operation.
- await writeRunReceiptAndRollup(engine, sourceId, result, /* halted */ false);
+ // --dry-run must not persist cache/knowledge state: skip the rollup UPSERT +
+ // receipt-page write so a preview leaves no extract cache row behind.
+ if (!dryRun) await writeRunReceiptAndRollup(engine, sourceId, result, /* halted */ false);
return result;
}
diff --git a/test/extract-conversation-facts.test.ts b/test/extract-conversation-facts.test.ts
index bcc0e4d1f2..865022c132 100644
--- a/test/extract-conversation-facts.test.ts
+++ b/test/extract-conversation-facts.test.ts
@@ -306,6 +306,7 @@ describe('runExtractConversationFactsCore', () => {
// truncation semantics than the canonical reset helper.
await engine.executeRaw(`DELETE FROM facts WHERE source LIKE 'cli:extract-conversation-facts%'`);
await engine.executeRaw(`DELETE FROM op_checkpoints WHERE op = 'extract-conversation-facts'`);
+ await engine.executeRaw(`DELETE FROM extract_rollup_7d`);
await engine.executeRaw(`DELETE FROM pages WHERE slug LIKE 'conversations/%' OR slug LIKE 'people/alice%'`);
// Set facts.extraction_enabled=true so kill-switch doesn't refuse.
await engine.setConfig('facts.extraction_enabled', 'true');
@@ -365,6 +366,21 @@ describe('runExtractConversationFactsCore', () => {
expect(result.segments_processed).toBeGreaterThanOrEqual(1);
});
+ test('dry-run does not write the extract_rollup_7d cache row', async () => {
+ // Regression: --dry-run promises "no DB writes" but writeRunReceiptAndRollup
+ // upsert-ed extract_rollup_7d unconditionally. A preview must not mutate the DB.
+ await runExtractConversationFactsCore(engine, {
+ sourceId: 'default',
+ slug: 'conversations/imessage/alice-example',
+ dryRun: true,
+ sleepMs: 0,
+ });
+ const rows = await engine.executeRaw<{ count: string | number }>(
+ `SELECT COUNT(*) AS count FROM extract_rollup_7d WHERE kind = 'facts.conversation' AND source_id = 'default'`,
+ );
+ expect(Number(rows[0]?.count ?? 0)).toBe(0);
+ });
+
test('non-conversation pages are skipped', async () => {
const result = await runExtractConversationFactsCore(engine, {
sourceId: 'default',