Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(search): a correction saved in the same flush as the post it corrects counts as newer
garrytana7297ef1a9f2
diff --git a/src/core/ops/search.ts b/src/core/ops/search.tsindex f8acae43e3..631d24358f 100644--- a/src/core/ops/search.ts+++ b/src/core/ops/search.ts@@ -464,8 +464,9 @@ async function matchingSavedFacts(ctx: OperationContext, scope: SourceScope, queconst admitted = found.filter(r => r.words.size >= r.need);if (supersede) {for (const older of admitted) {- const correction = found.filter(n => n.cue && n.fact.id !== older.fact.id && n.at > older.at- && [...n.words].filter(w => older.words.has(w)).length >= Math.min(2, n.need)).sort((a, b) => b.at - a.at)[0];+ // Posts saved in one flush share a time; the later id is the later post.+ const correction = found.filter(n => n.cue && (n.at > older.at || (n.at === older.at && n.fact.id > older.fact.id))+ && [...n.words].filter(w => older.words.has(w)).length >= Math.min(2, n.need)).sort((a, b) => b.at - a.at || b.fact.id - a.fact.id)[0];if (correction) older.fact.corrected_by = correction.fact.id;}const correcting = new Set(admitted.flatMap(r => r.fact.corrected_by ? [r.fact.corrected_by] : []));diff --git a/test/search-saved-facts-match.test.ts b/test/search-saved-facts-match.test.tsindex 6178e129b0..3cec07e0da 100644--- a/test/search-saved-facts-match.test.ts+++ b/test/search-saved-facts-match.test.ts@@ -60,7 +60,8 @@ beforeAll(async () => {await importFromContent(engine, slug, serializeMarkdown({}, body, '', { type: 'note', title, tags: [] }), { noEmbed: true, forceRechunk: true });}ids.first = await remember(FIRST, '2026-09-02T09:00:00Z');- ids.correction = await remember(CORRECTION, '2026-09-02T09:30:00Z');+ // Saved with the same time as the post it corrects, as a flush of both posts saves them.+ ids.correction = await remember(CORRECTION, '2026-09-02T09:00:00Z');ids.question = await remember(QUESTION, '2026-09-04T09:00:00Z');ids.lease = await remember('Delta Example countersigned the warehouse lease.', '2026-09-01T09:00:00Z');ids.olderLease = await remember('The warehouse lease runs five years.', '2026-08-01T09:00:00Z');