From 69d0b23ab6a86ff90467e31991a7eba33a11f424 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Tue, 24 Mar 2026 16:23:11 +0900 Subject: [PATCH] fix(anthropic-recovery): clear session state after successful summarize and fix timing test - Add missing clearSessionState() call after successful summarize (line 117) Without this, retry state persisted even after success, potentially causing unnecessary retries on subsequent compaction events. - Fix timing-sensitive test: adjust attempt=0 and firstAttemptTime to give proper remainingTimeMs buffer for capped delay calculation. Fixes #2225 Supersedes #2671 --- .../summarize-retry-strategy.test.ts | 6 +++--- .../summarize-retry-strategy.ts | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.test.ts b/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.test.ts index fa0fb295d..0818fbdd5 100644 --- a/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.test.ts +++ b/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.test.ts @@ -98,9 +98,9 @@ describe("runSummarizeRetryStrategy", () => { }) as typeof setTimeout autoCompactState.retryStateBySession.set(sessionID, { - attempt: 1, + attempt: 0, lastAttemptTime: Date.now(), - firstAttemptTime: Date.now() - 119700, + firstAttemptTime: Date.now() - 119900, }) summarizeMock.mockRejectedValueOnce(new Error("rate limited")) @@ -117,6 +117,6 @@ describe("runSummarizeRetryStrategy", () => { //#then expect(timeoutCalls.length).toBe(1) expect(timeoutCalls[0]!.delay).toBeGreaterThan(0) - expect(timeoutCalls[0]!.delay).toBeLessThanOrEqual(500) + expect(timeoutCalls[0]!.delay).toBeLessThanOrEqual(300) }) }) diff --git a/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.ts b/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.ts index 008ff74a5..36a5d1a8c 100644 --- a/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.ts +++ b/src/hooks/anthropic-context-window-limit-recovery/summarize-retry-strategy.ts @@ -114,6 +114,7 @@ export async function runSummarizeRetryStrategy(params: { body: summarizeBody as never, query: { directory: params.directory }, }) + clearSessionState(params.autoCompactState, params.sessionID) return } catch { const remainingTimeMs = SUMMARIZE_RETRY_TOTAL_TIMEOUT_MS - (Date.now() - retryState.firstAttemptTime)