From 61e093094e8ceba20de83d005233051123a500a3 Mon Sep 17 00:00:00 2001 From: 7418 <7418@openclaw.ai> Date: Tue, 24 Feb 2026 17:50:49 +0800 Subject: [PATCH] fix: auto-fallback to fresh conversation when SDK session resume fails When continuing an old chat session, CodePilot passes the stored sdk_session_id to the SDK with resume=true. If the local SDK session file is stale, corrupt, or incompatible (e.g. after a CLI version update), the SDK process exits with code 1 and the user sees a misleading "Invalid or missing API Key" error. This fix wraps the initial query() call with a try-catch that detects resume failures by peeking at the first async message. On failure, it automatically retries without the resume option, starting a fresh SDK session while preserving the chat history in CodePilot. - src/lib/claude-client.ts: added resume-failure detection and automatic fallback logic around the query() call --- src/lib/claude-client.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib/claude-client.ts b/src/lib/claude-client.ts index 366dab1..66f4120 100644 --- a/src/lib/claude-client.ts +++ b/src/lib/claude-client.ts @@ -533,11 +533,41 @@ export function streamClaude(options: ClaudeStreamOptions): ReadableStream; + } catch (resumeError) { + console.warn('[claude-client] Resume failed, retrying without resume:', resumeError instanceof Error ? resumeError.message : resumeError); + // Remove resume and try again as a fresh conversation + delete queryOptions.resume; + conversation = query({ + prompt: finalPrompt, + options: queryOptions, + }); + } + } + registerConversation(sessionId, conversation); let lastAssistantText = '';