Skip to content

Conversation

@johnstcn
Copy link
Member

@johnstcn johnstcn commented Dec 17, 2025

Relates to #20925

This PR modifies the postWorkspaceBuild handler to automatically unset dormancy on a workspace when a start transition is requested. Previously, the client was responsible for unsetting the dormancy on the workspace prior to posting a workspace build.

@johnstcn johnstcn self-assigned this Dec 17, 2025
@johnstcn johnstcn changed the title fix(coderd): attempting to start a dormant workspace should wake it fix(coderd): wake dormant workspace when attempting to start it Dec 17, 2025
@johnstcn johnstcn marked this pull request as ready for review December 17, 2025 14:42
@johnstcn johnstcn requested a review from sreya December 17, 2025 17:05
Copy link
Collaborator

@sreya sreya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine...the intent originally was for a user to have be deliberate about "activating" a dormant workspace to continue using it. I think back then the idea was that I did not want dormant workspaces to be activated unintentionally as a result of scripts or bulk actions.

Comment on lines 392 to 421
// #20925: if the workspace is dormant and we are starting the workspace,
// we need to unset that status before inserting a new build.
if workspace.DormantAt.Valid && transition == database.WorkspaceTransitionStart {
if _, err := api.Database.UpdateWorkspaceDormantDeletingAt(ctx, database.UpdateWorkspaceDormantDeletingAtParams{
ID: workspace.ID,
DormantAt: sql.NullTime{Valid: false},
}); err != nil {
return codersdk.WorkspaceBuild{}, httperror.NewResponseError(http.StatusInternalServerError, codersdk.Response{
Message: "Internal error unsetting workspace dormant status",
Detail: err.Error(),
})
}
// We need to audit this change separately.
updatedWorkspace := workspace.WorkspaceTable()
updatedWorkspace.DormantAt = sql.NullTime{Valid: false}
auditor := api.Auditor.Load()
bag := audit.BaggageFromContext(ctx)
audit.BackgroundAudit(ctx, &audit.BackgroundAuditParams[database.WorkspaceTable]{
Audit: *auditor,
Old: workspace.WorkspaceTable(),
New: updatedWorkspace,
Log: api.Logger,
UserID: apiKey.UserID,
OrganizationID: workspace.OrganizationID,
RequestID: workspace.ID,
IP: bag.IP,
Action: database.AuditActionWrite,
Status: http.StatusOK,
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this happen inside the transaction below? So if the workspace build cannot be created, the dormancy remains?

I can also see why the dormancy should be toggled regardless.

Copy link
Member Author

@johnstcn johnstcn Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see an argument either way; I'm choosing to interpret an attempt to start as enough to reactivate. I also considered doing it in wsbuilder but that didn't "feel" right.

Edit: I went ahead and updated it to unset it inside the tx. We can move it out later if needed.

@johnstcn johnstcn merged commit 8248fa3 into main Dec 18, 2025
49 of 51 checks passed
@johnstcn johnstcn deleted the cj/gh20925/start-workspace-unsets-dormancy branch December 18, 2025 10:35
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants