diff --git a/src/agents/command/attempt-execution.cli.test.ts b/src/agents/command/attempt-execution.cli.test.ts index 2f3be0c11ff4..4cd444e6ec93 100644 --- a/src/agents/command/attempt-execution.cli.test.ts +++ b/src/agents/command/attempt-execution.cli.test.ts @@ -1314,6 +1314,17 @@ describe("CLI attempt execution", () => { ); await replaceSessionEntry({ sessionKey, storePath }, concurrentEntry); sessionStore[sessionKey] = concurrentEntry; + const clearBeforeFreshRetry = runArgs.onBeforeFreshCliSessionRetry; + expect(clearBeforeFreshRetry).toBeTypeOf("function"); + await expect( + ( + clearBeforeFreshRetry as (params: { + provider: string; + reason: "timeout"; + sessionId: string; + }) => Promise + )({ provider: "claude-cli", reason: "timeout", sessionId: forkedCliSessionId }), + ).resolves.toBe(false); throw recoveryError; }); diff --git a/src/agents/command/session-store.ts b/src/agents/command/session-store.ts index b0abbffbe5f4..3f6ce6cadb5b 100644 --- a/src/agents/command/session-store.ts +++ b/src/agents/command/session-store.ts @@ -337,6 +337,7 @@ export async function clearCliSessionInStore(params: { return undefined; } + let didClear = false; const persisted = await patchSessionEntry( { storePath, @@ -358,14 +359,16 @@ export async function clearCliSessionInStore(params: { const next = { ...currentEntry }; clearCliSession(next, provider); next.updatedAt = Date.now(); + didClear = true; return next; }, { fallbackEntry: entry }, ); - if (persisted) { + if (persisted && didClear) { sessionStore[sessionKey] = persisted; + return persisted; } - return persisted ?? undefined; + return undefined; } /** Clears the one-shot fork marker before the resumed CLI process starts. */