Skip to content

feat(agent/agentcontainers): support agent name in customization #18451

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 4 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions agent/agentcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
}

var appsWithPossibleDuplicates []SubAgentApp
var possibleAgentName string

if config, err := api.dccli.ReadConfig(ctx, dc.WorkspaceFolder, dc.ConfigPath,
[]string{
Expand Down Expand Up @@ -1173,6 +1174,14 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c

appsWithPossibleDuplicates = append(appsWithPossibleDuplicates, customization.Apps...)
}

// NOTE(DanielleMaywood):
// We only want to take an agent name specified in the very last customization layer.
// This restricts the ability for a feature to specify the agent name. We may revisit
// this in the future, but for now we want to restrict this behavior.
if len(coderCustomization) > 0 {
possibleAgentName = coderCustomization[len(coderCustomization)-1].Name
}
}

displayApps := make([]codersdk.DisplayApp, 0, len(displayAppsMap))
Expand Down Expand Up @@ -1204,6 +1213,10 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c

subAgentConfig.DisplayApps = displayApps
subAgentConfig.Apps = apps

if possibleAgentName != "" {
subAgentConfig.Name = possibleAgentName
}
}

deleteSubAgent := proc.agent.ID != uuid.Nil && maybeRecreateSubAgent && !proc.agent.EqualConfig(subAgentConfig)
Expand Down
27 changes: 26 additions & 1 deletion agent/agentcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,32 @@ func TestAPI(t *testing.T) {
assert.Equal(t, int32(2), subAgent.Apps[1].Order)
},
},
{
name: "Name",
customization: []agentcontainers.CoderCustomization{
{
Name: "not-this-name",
},
{
Name: "custom-name",
},
},
afterCreate: func(t *testing.T, subAgent agentcontainers.SubAgent) {
require.Equal(t, "custom-name", subAgent.Name)
},
},
{
name: "NameIsOnlyUsedWhenInLastLayer",
customization: []agentcontainers.CoderCustomization{
{
Name: "custom-name",
},
{},
},
afterCreate: func(t *testing.T, subAgent agentcontainers.SubAgent) {
require.NotEqual(t, "custom-name", subAgent.Name)
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -1825,7 +1851,6 @@ func TestAPI(t *testing.T) {

// Then: We expected it to succeed
require.Len(t, fSAC.created, 1)
assert.Equal(t, testContainer.FriendlyName, fSAC.created[0].Name)

if tt.afterCreate != nil {
tt.afterCreate(t, fSAC.created[0])
Expand Down
1 change: 1 addition & 0 deletions agent/agentcontainers/devcontainercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type DevcontainerCustomizations struct {
type CoderCustomization struct {
DisplayApps map[codersdk.DisplayApp]bool `json:"displayApps,omitempty"`
Apps []SubAgentApp `json:"apps,omitempty"`
Name string `json:"name,omitempty"`
}

// DevcontainerCLI is an interface for the devcontainer CLI.
Expand Down
Loading