Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cli)!: enforce selection for multiple agents rather than use randomness#18427

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 3 commits intomainfrommafredri/fix-cli-agent-selection
Jun 19, 2025
Merged
Changes from1 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
NextNext commit
fix(cli)!: select sub agent if available and error on multiple agents
In the past we randomly selected workspace agent if there were multiple.Unless both are running on the same machine with the same configuration,this would be very confusing behavior for a user.With the introduction of sub agents (devcontainer agents), it wasdecided prioritize them if present. Similarly as before, selecting adevcontainer randomly would be confusing. We now error out if the agentname is not specified and there are multiple agents.Fixescoder/internal#696
  • Loading branch information
@mafredri
mafredri committedJun 19, 2025
commit81d3f62b0e7891593a0b2934025cfdeea51d5982
42 changes: 25 additions & 17 deletionscli/ssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -925,36 +925,44 @@ func getWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *
func getWorkspaceAgent(workspace codersdk.Workspace, agentName string) (workspaceAgent codersdk.WorkspaceAgent, err error) {
resources := workspace.LatestBuild.Resources

agents := make([]codersdk.WorkspaceAgent, 0)
var (
availableNames []string
agents []codersdk.WorkspaceAgent
subAgents []codersdk.WorkspaceAgent
)
for _, resource := range resources {
agents = append(agents, resource.Agents...)
for _, agent := range resource.Agents {
availableNames = append(availableNames, agent.Name)
if agent.ParentID.UUID == uuid.Nil {
agents = append(agents, agent)
} else {
subAgents = append(subAgents, agent)
}
}
}
if len(agents) == 0 {
return codersdk.WorkspaceAgent{}, xerrors.Errorf("workspace %q has no agents", workspace.Name)
}
slices.Sort(availableNames)
if agentName != "" {
agents = append(agents, subAgents...)
for _, otherAgent := range agents {
if otherAgent.Name != agentName {
continue
}
workspaceAgent = otherAgent
break
}
if workspaceAgent.ID == uuid.Nil {
return codersdk.WorkspaceAgent{}, xerrors.Errorf("agent not found by name %q", agentName)
return otherAgent, nil
}
return codersdk.WorkspaceAgent{}, xerrors.Errorf("agent not found by name %q, available agents: %v", agentName, availableNames)
}
if workspaceAgent.ID == uuid.Nil {
if len(agents) > 1 {
workspaceAgent, err = cryptorand.Element(agents)
if err != nil {
return codersdk.WorkspaceAgent{}, err
}
} else {
workspaceAgent = agents[0]
}
if len(subAgents) == 1 {
return subAgents[0], nil
} else if len(subAgents) > 1 {
return codersdk.WorkspaceAgent{}, xerrors.Errorf("multiple sub-agents found, please specify the agent name, available agents: %v", availableNames)
}
if len(agents) == 1 {
return agents[0], nil
}
returnworkspaceAgent, nil
returncodersdk.WorkspaceAgent{}, xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v", availableNames)
}

// Attempt to poll workspace autostop. We write a per-workspace lockfile to
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp