Skip to content

Commit 35a808f

Browse files
authored
fix(coderd/agentapi): set ReadyAt for start timeout (#13846)
1 parent b07e306 commit 35a808f

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

cli/cliui/agent.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
209209
case codersdk.WorkspaceAgentLifecycleReady:
210210
sw.Complete(stage, safeDuration(sw, agent.ReadyAt, agent.StartedAt))
211211
case codersdk.WorkspaceAgentLifecycleStartTimeout:
212-
sw.Fail(stage, 0)
212+
// Backwards compatibility: Avoid printing warning if
213+
// coderd is old and doesn't set ReadyAt for timeouts.
214+
if agent.ReadyAt == nil {
215+
sw.Fail(stage, 0)
216+
} else {
217+
sw.Fail(stage, safeDuration(sw, agent.ReadyAt, agent.StartedAt))
218+
}
213219
sw.Log(time.Time{}, codersdk.LogLevelWarn, "Warning: A startup script timed out and your workspace may be incomplete.")
214220
case codersdk.WorkspaceAgentLifecycleStartError:
215221
sw.Fail(stage, safeDuration(sw, agent.ReadyAt, agent.StartedAt))

cli/cliui/agent_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ func TestAgent(t *testing.T) {
9595
iter: []func(context.Context, *testing.T, *codersdk.WorkspaceAgent, <-chan string, chan []codersdk.WorkspaceAgentLog) error{
9696
func(_ context.Context, _ *testing.T, agent *codersdk.WorkspaceAgent, _ <-chan string, _ chan []codersdk.WorkspaceAgentLog) error {
9797
agent.Status = codersdk.WorkspaceAgentConnecting
98+
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStarting
99+
agent.StartedAt = ptr.Ref(time.Now())
98100
return nil
99101
},
100102
func(_ context.Context, t *testing.T, agent *codersdk.WorkspaceAgent, output <-chan string, _ chan []codersdk.WorkspaceAgentLog) error {
@@ -104,6 +106,7 @@ func TestAgent(t *testing.T) {
104106
agent.Status = codersdk.WorkspaceAgentConnected
105107
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStartTimeout
106108
agent.FirstConnectedAt = ptr.Ref(time.Now())
109+
agent.ReadyAt = ptr.Ref(time.Now())
107110
return nil
108111
},
109112
},

coderd/agentapi/lifecycle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ func (a *LifecycleAPI) UpdateLifecycle(ctx context.Context, req *agentproto.Upda
9898
// This agent is (re)starting, so it's not ready yet.
9999
readyAt.Time = time.Time{}
100100
readyAt.Valid = false
101-
case database.WorkspaceAgentLifecycleStateReady, database.WorkspaceAgentLifecycleStateStartError:
101+
case database.WorkspaceAgentLifecycleStateReady,
102+
database.WorkspaceAgentLifecycleStateStartTimeout,
103+
database.WorkspaceAgentLifecycleStateStartError:
102104
if !startedAt.Valid {
103105
startedAt = dbChangedAt
104106
}

coderd/agentapi/lifecycle_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func TestUpdateLifecycle(t *testing.T) {
275275
if state == agentproto.Lifecycle_STARTING {
276276
expectedStartedAt = sql.NullTime{Valid: true, Time: stateNow}
277277
}
278-
if state == agentproto.Lifecycle_READY || state == agentproto.Lifecycle_START_ERROR {
278+
if state == agentproto.Lifecycle_READY || state == agentproto.Lifecycle_START_TIMEOUT || state == agentproto.Lifecycle_START_ERROR {
279279
expectedReadyAt = sql.NullTime{Valid: true, Time: stateNow}
280280
}
281281

0 commit comments

Comments
 (0)