Skip to content

Commit 503e2b3

Browse files
authored
make transitions feel faster (#8018)
1 parent 2fbf269 commit 503e2b3

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/github/copilotRemoteAgent.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,6 @@ export class CopilotRemoteAgentManager extends Disposable {
857857
const webviewUri = await toOpenPullRequestWebviewUri({ owner, repo, pullRequestNumber: number });
858858
const prLlmString = `The remote agent has begun work and has created a pull request. Details about the pull request are being shown to the user. If the user wants to track progress or iterate on the agent's work, they should use the pull request.`;
859859

860-
chatStream?.progress(vscode.l10n.t('Attaching to session'));
861-
await this.waitForQueuedToInProgress(response.session_id, token);
862860
this._onDidCreatePullRequest.fire(number);
863861
return {
864862
state: 'success',
@@ -1163,14 +1161,14 @@ export class CopilotRemoteAgentManager extends Disposable {
11631161
sessions: SessionInfo[],
11641162
pullRequest: PullRequestModel
11651163
): ((stream: vscode.ChatResponseStream, token: vscode.CancellationToken) => Thenable<void>) | undefined {
1166-
// Only the latest in-progress session gets activeResponseCallback
1167-
const inProgressSession = sessions
1164+
// Only the latest in-progress or queued session gets activeResponseCallback
1165+
const pendingSession = sessions
11681166
.slice()
11691167
.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())
1170-
.find(session => session.state === 'in_progress');
1168+
.find(session => session.state === 'in_progress' || session.state === 'queued');
11711169

1172-
if (inProgressSession) {
1173-
return this.createActiveResponseCallback(pullRequest, inProgressSession.id);
1170+
if (pendingSession) {
1171+
return this.createActiveResponseCallback(pullRequest, pendingSession.id);
11741172
}
11751173
return undefined;
11761174
}
@@ -1185,6 +1183,7 @@ export class CopilotRemoteAgentManager extends Disposable {
11851183
private createActiveResponseCallback(pullRequest: PullRequestModel, sessionId: string): (stream: vscode.ChatResponseStream, token: vscode.CancellationToken) => Thenable<void> {
11861184
return async (stream: vscode.ChatResponseStream, token: vscode.CancellationToken) => {
11871185
// Use the shared streaming logic
1186+
await this.waitForQueuedToInProgress(sessionId, stream, token);
11881187
return this.streamSessionLogs(stream, pullRequest, sessionId, token);
11891188
};
11901189
}
@@ -1500,6 +1499,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15001499

15011500
private async waitForQueuedToInProgress(
15021501
sessionId: string,
1502+
stream?: vscode.ChatResponseStream,
15031503
token?: vscode.CancellationToken
15041504
): Promise<SessionInfo | undefined> {
15051505
const capi = await this.copilotApi;
@@ -1517,6 +1517,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15171517
do {
15181518
sessionInfo = await capi.getSessionInfo(sessionId);
15191519
if (sessionInfo && sessionInfo.state === 'queued') {
1520+
stream?.progress(vscode.l10n.t('Attaching to session'));
15201521
Logger.trace('Queued session found', CopilotRemoteAgentManager.ID);
15211522
break;
15221523
}
@@ -1528,6 +1529,10 @@ export class CopilotRemoteAgentManager extends Disposable {
15281529
} while (waitForQueuedCount <= waitForQueuedMaxRetries && (!token || !token.isCancellationRequested));
15291530

15301531
if (!sessionInfo || sessionInfo.state !== 'queued') {
1532+
if (sessionInfo?.state === 'in_progress') {
1533+
Logger.trace('Session already in progress', CopilotRemoteAgentManager.ID);
1534+
return sessionInfo;
1535+
}
15311536
// Failure
15321537
Logger.trace('Failed to find queued session', CopilotRemoteAgentManager.ID);
15331538
return;
@@ -1546,6 +1551,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15461551
}
15471552
await new Promise(resolve => setTimeout(resolve, pollInterval));
15481553
}
1554+
Logger.warn(`Timed out waiting for session ${sessionId} to transition from queued to in_progress`, CopilotRemoteAgentManager.ID);
15491555
}
15501556

15511557
private async waitForNewSession(
@@ -1579,7 +1585,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15791585
if (!waitForTransitionToInProgress) {
15801586
return newSession;
15811587
}
1582-
const inProgressSession = await this.waitForQueuedToInProgress(newSession.id, token);
1588+
const inProgressSession = await this.waitForQueuedToInProgress(newSession.id, stream, token);
15831589
if (!inProgressSession) {
15841590
stream.markdown(vscode.l10n.t('Timed out waiting for coding agent to begin work. Please try again shortly.'));
15851591
return;

src/github/copilotRemoteAgent/chatSessionContentBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ export class ChatSessionContentBuilder {
9595
private async createResponseTurn(pullRequest: PullRequestModel, logs: string, session: SessionInfo): Promise<vscode.ChatResponseTurn2 | undefined> {
9696
if (logs.trim().length > 0) {
9797
return await this.parseSessionLogsIntoResponseTurn(pullRequest, logs, session);
98-
} else if (session.state === 'in_progress') {
98+
} else if (session.state === 'in_progress' || session.state === 'queued') {
9999
// For in-progress sessions without logs, create a placeholder response
100-
const placeholderParts = [new vscode.ChatResponseProgressPart('Session is initializing...')];
100+
const placeholderParts = [new vscode.ChatResponseProgressPart('Initializing session')];
101101
const responseResult: vscode.ChatResult = {};
102102
return new vscode.ChatResponseTurn2(placeholderParts, responseResult, COPILOT_SWE_AGENT);
103103
} else {

0 commit comments

Comments
 (0)