From 65ad9a4262e38d1407b75660cd65a68580579865 Mon Sep 17 00:00:00 2001 From: Rodrigo Uroz Date: Wed, 11 Feb 2026 20:56:56 +0000 Subject: [PATCH] Memory: fix MMR tie-break and temporal timestamp dedupe --- src/memory/mmr.ts | 2 +- src/memory/temporal-decay.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/memory/mmr.ts b/src/memory/mmr.ts index ec87b9e3ff3..dc7144db10c 100644 --- a/src/memory/mmr.ts +++ b/src/memory/mmr.ts @@ -163,7 +163,7 @@ export function mmrRerank(items: T[], config: Partial bestMMRScore || - (mmrScore === bestMMRScore && (bestItem === null || candidate.score > bestItem.score)) + (mmrScore === bestMMRScore && candidate.score > (bestItem?.score ?? -Infinity)) ) { bestMMRScore = mmrScore; bestItem = candidate; diff --git a/src/memory/temporal-decay.ts b/src/memory/temporal-decay.ts index adaf2ee4c37..d3643fc5c21 100644 --- a/src/memory/temporal-decay.ts +++ b/src/memory/temporal-decay.ts @@ -132,21 +132,22 @@ export async function applyTemporalDecayToHybridResults< } const nowMs = params.nowMs ?? Date.now(); - const timestampCache = new Map(); + const timestampPromiseCache = new Map>(); return Promise.all( params.results.map(async (entry) => { const cacheKey = `${entry.source}:${entry.path}`; - if (!timestampCache.has(cacheKey)) { - const timestamp = await extractTimestamp({ + let timestampPromise = timestampPromiseCache.get(cacheKey); + if (!timestampPromise) { + timestampPromise = extractTimestamp({ filePath: entry.path, source: entry.source, workspaceDir: params.workspaceDir, }); - timestampCache.set(cacheKey, timestamp); + timestampPromiseCache.set(cacheKey, timestampPromise); } - const timestamp = timestampCache.get(cacheKey) ?? null; + const timestamp = await timestampPromise; if (!timestamp) { return entry; }