@@ -302,6 +302,35 @@ func taskFromDBTaskAndWorkspace(dbTask database.Task, ws codersdk.Workspace) cod
302302}
303303}
304304
305+ // When the task is initializing and there's no app status yet, provide a
306+ // default current_state with an appropriate message.
307+ if currentState == nil && codersdk .TaskStatus (dbTask .Status )== codersdk .TaskStatusInitializing {
308+ message := "Initializing workspace"
309+
310+ switch {
311+ case ws .LatestBuild .Status == codersdk .WorkspaceStatusPending :
312+ message = "Workspace build is pending"
313+ case ws .LatestBuild .Status == codersdk .WorkspaceStatusStarting :
314+ message = "Starting workspace"
315+ case taskAgentLifecycle != nil :
316+ switch * taskAgentLifecycle {
317+ case codersdk .WorkspaceAgentLifecycleCreated :
318+ message = "Agent is connecting"
319+ case codersdk .WorkspaceAgentLifecycleStarting :
320+ message = "Agent is starting"
321+ default :
322+ message = "Initializing workspace agent"
323+ }
324+ }
325+
326+ currentState = & codersdk.TaskStateEntry {
327+ Timestamp :ws .LatestBuild .CreatedAt ,
328+ State :codersdk .TaskStateWorking ,
329+ Message :message ,
330+ URI :"" ,
331+ }
332+ }
333+
305334return codersdk.Task {
306335ID :dbTask .ID ,
307336OrganizationID :dbTask .OrganizationID ,