From f871087a8486c717450456b6e5fe399df2acad56 Mon Sep 17 00:00:00 2001 From: 7418 <7418@openclaw.ai> Date: Tue, 24 Feb 2026 17:56:38 +0800 Subject: [PATCH] fix: clear stale sdk_session_id on mid-stream crash to prevent repeated failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a resumed SDK session crashes mid-stream (after outputting some content), the sdk_session_id remains in the database. Every subsequent message in that chat session attempts to resume the same broken SDK session, causing repeated failures. Root cause: the SDK process starts successfully with resume, outputs some content, then crashes (exit code 1). The sdk_session_id was already stored from a previous successful turn and never gets cleared on error. Fix: in the catch block of streamClaude(), when we were resuming a session (sdkSessionId is set), clear the sdk_session_id in the database. This ensures the next message starts a fresh SDK session instead of repeatedly hitting the same broken resume. Combined with the earlier peek-based fallback (which handles failures at startup), this covers both failure modes: 1. Resume fails immediately → fallback retries without resume in the same request 2. Resume fails mid-stream → clears sdk_session_id so the NEXT request starts fresh - src/lib/claude-client.ts: import updateSdkSessionId, add sdk_session_id reset in catch block when sdkSessionId was set --- src/lib/claude-client.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/claude-client.ts b/src/lib/claude-client.ts index 66f4120..d75b514 100644 --- a/src/lib/claude-client.ts +++ b/src/lib/claude-client.ts @@ -19,7 +19,7 @@ import type { ClaudeStreamOptions, SSEEvent, TokenUsage, MCPServerConfig, Permis import { isImageFile } from '@/types'; import { registerPendingPermission } from './permission-registry'; import { registerConversation, unregisterConversation } from './conversation-registry'; -import { getSetting, getActiveProvider } from './db'; +import { getSetting, getActiveProvider, updateSdkSessionId } from './db'; import { findClaudeBinary, findGitBash, getExpandedPath } from './platform'; import os from 'os'; import fs from 'fs'; @@ -747,6 +747,19 @@ export function streamClaude(options: ClaudeStreamOptions): ReadableStream