@@ -30,7 +30,7 @@ import type { OneWayWebSocket } from "../websocket/oneWayWebSocket";
3030export class WorkspaceStateMachine implements vscode . Disposable {
3131 private readonly terminal : TerminalSession ;
3232
33- private agentId : string | undefined ;
33+ private agent : { id : string ; name : string } | undefined ;
3434
3535 private buildLogSocket : OneWayWebSocket < ProvisionerJobLog > | null = null ;
3636
@@ -46,7 +46,7 @@ export class WorkspaceStateMachine implements vscode.Disposable {
4646 private readonly pathResolver : PathResolver ,
4747 private readonly vscodeProposed : typeof vscode ,
4848 ) {
49- this . terminal = new TerminalSession ( "Agent Log " ) ;
49+ this . terminal = new TerminalSession ( "Workspace Build " ) ;
5050 }
5151
5252 /**
@@ -69,11 +69,11 @@ export class WorkspaceStateMachine implements vscode.Disposable {
6969 this . closeBuildLogSocket ( ) ;
7070
7171 if ( ! this . firstConnect && ! ( await this . confirmStart ( workspaceName ) ) ) {
72- throw new Error ( `User declined to start ${ workspaceName } ` ) ;
72+ throw new Error ( `Workspace start cancelled ` ) ;
7373 }
7474
75- progress . report ( { message : `Starting ${ workspaceName } ...` } ) ;
76- this . logger . info ( `Starting ${ workspaceName } ... ` ) ;
75+ progress . report ( { message : `starting ${ workspaceName } ...` } ) ;
76+ this . logger . info ( `Starting ${ workspaceName } ` ) ;
7777 const globalConfigDir = this . pathResolver . getGlobalConfigDir (
7878 this . parts . label ,
7979 ) ;
@@ -92,13 +92,13 @@ export class WorkspaceStateMachine implements vscode.Disposable {
9292 case "pending" :
9393 case "starting" :
9494 case "stopping" :
95- // Clear the agent ID since it could change after a restart
96- this . agentId = undefined ;
95+ // Clear the agent since it's ID could change after a restart
96+ this . agent = undefined ;
9797 this . closeAgentLogSocket ( ) ;
9898 progress . report ( {
99- message : `Waiting for workspace build (${ workspace . latest_build . status } )...` ,
99+ message : `building ${ workspaceName } (${ workspace . latest_build . status } )...` ,
100100 } ) ;
101- this . logger . info ( `Waiting for ${ workspaceName } ... ` ) ;
101+ this . logger . info ( `Waiting for ${ workspaceName } ` ) ;
102102
103103 this . buildLogSocket ??= await streamBuildLogs (
104104 this . workspaceClient ,
@@ -116,44 +116,42 @@ export class WorkspaceStateMachine implements vscode.Disposable {
116116 }
117117
118118 const agents = extractAgents ( workspace . latest_build . resources ) ;
119- if ( this . agentId === undefined ) {
120- this . logger . info ( `Finding agent for ${ workspaceName } ... ` ) ;
119+ if ( this . agent === undefined ) {
120+ this . logger . info ( `Finding agent for ${ workspaceName } ` ) ;
121121 const gotAgent = await maybeAskAgent ( agents , this . parts . agent ) ;
122122 if ( ! gotAgent ) {
123123 // User declined to pick an agent.
124- throw new Error ( "User declined to pick an agent " ) ;
124+ throw new Error ( "Agent selection cancelled " ) ;
125125 }
126- this . agentId = gotAgent . id ;
126+ this . agent = { id : gotAgent . id , name : gotAgent . name } ;
127127 this . logger . info (
128128 `Found agent ${ gotAgent . name } with status` ,
129129 gotAgent . status ,
130130 ) ;
131131 }
132- const agent = agents . find ( ( a ) => a . id === this . agentId ) ;
132+ const agent = agents . find ( ( a ) => a . id === this . agent ?. id ) ;
133133 if ( ! agent ) {
134- throw new Error ( `Agent not found in ${ workspaceName } resources` ) ;
134+ throw new Error (
135+ `Agent ${ this . agent . name } not found in ${ workspaceName } resources` ,
136+ ) ;
135137 }
136138
137- const agentName = `${ workspaceName } /${ agent . name } ` ;
138-
139139 switch ( agent . status ) {
140140 case "connecting" :
141141 progress . report ( {
142- message : `Waiting for agent ${ agentName } to connect ...` ,
142+ message : `connecting to agent ${ agent . name } ...` ,
143143 } ) ;
144- this . logger . debug ( `Waiting for agent ${ agentName } ... ` ) ;
144+ this . logger . debug ( `Connecting to agent ${ agent . name } ` ) ;
145145 return false ;
146146
147147 case "disconnected" :
148- throw new Error ( `${ agentName } disconnected` ) ;
148+ throw new Error ( `Agent ${ workspaceName } / ${ agent . name } disconnected` ) ;
149149
150150 case "timeout" :
151151 progress . report ( {
152- message : `Agent ${ agentName } timed out, continuing to wait ...` ,
152+ message : `agent ${ agent . name } timed out, retrying ...` ,
153153 } ) ;
154- this . logger . debug (
155- `Agent ${ agentName } timed out, continuing to wait...` ,
156- ) ;
154+ this . logger . debug ( `Agent ${ agent . name } timed out, retrying` ) ;
157155 return false ;
158156
159157 case "connected" :
@@ -174,9 +172,9 @@ export class WorkspaceStateMachine implements vscode.Disposable {
174172 }
175173
176174 progress . report ( {
177- message : `Waiting for ${ agentName } startup scripts...` ,
175+ message : `running agent ${ agent . name } startup scripts...` ,
178176 } ) ;
179- this . logger . debug ( `Waiting for ${ agentName } startup scripts... ` ) ;
177+ this . logger . debug ( `Running agent ${ agent . name } startup scripts` ) ;
180178
181179 this . agentLogSocket ??= await streamAgentLogs (
182180 this . workspaceClient ,
@@ -188,22 +186,22 @@ export class WorkspaceStateMachine implements vscode.Disposable {
188186
189187 case "created" :
190188 progress . report ( {
191- message : `Waiting for ${ agentName } to start ...` ,
189+ message : `starting agent ${ agent . name } ...` ,
192190 } ) ;
193- this . logger . debug ( `Waiting for ${ agentName } to start... ` ) ;
191+ this . logger . debug ( `Starting agent ${ agent . name } ` ) ;
194192 return false ;
195193
196194 case "start_error" :
197195 this . closeAgentLogSocket ( ) ;
198196 this . logger . info (
199- `Agent ${ agentName } startup script failed, but continuing... ` ,
197+ `Agent ${ agent . name } startup scripts failed, but continuing` ,
200198 ) ;
201199 return true ;
202200
203201 case "start_timeout" :
204202 this . closeAgentLogSocket ( ) ;
205203 this . logger . info (
206- `Agent ${ agentName } startup script timed out, but continuing... ` ,
204+ `Agent ${ agent . name } startup scripts timed out, but continuing` ,
207205 ) ;
208206 return true ;
209207
@@ -213,7 +211,7 @@ export class WorkspaceStateMachine implements vscode.Disposable {
213211 case "shutdown_timeout" :
214212 this . closeAgentLogSocket ( ) ;
215213 throw new Error (
216- `Invalid lifecycle state '${ agent . lifecycle_state } ' for ${ agentName } ` ,
214+ `Invalid lifecycle state '${ agent . lifecycle_state } ' for ${ workspaceName } / ${ agent . name } ` ,
217215 ) ;
218216 }
219217 }
@@ -245,7 +243,7 @@ export class WorkspaceStateMachine implements vscode.Disposable {
245243 }
246244
247245 public getAgentId ( ) : string | undefined {
248- return this . agentId ;
246+ return this . agent ?. id ;
249247 }
250248
251249 dispose ( ) : void {
0 commit comments