Skip to content

Commit 600fcc5

Browse files
authored
Fix cancellation not working for request handler and active response callback. (#7452)
* Fix cancellation not working for request handler and active response callback. * localization
1 parent e31d406 commit 600fcc5

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/github/copilotRemoteAgent.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ export class CopilotRemoteAgentManager extends Disposable {
10461046
return await this.parseSessionLogsIntoResponseTurn(pullRequest, logs, session);
10471047
} else if (session.state === 'in_progress') {
10481048
// For in-progress sessions without logs, create a placeholder response
1049-
const placeholderParts = [new vscode.ChatResponseMarkdownPart('Session is initializing...')];
1049+
const placeholderParts = [new vscode.ChatResponseProgressPart('Session is initializing...')];
10501050
const responseResult: vscode.ChatResult = {};
10511051
return new vscode.ChatResponseTurn2(placeholderParts, responseResult, 'copilot-swe-agent');
10521052
} else {
@@ -1184,7 +1184,16 @@ export class CopilotRemoteAgentManager extends Disposable {
11841184
const pollingInterval = 3000; // 3 seconds
11851185

11861186
return new Promise<void>((resolve, reject) => {
1187+
let cancellationListener: vscode.Disposable | undefined;
1188+
let isCompleted = false;
1189+
11871190
const complete = async () => {
1191+
if (isCompleted) {
1192+
return;
1193+
}
1194+
isCompleted = true;
1195+
cancellationListener?.dispose();
1196+
11881197
const multiDiffPart = await this.getFileChangesMultiDiffPart(pullRequest);
11891198
if (multiDiffPart) {
11901199
stream.push(multiDiffPart);
@@ -1198,6 +1207,24 @@ export class CopilotRemoteAgentManager extends Disposable {
11981207

11991208
resolve();
12001209
};
1210+
1211+
cancellationListener = token.onCancellationRequested(async () => {
1212+
if (isCompleted) {
1213+
return;
1214+
}
1215+
1216+
try {
1217+
const sessionInfo = await capi.getSessionInfo(sessionId);
1218+
if (sessionInfo && sessionInfo.state !== 'completed' && sessionInfo.workflow_run_id) {
1219+
await pullRequest.githubRepository.cancelWorkflow(sessionInfo.workflow_run_id);
1220+
stream.markdown(vscode.l10n.t('Session has been cancelled.'));
1221+
complete();
1222+
}
1223+
} catch (error) {
1224+
Logger.error(`Error while trying to cancel session ${sessionId} workflow: ${error}`, CopilotRemoteAgentManager.ID);
1225+
}
1226+
});
1227+
12011228
const pollForUpdates = async (): Promise<void> => {
12021229
try {
12031230
if (token.isCancellationRequested) {

0 commit comments

Comments
 (0)