@@ -51,10 +51,11 @@ export class Remote {
5151 * Try to get the workspace running. Return undefined if the user canceled.
5252 */
5353 private async maybeWaitForRunning (
54- restClient : Api ,
5554 workspace : Workspace ,
5655 label : string ,
5756 binPath : string ,
57+ baseUrlRaw : string ,
58+ token : string ,
5859 ) : Promise < Workspace | undefined > {
5960 const workspaceName = `${ workspace . owner_name } /${ workspace . name } `
6061
@@ -94,6 +95,7 @@ export class Remote {
9495 title : "Waiting for workspace build..." ,
9596 } ,
9697 async ( ) => {
98+ let restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
9799 const globalConfigDir = path . dirname ( this . storage . getSessionTokenPath ( label ) )
98100 while ( workspace . latest_build . status !== "running" ) {
99101 ++ attempts
@@ -109,6 +111,9 @@ export class Remote {
109111 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
110112 return undefined
111113 }
114+ // Recreate REST client since confirmStart may have waited an
115+ // indeterminate amount of time for confirmation.
116+ restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
112117 writeEmitter = initWriteEmitterAndTerminal ( )
113118 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
114119 workspace = await startWorkspaceIfStoppedOrFailed (
@@ -126,6 +131,9 @@ export class Remote {
126131 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
127132 return undefined
128133 }
134+ // Recreate REST client since confirmStart may have waited an
135+ // indeterminate amount of time for confirmation.
136+ restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
129137 writeEmitter = initWriteEmitterAndTerminal ( )
130138 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
131139 workspace = await startWorkspaceIfStoppedOrFailed (
@@ -316,7 +324,7 @@ export class Remote {
316324
317325 // If the workspace is not in a running state, try to get it running.
318326 if ( workspace . latest_build . status !== "running" ) {
319- if ( ! ( await this . maybeWaitForRunning ( workspaceRestClient , workspace , parts . label , binaryPath ) ) ) {
327+ if ( ! ( await this . maybeWaitForRunning ( workspace , parts . label , binaryPath , baseUrlRaw , token ) ) ) {
320328 // User declined to start the workspace.
321329 await this . closeRemote ( )
322330 } else {
0 commit comments