Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 12 commits into from
Jun 23, 2025

Conversation

DanielleMaywood
Copy link
Contributor

@DanielleMaywood DanielleMaywood commented Jun 20, 2025

Relates to coder/internal#732

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.

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.

Copy link
Contributor

@Copilot Copilot AI left a 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 to DevcontainerConfig and reads WorkspaceFolder
  • 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 its WorkspaceFolder field to explain how the workspace folder is used in naming.
type DevcontainerWorkspace struct {

DanielleMaywood and others added 5 commits June 23, 2025 08:26
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]>
@DanielleMaywood DanielleMaywood force-pushed the dm-devcontainer-folder-name branch from 82f8e3f to a1a8957 Compare June 23, 2025 08:30
@DanielleMaywood DanielleMaywood marked this pull request as ready for review June 23, 2025 08:47
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.

Noted a few nits but otherwise LGTM 👍🏻

@DanielleMaywood DanielleMaywood merged commit c3bc1e7 into main Jun 23, 2025
34 checks passed
@DanielleMaywood DanielleMaywood deleted the dm-devcontainer-folder-name branch June 23, 2025 12:05
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 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.

3 participants