When using an agent session on a workspace that has a devcontainer, portable desktop is unusable and the terminal behaves inconsistently.
Portable desktop
I'm stuck on this screen with no way to get a desktop session:
Hitting "Reconnect" loops back to the same error.
Terminal
The web terminal is inconsistent — sometimes it drops me inside the devcontainer, sometimes on the host. There's no obvious pattern.
Root cause
watchChatDesktop() in coderd/exp_chats.go fetches all agents via GetWorkspaceAgentsInLatestBuildByWorkspaceID and blindly picks agents[0]:
agents, err := api.Database.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, chat.WorkspaceID.UUID)
// ...
apiAgent, err := db2sdk.WorkspaceAgent(..., agents[0], ...)
// ...
agentConn, release, err := api.agentProvider.AgentConn(dialCtx, agents[0].ID)
The underlying SQL query has no parent_id IS NULL filter and no ORDER BY, so it returns both the parent (host) agent and devcontainer sub-agents in non-deterministic order. When a sub-agent ends up at index 0, the desktop stream is routed to the devcontainer agent where portabledesktop either doesn't exist or tries to dial 127.0.0.1:<vncPort> inside the container's network namespace — nothing is listening, so the connection fails.
Same agents[0] pattern is used for terminal connections, which explains the inconsistent terminal behavior.
Related
- CODAGT-101 — Agents: AI chat always targets the host agent, ignoring devcontainer sub-agents
- CODAGT-67 — DevContainer support for Agents
- CODAGT-101 — same underlying
agents[0] selection problem
When using an agent session on a workspace that has a devcontainer, portable desktop is unusable and the terminal behaves inconsistently.
Portable desktop
I'm stuck on this screen with no way to get a desktop session:
Hitting "Reconnect" loops back to the same error.
Terminal
The web terminal is inconsistent — sometimes it drops me inside the devcontainer, sometimes on the host. There's no obvious pattern.
Root cause
watchChatDesktop()incoderd/exp_chats.gofetches all agents viaGetWorkspaceAgentsInLatestBuildByWorkspaceIDand blindly picksagents[0]:The underlying SQL query has no
parent_id IS NULLfilter and noORDER BY, so it returns both the parent (host) agent and devcontainer sub-agents in non-deterministic order. When a sub-agent ends up at index 0, the desktop stream is routed to the devcontainer agent where portabledesktop either doesn't exist or tries to dial127.0.0.1:<vncPort>inside the container's network namespace — nothing is listening, so the connection fails.Same
agents[0]pattern is used for terminal connections, which explains the inconsistent terminal behavior.Related
agents[0]selection problem