fix(#2736): prevent infinite compaction loop by setting cooldown before try
lastCompactionTime was only set on successful compaction. When compaction failed (rate limit, timeout, etc.), no cooldown was recorded, causing immediate retries in an infinite loop. Fix: set lastCompactionTime before the try block so both success and failure respect the cooldown window. - test: add failed-compaction cooldown enforcement test - test: fix timeout retry test to advance past cooldown
This commit is contained in:
@@ -112,6 +112,7 @@ export function createPreemptiveCompactionHook(
|
||||
if (usageRatio < PREEMPTIVE_COMPACTION_THRESHOLD || !cached.modelID) return
|
||||
|
||||
compactionInProgress.add(sessionID)
|
||||
lastCompactionTime.set(sessionID, Date.now())
|
||||
|
||||
try {
|
||||
const { providerID: targetProviderID, modelID: targetModelID } = resolveCompactionModel(
|
||||
@@ -132,7 +133,6 @@ export function createPreemptiveCompactionHook(
|
||||
)
|
||||
|
||||
compactedSessions.add(sessionID)
|
||||
lastCompactionTime.set(sessionID, Date.now())
|
||||
} catch (error) {
|
||||
log("[preemptive-compaction] Compaction failed", { sessionID, error: String(error) })
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user