Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

refactor(claude): share the dead-session cleanup between the two retry paths

AdityaUmale8138c7cfa54f
diff --git a/scripts/testing/file-size-ratchet.test.ts b/scripts/testing/file-size-ratchet.test.ts
index 22a6803814..efe75cc34e 100644
--- a/scripts/testing/file-size-ratchet.test.ts
+++ b/scripts/testing/file-size-ratchet.test.ts
@@ -21,7 +21,7 @@ const LINES: Record<string, number> = {
"electron/main.mjs": 3160,
"server/store.ts": 2291,
"src/components/Sidebar.tsx": 1687,
- "server/drivers/claude.ts": 2090,
+ "server/drivers/claude.ts": 2087,
"server/drivers/acp/core.ts": 1704,
"server/drivers/codex.ts": 1718,
"server/routines.ts": 1567,
diff --git a/server/drivers/claude.ts b/server/drivers/claude.ts
index 767892c025..933505b151 100644
--- a/server/drivers/claude.ts
+++ b/server/drivers/claude.ts
@@ -893,6 +893,22 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
if (stopped) void session.finishClose?.();
});
};
+ /** Forgets a CLI that died mid-turn and removes its files, so the retry starts a clean session. */
+ const discardSession = (threadId: string, session: Session) => {
+ session.elicit.close();
+ if (session.mcpConfigPath) {
+ try {
+ rmSync(dirname(session.mcpConfigPath), { recursive: true, force: true });
+ } catch {}
+ session.mcpConfigPath = null;
+ }
+ if (session.systemPromptPath) {
+ removePrivateTempDir(session.systemPromptPath);
+ session.systemPromptPath = null;
+ }
+ sessions.delete(threadId);
+ session.turn = null;
+ };
const closeSession = (threadId: string, why: string) => {
const s = sessions.get(threadId);
if (!s || s.closing) return;
@@ -1731,19 +1747,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
session.broker = undefined;
failedBroker?.pause();
failedBroker?.close();
- session.elicit.close();
- if (session.mcpConfigPath) {
- try {
- rmSync(dirname(session.mcpConfigPath), { recursive: true, force: true });
- } catch {}
- session.mcpConfigPath = null;
- }
- if (session.systemPromptPath) {
- removePrivateTempDir(session.systemPromptPath);
- session.systemPromptPath = null;
- }
- sessions.delete(threadId);
- session.turn = null;
+ discardSession(threadId, session);
let delayMs = 0;
if (!endedBeforeTurn) {
retry.attempt++;
@@ -1813,19 +1817,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
});
session.broker?.close();
session.broker = undefined;
- session.elicit.close();
- if (session.mcpConfigPath) {
- try {
- rmSync(dirname(session.mcpConfigPath), { recursive: true, force: true });
- } catch {}
- session.mcpConfigPath = null;
- }
- if (session.systemPromptPath) {
- removePrivateTempDir(session.systemPromptPath);
- session.systemPromptPath = null;
- }
- sessions.delete(threadId);
- session.turn = null;
+ discardSession(threadId, session);
retry.rebuilt = recovery.replayed;
retryState.set(threadId, retry);
active.set(threadId, { stop: () => { retry.cancelled = true; retryAbort.abort(); }, turnId });