Skip to content

Refactor timeline event polling to use timeout-based approach for Copilot sessions #7484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/github/copilotRemoteAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve, reject) => {
let cancellationListener: vscode.Disposable | undefined;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,18 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
// need to wait until we get the updated timeline events
let events: TimelineEvent[] = [];
if (result) {
do {
// Wait for the first copilot timeline event with timeout
const maxWaitTime = 60 * 1000; // 1 minute timeout
const pollInterval = 2000; // 2 seconds
const startTime = Date.now();

while (Date.now() - startTime < maxWaitTime) {
events = await this._getTimeline();
} while (copilotEventToStatus(mostRecentCopilotEvent(events)) !== CopilotPRStatus.Completed && await new Promise<boolean>(c => setTimeout(() => c(true), 2000)));
if (copilotEventToStatus(mostRecentCopilotEvent(events)) === CopilotPRStatus.Completed) {
break;
}
await new Promise<void>(resolve => setTimeout(resolve, pollInterval));
}
}
const reply: CancelCodingAgentReply = {
events
Expand Down