mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix(vscode-ide-companion): optimize stream termination handling and remove timeout for session_prompt
This commit is contained in:
@@ -54,27 +54,31 @@ export class AcpSessionManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// different timeout durations based on methods
|
// No timeout for session_prompt as LLM tasks can take 5-10 minutes or longer
|
||||||
let timeoutDuration = 60000; // default 60 seconds
|
// The request should always terminate with a stop_reason
|
||||||
if (
|
let timeoutId: NodeJS.Timeout | undefined;
|
||||||
method === AGENT_METHODS.session_prompt ||
|
let timeoutDuration: number | undefined;
|
||||||
method === AGENT_METHODS.initialize
|
|
||||||
) {
|
|
||||||
timeoutDuration = 120000; // 2min for session_prompt and initialize
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeoutId = setTimeout(() => {
|
if (method !== AGENT_METHODS.session_prompt) {
|
||||||
pendingRequests.delete(id);
|
// Set timeout for other methods
|
||||||
reject(new Error(`Request ${method} timed out`));
|
timeoutDuration = method === AGENT_METHODS.initialize ? 120000 : 60000;
|
||||||
}, timeoutDuration);
|
timeoutId = setTimeout(() => {
|
||||||
|
pendingRequests.delete(id);
|
||||||
|
reject(new Error(`Request ${method} timed out`));
|
||||||
|
}, timeoutDuration);
|
||||||
|
}
|
||||||
|
|
||||||
const pendingRequest: PendingRequest<T> = {
|
const pendingRequest: PendingRequest<T> = {
|
||||||
resolve: (value: T) => {
|
resolve: (value: T) => {
|
||||||
clearTimeout(timeoutId);
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
resolve(value);
|
resolve(value);
|
||||||
},
|
},
|
||||||
reject: (error: Error) => {
|
reject: (error: Error) => {
|
||||||
clearTimeout(timeoutId);
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
reject(error);
|
reject(error);
|
||||||
},
|
},
|
||||||
timeoutId,
|
timeoutId,
|
||||||
|
|||||||
@@ -440,24 +440,25 @@ export class SessionMessageHandler extends BaseMessageHandler {
|
|||||||
const isTimeoutError =
|
const isTimeoutError =
|
||||||
lower.includes('timeout') || lower.includes('timed out');
|
lower.includes('timeout') || lower.includes('timed out');
|
||||||
if (isTimeoutError) {
|
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(
|
console.warn(
|
||||||
'[SessionMessageHandler] Prompt timed out; suppressing popup',
|
'[SessionMessageHandler] Request timed out; suppressing popup',
|
||||||
);
|
);
|
||||||
|
|
||||||
const timeoutMessage: ChatMessage = {
|
const timeoutMessage: ChatMessage = {
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content:
|
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(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send a timeout message to the WebView without terminating the stream
|
// Send a timeout message to the WebView
|
||||||
// In this way, the long-term task can continue to receive subsequent messages after timeout.
|
|
||||||
this.sendToWebView({
|
this.sendToWebView({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
data: timeoutMessage,
|
data: timeoutMessage,
|
||||||
});
|
});
|
||||||
|
this.sendStreamEnd('timeout');
|
||||||
} else {
|
} else {
|
||||||
// Handling of Non-Timeout Errors
|
// Handling of Non-Timeout Errors
|
||||||
vscode.window.showErrorMessage(`Error sending message: ${error}`);
|
vscode.window.showErrorMessage(`Error sending message: ${error}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user