Skip to content

Commit c85aa44

Browse files
committed
fix(coderd/agentapi): set ReadyAt for start timeout
1 parent 0c423f0 commit c85aa44

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

cli/cliui/agent.go

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

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)