Skip to content

Bug: Chat embed URL broken when subdomain=false in agentapi module #684

@maxious

Description

@maxious

Description

When using AI agent modules (opencode, claude-code, aider, goose, copilot, codex) with subdomain = false, the Coder Tasks UI chat panel fails with:

"user" must be an existing uuid or username. queried user="chat"

Root Cause

The agentapi module constructs AGENTAPI_CHAT_BASE_PATH using var.agent_id (a UUID) instead of the agent name:

https://github.com/coder/registry/blob/main/registry/coder/modules/agentapi/main.tf#L182

agentapi_chat_base_path = var.agentapi_subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${var.web_app_slug}/chat"

This produces a malformed URL:

  • Broken: /@owner/workspace.{uuid}/apps/opencode/chat/embed
  • Expected: /@owner/workspace.{agent_name}/apps/opencode/chat/embed

The Coder proxy expects the agent name (e.g., main) in the path, not the agent ID (UUID). When the URL contains the UUID, the proxy incorrectly parses the path and tries to look up "chat" as a username.

Affected Modules

All modules that expose a subdomain variable and use the agentapi module are affected:

Module Path
coder/claude-code registry/coder/modules/claude-code/main.tf
coder/aider registry/coder/modules/aider/main.tf
coder/goose registry/coder/modules/goose/main.tf
coder-labs/opencode registry/coder-labs/modules/opencode/main.tf
coder-labs/copilot registry/coder-labs/modules/copilot/main.tf
coder-labs/codex registry/coder-labs/modules/codex/main.tf

Reproduction Steps

  1. Create a workspace using any affected module with subdomain = false
  2. Open the workspace in Coder UI
  3. Click on the AI agent app (e.g., OpenCode)
  4. Observe the chat panel fails to load with the error above

Workaround

Set AGENTAPI_CHAT_BASE_PATH environment variable directly in your template:

resource "coder_env" "agentapi_chat_base_path" {
  agent_id = coder_agent.main.id
  name     = "AGENTAPI_CHAT_BASE_PATH"
  value    = "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.main/apps/opencode/chat"
}

Replace main with your agent's name and opencode with your app slug.

Suggested Fix

Add an agent_name variable to the agentapi module and use it for path construction:

variable "agent_name" {
  type        = string
  description = "The name of the Coder agent (used for path-based app routing when subdomain=false)."
}

locals {
  agentapi_chat_base_path = var.agentapi_subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_name}/apps/${var.web_app_slug}/chat"
}

All modules using agentapi would need to be updated to pass agent_name.

Environment

  • Coder version: v2.28.8
  • agentapi module version: 2.0.0
  • opencode module version: 0.1.1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions