Skip to content

weirdness with terminal and portabledesktop with devcontainers #24716

@bpmct

Description

@bpmct

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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions