diff --git a/src/github/copilotRemoteAgent.ts b/src/github/copilotRemoteAgent.ts index 67e4d63198..a37ec48471 100644 --- a/src/github/copilotRemoteAgent.ts +++ b/src/github/copilotRemoteAgent.ts @@ -1185,6 +1185,8 @@ export class CopilotRemoteAgentManager extends Disposable { let lastProcessedLength = 0; let hasActiveProgress = false; const pollingInterval = 3000; // 3 seconds + const maxWaitTime = 60 * 60 * 1000; // 1 hour timeout for long-running sessions + const startTime = Date.now(); return new Promise((resolve, reject) => { let cancellationListener: vscode.Disposable | undefined; @@ -1229,6 +1231,14 @@ export class CopilotRemoteAgentManager extends Disposable { return; } + // Check for timeout + if (Date.now() - startTime > maxWaitTime) { + Logger.appendLine(`Session polling timed out after ${maxWaitTime / 1000} seconds`, CopilotRemoteAgentManager.ID); + stream.markdown(vscode.l10n.t('Session polling timed out. The session may still be running.')); + complete(); + return; + } + // Get the specific session info const sessionInfo = await capi.getSessionInfo(sessionId); if (!sessionInfo || token.isCancellationRequested) { @@ -1286,7 +1296,7 @@ export class CopilotRemoteAgentManager extends Disposable { } } catch (error) { Logger.error(`Error polling for session updates: ${error}`, CopilotRemoteAgentManager.ID); - if (!token.isCancellationRequested) { + if (!token.isCancellationRequested && Date.now() - startTime <= maxWaitTime) { setTimeout(pollForUpdates, pollingInterval); } else { reject(error); diff --git a/src/github/pullRequestOverview.ts b/src/github/pullRequestOverview.ts index 107e22675c..77bb088e84 100644 --- a/src/github/pullRequestOverview.ts +++ b/src/github/pullRequestOverview.ts @@ -516,9 +516,18 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel(c => setTimeout(() => c(true), 2000))); + if (copilotEventToStatus(mostRecentCopilotEvent(events)) === CopilotPRStatus.Completed) { + break; + } + await new Promise(resolve => setTimeout(resolve, pollInterval)); + } } const reply: CancelCodingAgentReply = { events