fix: refresh history key order for LRU eviction

This commit is contained in:
Shadow
2026-01-26 15:23:51 -06:00
committed by Shadow
parent af9606de36
commit 5c35b62a5c

View File

@@ -54,6 +54,10 @@ export function appendHistoryEntry<T extends HistoryEntry>(params: {
const history = historyMap.get(historyKey) ?? [];
history.push(entry);
while (history.length > params.limit) history.shift();
if (historyMap.has(historyKey)) {
// Refresh insertion order so eviction keeps recently used histories.
historyMap.delete(historyKey);
}
historyMap.set(historyKey, history);
// Evict oldest keys if map exceeds max size to prevent unbounded memory growth
evictOldHistoryKeys(historyMap);