From 12f84fb730e5972262beae544f04fc7f9de351b6 Mon Sep 17 00:00:00 2001 From: yiliang114 <1204183885@qq.com> Date: Wed, 17 Dec 2025 21:00:26 +0800 Subject: [PATCH] fix(vscode-ide-companion): optimize stream termination handling and remove timeout for session_prompt --- .../src/services/acpSessionManager.ts | 32 +++++++++++-------- .../webview/handlers/SessionMessageHandler.ts | 11 ++++--- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/vscode-ide-companion/src/services/acpSessionManager.ts b/packages/vscode-ide-companion/src/services/acpSessionManager.ts index cfa299bf..e2055a3a 100644 --- a/packages/vscode-ide-companion/src/services/acpSessionManager.ts +++ b/packages/vscode-ide-companion/src/services/acpSessionManager.ts @@ -54,27 +54,31 @@ export class AcpSessionManager { }; return new Promise((resolve, reject) => { - // different timeout durations based on methods - let timeoutDuration = 60000; // default 60 seconds - if ( - method === AGENT_METHODS.session_prompt || - method === AGENT_METHODS.initialize - ) { - timeoutDuration = 120000; // 2min for session_prompt and initialize - } + // No timeout for session_prompt as LLM tasks can take 5-10 minutes or longer + // The request should always terminate with a stop_reason + let timeoutId: NodeJS.Timeout | undefined; + let timeoutDuration: number | undefined; - const timeoutId = setTimeout(() => { - pendingRequests.delete(id); - reject(new Error(`Request ${method} timed out`)); - }, timeoutDuration); + if (method !== AGENT_METHODS.session_prompt) { + // Set timeout for other methods + timeoutDuration = method === AGENT_METHODS.initialize ? 120000 : 60000; + timeoutId = setTimeout(() => { + pendingRequests.delete(id); + reject(new Error(`Request ${method} timed out`)); + }, timeoutDuration); + } const pendingRequest: PendingRequest = { resolve: (value: T) => { - clearTimeout(timeoutId); + if (timeoutId) { + clearTimeout(timeoutId); + } resolve(value); }, reject: (error: Error) => { - clearTimeout(timeoutId); + if (timeoutId) { + clearTimeout(timeoutId); + } reject(error); }, timeoutId, diff --git a/packages/vscode-ide-companion/src/webview/handlers/SessionMessageHandler.ts b/packages/vscode-ide-companion/src/webview/handlers/SessionMessageHandler.ts index 4b4ca09c..d8861b95 100644 --- a/packages/vscode-ide-companion/src/webview/handlers/SessionMessageHandler.ts +++ b/packages/vscode-ide-companion/src/webview/handlers/SessionMessageHandler.ts @@ -440,24 +440,25 @@ export class SessionMessageHandler extends BaseMessageHandler { const isTimeoutError = lower.includes('timeout') || lower.includes('timed out'); if (isTimeoutError) { - // Timeout has no action for the user to perform, so only reset the information in the panel and no VS Code error alert will pop up. + // Note: session_prompt no longer has a timeout, so this should rarely occur + // This path may still be hit for other methods (initialize, etc.) or network-level timeouts console.warn( - '[SessionMessageHandler] Prompt timed out; suppressing popup', + '[SessionMessageHandler] Request timed out; suppressing popup', ); const timeoutMessage: ChatMessage = { role: 'assistant', content: - 'Request timed out (no response within 120 seconds). Please try again or simplify the request.', + 'Request timed out. This may be due to a network issue. Please try again.', timestamp: Date.now(), }; - // Send a timeout message to the WebView without terminating the stream - // In this way, the long-term task can continue to receive subsequent messages after timeout. + // Send a timeout message to the WebView this.sendToWebView({ type: 'message', data: timeoutMessage, }); + this.sendStreamEnd('timeout'); } else { // Handling of Non-Timeout Errors vscode.window.showErrorMessage(`Error sending message: ${error}`);