@@ -51,10 +51,11 @@ export class Remote {
5151 * Try to get the workspace running. Return undefined if the user canceled.
5252 */
5353private async maybeWaitForRunning (
54- restClient :Api ,
5554workspace :Workspace ,
5655label :string ,
5756binPath :string ,
57+ baseUrlRaw :string ,
58+ token :string ,
5859) :Promise < Workspace | undefined > {
5960const workspaceName = `${ workspace . owner_name } /${ workspace . name } `
6061
@@ -94,6 +95,7 @@ export class Remote {
9495title :"Waiting for workspace build..." ,
9596} ,
9697async ( ) => {
98+ let restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
9799const globalConfigDir = path . dirname ( this . storage . getSessionTokenPath ( label ) )
98100while ( workspace . latest_build . status !== "running" ) {
99101++ attempts
@@ -109,6 +111,9 @@ export class Remote {
109111if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
110112return 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 )
112117writeEmitter = initWriteEmitterAndTerminal ( )
113118this . storage . writeToCoderOutputChannel ( `Starting${ workspaceName } ...` )
114119workspace = await startWorkspaceIfStoppedOrFailed (
@@ -126,6 +131,9 @@ export class Remote {
126131if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
127132return 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 )
129137writeEmitter = initWriteEmitterAndTerminal ( )
130138this . storage . writeToCoderOutputChannel ( `Starting${ workspaceName } ...` )
131139workspace = 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.
318326if ( 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.
321329await this . closeRemote ( )
322330} else {