fix(vscode-ide-companion): optimize stream termination handling and remove timeout for session_prompt

This commit is contained in:
yiliang114
2025-12-17 21:00:26 +08:00
parent 725843f9b3
commit 12f84fb730
2 changed files with 24 additions and 19 deletions

View File

@@ -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(() => {
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<T> = {
resolve: (value: T) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
resolve(value);
},
reject: (error: Error) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
reject(error);
},
timeoutId,

View File

@@ -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}`);