@@ -470,6 +470,7 @@ export class CopilotRemoteAgentManager extends Disposable {
470470 const result = await this . invokeRemoteAgent (
471471 userPrompt ,
472472 summary ,
473+ undefined ,
473474 autoPushAndCommit ,
474475 ) ;
475476
@@ -534,7 +535,7 @@ export class CopilotRemoteAgentManager extends Disposable {
534535 return vscode . l10n . t ( '🚀 Coding agent will continue work in [#{0}]({1}). Track progress [here]({2}).' , number , link , webviewUri . toString ( ) ) ;
535536 }
536537
537- async invokeRemoteAgent ( prompt : string , problemContext ?: string , autoPushAndCommit = true ) : Promise < RemoteAgentResult > {
538+ async invokeRemoteAgent ( prompt : string , problemContext ?: string , token ?: vscode . CancellationToken , autoPushAndCommit = true ) : Promise < RemoteAgentResult > {
538539 const capiClient = await this . copilotApi ;
539540 if ( ! capiClient ) {
540541 return { error : vscode . l10n . t ( 'Failed to initialize Copilot API' ) , state : 'error' } ;
@@ -610,6 +611,8 @@ export class CopilotRemoteAgentManager extends Disposable {
610611 this . _onDidCreatePullRequest . fire ( pull_request . number ) ;
611612 const webviewUri = await toOpenPullRequestWebviewUri ( { owner, repo, pullRequestNumber : pull_request . number } ) ;
612613 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.` ;
614+
615+ await this . waitForQueuedToInProgress ( session_id , token ) ;
613616 return {
614617 state : 'success' ,
615618 number : pull_request . number ,
@@ -830,22 +833,21 @@ export class CopilotRemoteAgentManager extends Disposable {
830833 this . extractFileReferences ( request . references ) ,
831834 await this . extractHistory ( history )
832835 ] . join ( '\n\n' ) . trim ( ) ,
836+ token ,
833837 false ,
834838 ) ;
835839 if ( result . state !== 'success' ) {
836840 Logger . error ( `Failed to provide new chat session item: ${ result . error } ` , CopilotRemoteAgentManager . ID ) ;
837841 throw new Error ( `Failed to provide new chat session item: ${ result . error } ` ) ;
838842 }
839843
840- const { number, sessionId } = result ;
844+ const { number } = result ;
841845
842846 const pullRequest = await this . findPullRequestById ( number , true ) ;
843847 if ( ! pullRequest ) {
844848 throw new Error ( `Failed to find session for pull request: ${ number } ` ) ;
845849 }
846850
847- await this . waitForQueuedToInProgress ( sessionId , token ) ;
848-
849851 const timeline = await pullRequest . getCopilotTimelineEvents ( pullRequest ) ;
850852 const status = copilotEventToSessionStatus ( mostRecentCopilotEvent ( timeline ) ) ;
851853 const tooltip = await issueMarkdown ( pullRequest , this . context , this . repositoriesManager ) ;
@@ -993,6 +995,7 @@ export class CopilotRemoteAgentManager extends Disposable {
993995 const result = await this . invokeRemoteAgent (
994996 prompt ,
995997 summary || prompt ,
998+ undefined ,
996999 false ,
9971000 ) ;
9981001 this . ephemeralChatSessions . delete ( id ) ; // TODO: Better state management
@@ -1504,7 +1507,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15041507
15051508 private async waitForQueuedToInProgress (
15061509 sessionId : string ,
1507- token : vscode . CancellationToken
1510+ token ? : vscode . CancellationToken
15081511 ) : Promise < SessionInfo | undefined > {
15091512 const capi = await this . copilotApi ;
15101513 if ( ! capi ) {
@@ -1521,7 +1524,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15211524 }
15221525
15231526 Logger . appendLine ( `Session ${ sessionInfo . id } is queued, waiting to start...` , CopilotRemoteAgentManager . ID ) ;
1524- while ( Date . now ( ) - startTime < maxWaitTime && ! token . isCancellationRequested ) {
1527+ while ( Date . now ( ) - startTime < maxWaitTime && ( ! token || ! token . isCancellationRequested ) ) {
15251528 const sessionInfo = await capi . getSessionInfo ( sessionId ) ;
15261529 if ( sessionInfo ?. state === 'in_progress' ) {
15271530 Logger . appendLine ( `Session ${ sessionInfo . id } now in progress.` , CopilotRemoteAgentManager . ID ) ;
0 commit comments