Skip to content

Commit 57d1f2f

Browse files
authored
fix #7783 (main) (#7784) (#7785)
* move waitForQueuedToInProgress to inside invoke * accept cancellationToken
1 parent 896fb88 commit 57d1f2f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/github/copilotRemoteAgent.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ export class CopilotRemoteAgentManager extends Disposable {
449449
const result = await this.invokeRemoteAgent(
450450
userPrompt,
451451
summary,
452+
undefined,
452453
autoPushAndCommit,
453454
);
454455

@@ -513,7 +514,7 @@ export class CopilotRemoteAgentManager extends Disposable {
513514
return vscode.l10n.t('🚀 Coding agent will continue work in [#{0}]({1}). Track progress [here]({2}).', number, link, webviewUri.toString());
514515
}
515516

516-
async invokeRemoteAgent(prompt: string, problemContext?: string, autoPushAndCommit = true): Promise<RemoteAgentResult> {
517+
async invokeRemoteAgent(prompt: string, problemContext?: string, token?: vscode.CancellationToken, autoPushAndCommit = true): Promise<RemoteAgentResult> {
517518
const capiClient = await this.copilotApi;
518519
if (!capiClient) {
519520
return { error: vscode.l10n.t('Failed to initialize Copilot API'), state: 'error' };
@@ -589,6 +590,8 @@ export class CopilotRemoteAgentManager extends Disposable {
589590
this._onDidCreatePullRequest.fire(pull_request.number);
590591
const webviewUri = await toOpenPullRequestWebviewUri({ owner, repo, pullRequestNumber: pull_request.number });
591592
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.`;
593+
594+
await this.waitForQueuedToInProgress(session_id, token);
592595
return {
593596
state: 'success',
594597
number: pull_request.number,
@@ -809,22 +812,21 @@ export class CopilotRemoteAgentManager extends Disposable {
809812
this.extractFileReferences(request.references),
810813
await this.extractHistory(history)
811814
].join('\n\n').trim(),
815+
token,
812816
false,
813817
);
814818
if (result.state !== 'success') {
815819
Logger.error(`Failed to provide new chat session item: ${result.error}`, CopilotRemoteAgentManager.ID);
816820
throw new Error(`Failed to provide new chat session item: ${result.error}`);
817821
}
818822

819-
const { number, sessionId } = result;
823+
const { number } = result;
820824

821825
const pullRequest = await this.findPullRequestById(number, true);
822826
if (!pullRequest) {
823827
throw new Error(`Failed to find session for pull request: ${number}`);
824828
}
825829

826-
await this.waitForQueuedToInProgress(sessionId, token);
827-
828830
const timeline = await pullRequest.getCopilotTimelineEvents(pullRequest);
829831
const status = copilotEventToSessionStatus(mostRecentCopilotEvent(timeline));
830832
const tooltip = await issueMarkdown(pullRequest, this.context, this.repositoriesManager);
@@ -972,6 +974,7 @@ export class CopilotRemoteAgentManager extends Disposable {
972974
const result = await this.invokeRemoteAgent(
973975
prompt,
974976
summary || prompt,
977+
undefined,
975978
false,
976979
);
977980
this.ephemeralChatSessions.delete(id); // TODO: Better state management
@@ -1462,7 +1465,7 @@ export class CopilotRemoteAgentManager extends Disposable {
14621465

14631466
private async waitForQueuedToInProgress(
14641467
sessionId: string,
1465-
token: vscode.CancellationToken
1468+
token?: vscode.CancellationToken
14661469
): Promise<SessionInfo | undefined> {
14671470
const capi = await this.copilotApi;
14681471
if (!capi) {
@@ -1479,7 +1482,7 @@ export class CopilotRemoteAgentManager extends Disposable {
14791482
}
14801483

14811484
Logger.appendLine(`Session ${sessionInfo.id} is queued, waiting to start...`, CopilotRemoteAgentManager.ID);
1482-
while (Date.now() - startTime < maxWaitTime && !token.isCancellationRequested) {
1485+
while (Date.now() - startTime < maxWaitTime && (!token || !token.isCancellationRequested)) {
14831486
const sessionInfo = await capi.getSessionInfo(sessionId);
14841487
if (sessionInfo?.state === 'in_progress') {
14851488
Logger.appendLine(`Session ${sessionInfo.id} now in progress.`, CopilotRemoteAgentManager.ID);

src/test/mocks/mockExtensionContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class MockExtensionContext implements ExtensionContext {
2727
delete(key: string): Thenable<void> {
2828
throw new Error('Method not implemented.');
2929
}
30+
3031
onDidChange!: Event<SecretStorageChangeEvent>;
3132
})();
3233
subscriptions: { dispose(): any }[] = [];

0 commit comments

Comments
 (0)