Skip to content

Commit e474468

Browse files
authored
fix(codersdk): handle API older than client for startup script behavior (#7933)
1 parent 30a635a commit e474468

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

coderd/workspaceagents.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
11261126
ConnectionTimeoutSeconds: dbAgent.ConnectionTimeoutSeconds,
11271127
TroubleshootingURL: troubleshootingURL,
11281128
LifecycleState: codersdk.WorkspaceAgentLifecycle(dbAgent.LifecycleState),
1129-
LoginBeforeReady: dbAgent.StartupScriptBehavior == database.StartupScriptBehaviorNonBlocking,
1129+
LoginBeforeReady: dbAgent.StartupScriptBehavior != database.StartupScriptBehaviorBlocking,
11301130
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehavior(dbAgent.StartupScriptBehavior),
11311131
StartupScriptTimeoutSeconds: dbAgent.StartupScriptTimeoutSeconds,
11321132
ShutdownScript: dbAgent.ShutdownScript.String,

codersdk/workspaceagents.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,18 @@ func (c *Client) WorkspaceAgent(ctx context.Context, id uuid.UUID) (WorkspaceAge
375375
return WorkspaceAgent{}, ReadBodyAsError(res)
376376
}
377377
var workspaceAgent WorkspaceAgent
378-
return workspaceAgent, json.NewDecoder(res.Body).Decode(&workspaceAgent)
378+
err = json.NewDecoder(res.Body).Decode(&workspaceAgent)
379+
if err != nil {
380+
return WorkspaceAgent{}, err
381+
}
382+
// Backwards compatibility for cases where the API is older then the client.
383+
if workspaceAgent.StartupScriptBehavior == "" {
384+
workspaceAgent.StartupScriptBehavior = WorkspaceAgentStartupScriptBehaviorNonBlocking
385+
if !workspaceAgent.LoginBeforeReady {
386+
workspaceAgent.StartupScriptBehavior = WorkspaceAgentStartupScriptBehaviorBlocking
387+
}
388+
}
389+
return workspaceAgent, nil
379390
}
380391

381392
type IssueReconnectingPTYSignedTokenRequest struct {

0 commit comments

Comments
 (0)