Skip to content

Conversation

@DanielleMaywood
Copy link
Contributor

@DanielleMaywood DanielleMaywood commented Dec 12, 2025

@DanielleMaywood DanielleMaywood force-pushed the danielle/devcontainers/delete/agent branch from 49794cc to 4504755 Compare December 12, 2025 12:12
@DanielleMaywood DanielleMaywood force-pushed the danielle/devcontainers/delete/agent branch from 4504755 to 0fcab3f Compare December 12, 2025 14:43
@DanielleMaywood DanielleMaywood marked this pull request as ready for review December 12, 2025 15:19
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

I did a quick review, didn't really dig into the tests yet.

return
}

// Check if the devcontainer is currently starting - if so, we can't delete it.
Copy link
Member

Choose a reason for hiding this comment

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

This should be rewritten and explain why we've decided to have this limitation. Technically there's nothing preventing us from implementing cancellation of create, etc.

PS. I see you -.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Believe it or not, I think I wrote that 😂

}

// Similarly, if already stopping, don't allow another delete.
if dc.Status == codersdk.WorkspaceAgentDevcontainerStatusStopping {
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this state deleting instead? I would like to keep stopping as a separate state for the future, one that does not mean delete (i.e. start/stop/delete for the full suite).

Logically a delete could be a stop followed by a delete. I think both are valid use-cases (a user may want to just quickly restart the container to reset the processes, deletion will take potentially much longer).

Detail: err.Error(),
})
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Error paths seem to be lacking state handling for the devcontainer. Should probably update dc.Error, perhaps others?

delete(api.recreateSuccessTimes, workspaceFolder)
delete(api.recreateErrorTimes, workspaceFolder)
delete(api.usingWorkspaceFolderName, workspaceFolder)
delete(api.injectedSubAgentProcs, workspaceFolder)
Copy link
Member

Choose a reason for hiding this comment

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

Check: Will this leave the devcontainer available in the dashboard to start, like we do for e.g. detected containers?

Just because the user deleted it, doesn't necessarily mean they won't want to start it again.

}

// Delete the subagent if it exists.
if subAgentID != uuid.Nil {
Copy link
Member

Choose a reason for hiding this comment

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

Should we run this cleanup even if stop/remove fails?

httpapi.Write(ctx, w, http.StatusInternalServerError, codersdk.Response{
Message: "An internal error occurred deleting the agent",
Detail: err.Error(),
})
Copy link
Member

Choose a reason for hiding this comment

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

These failures leave the API in a weird state, we've entered a terminal state (stopping), and can't re-invoke delete even if the errors are ephemeral. The container will become immortal.

}
}
if dc.ID == uuid.Nil {
dc, err := api.devcontainerByIDLocked(devcontainerID)
Copy link
Member

Choose a reason for hiding this comment

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

Nice 👍🏻

return nil, f.execErr
}

func (f *fakeContainerCLI) Stop(ctx context.Context, name string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Since we're introducing mutation, we'll need to add a mutex to these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants