-
Notifications
You must be signed in to change notification settings - Fork 925
feat(agent/agentcontainers): fall back to workspace folder name #18466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances agent naming by falling back to the workspace folder name before using the container’s friendly name, and cleans up old pwd
-based logic.
- Adds
Workspace
info toDevcontainerConfig
and readsWorkspaceFolder
- Introduces
safeAgentName
(plus regex) to sanitize folder names and updates naming logic - Removes exec-based workspace detection and updates tests accordingly, plus adds unit tests for
safeAgentName
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
agent/agentcontainers/devcontainercli.go | Added Workspace field and DevcontainerWorkspace struct |
agent/agentcontainers/devcontainer.go | Removed default workspace constant and exec-based logic |
agent/agentcontainers/api.go | Imported regexp , added safeAgentName and collapsed hyphens |
agent/agentcontainers/api_test.go | Updated expected agent names/directories in container tests |
agent/agentcontainers/api_internal_test.go | New unit tests covering safeAgentName transformations |
Comments suppressed due to low confidence (2)
agent/agentcontainers/api.go:635
- [nitpick] Add a comment explaining that this regex collapses multiple consecutive hyphens into a single hyphen for improved clarity.
var consecutiveHyphenRegex = regexp.MustCompile("-+")
agent/agentcontainers/devcontainercli.go:28
- [nitpick] Consider adding a brief doc comment for
DevcontainerWorkspace
and itsWorkspaceFolder
field to explain how the workspace folder is used in naming.
type DevcontainerWorkspace struct {
This PR changes the logic for how we decide on an agent name. Previously it followed these steps: 1. Use a name from `customizations.coder.name` 2. Use a name from the terraform resource `coder_devcontainer` 3. Use the dev container's friendly name With this change it now does: 1. Use a name from `customizations.coder.name` 2. Use a name from the terraform resource `coder_devcontainer` 3. Use a name from the workspace folder 4. Use the dev container's friendly name We now attempt to construct a valid agent name from the workspace folder. Should we fail to construct a valid agent name from the workspace folder, we will fall back to the dev container's friendly name.
Appease the linter and make a test case for `safeAgentName`.
Co-authored-by: Copilot <[email protected]>
82f8e3f
to
a1a8957
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted a few nits but otherwise LGTM 👍🏻
Relates to coder/internal#732
This PR changes the logic for how we decide on an agent name.
Previously it followed these steps:
customizations.coder.name
coder_devcontainer
With this change it now does:
customizations.coder.name
coder_devcontainer
We now attempt to construct a valid agent name from the workspace folder. Should we fail to construct a valid agent name from the workspace folder, we will fall back to the dev container's friendly name.
In a follow up PR we'll implement retry logic, where we'll attempt to use a different name should agent creation fail due to the name already being taken.