Skip to content

fix: expose agentapi_port in codex/auggie/gemini/opencode modules#838

Open
qinkangdeid wants to merge 3 commits intocoder:mainfrom
qinkangdeid:fix/expose-agentapi-port
Open

fix: expose agentapi_port in codex/auggie/gemini/opencode modules#838
qinkangdeid wants to merge 3 commits intocoder:mainfrom
qinkangdeid:fix/expose-agentapi-port

Conversation

@qinkangdeid
Copy link
Copy Markdown

Summary

When multiple AI coding tools (e.g. Claude Code + Codex, or Gemini + OpenCode) are installed in the same Coder workspace, they all hardcode AgentAPI to port 3284, causing port conflicts that prevent the second tool from starting.

The underlying agentapi submodule already supports a configurable agentapi_port parameter, but the parent modules (codex, auggie, gemini, opencode) don't expose or pass it through. This PR adds a agentapi_port variable (defaulting to 3284 for backward compatibility) to all four modules and passes it to the agentapi submodule.

Changes

For each of the 4 modules (codex, auggie, gemini, opencode):

  1. Added variable "agentapi_port" with type number, default 3284
  2. Added agentapi_port = var.agentapi_port in the module "agentapi" block

Related Issues

Fixes #666
Fixes #837

@qinkangdeid
Copy link
Copy Markdown
Author

Note: this is a more focused version of #829 (which was self-closed by the author). That PR updated 12 modules; this one targets only the 4 coder-labs modules to keep the scope minimal and reviewable.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e8d99bab7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

install_agentapi = var.install_agentapi
agentapi_subdomain = var.subdomain
agentapi_version = var.agentapi_version
agentapi_port = var.agentapi_port
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Propagate configurable AgentAPI port into module configs

Passing agentapi_port into the agentapi submodule here does not actually reconfigure the client-side MCP wiring, because the module install paths still hardcode http://localhost:3284 (for example: registry/coder-labs/modules/codex/scripts/install.sh:132, auggie/scripts/install.sh:88, gemini/main.tf:167 and gemini/scripts/install.sh:145, opencode/scripts/install.sh:97). With any non-default agentapi_port, these modules will still point tools at 3284, so task reporting/MCP calls hit the wrong endpoint or fail entirely, which breaks the multi-tool port-conflict fix this commit is trying to add.

Useful? React with 👍 / 👎.

@matifali matifali requested a review from 35C4n0r April 9, 2026 05:10
Pass ARG_AGENTAPI_PORT from main.tf install_script blocks into each
module's install.sh, replacing hardcoded localhost:3284 references
with ${ARG_AGENTAPI_PORT:-3284}. This ensures the MCP client-side
URL matches the configured AgentAPI port end-to-end.

Changes per module:
- codex: main.tf (pass env var) + install.sh (use env var)
- auggie: main.tf (pass env var) + install.sh (use env var)
- gemini: main.tf (pass env var + fix inline JSON) + install.sh (use env var)
- opencode: main.tf (pass env var) + install.sh (use env var)
@qinkangdeid
Copy link
Copy Markdown
Author

Addressed Codex Review Feedback

The automated review correctly identified that passing agentapi_port to the agentapi submodule alone is insufficient — the install scripts still had hardcoded localhost:3284 for the MCP client URL.

What was added (commit a5aba0e)

8 files changed, 9 insertions(+), 5 deletions(-):

Module main.tf scripts/install.sh
codex Pass ARG_AGENTAPI_PORT env var 3284${ARG_AGENTAPI_PORT:-3284}
auggie Pass ARG_AGENTAPI_PORT env var 3284${ARG_AGENTAPI_PORT:-3284}
gemini Pass ARG_AGENTAPI_PORT env var + fix inline JSON (${var.agentapi_port}) 3284${ARG_AGENTAPI_PORT:-3284}
opencode Pass ARG_AGENTAPI_PORT env var 3284${ARG_AGENTAPI_PORT:-3284}

This follows the existing pattern in the agentapi submodule (ARG_AGENTAPI_PORT naming convention). The :-3284 default ensures backward compatibility.

End-to-end verification

Tested by deploying a Coder workspace template with both claude-code (default port 3284) and codex (agentapi_port = 3285). Verified via Coder API:

ccw (Claude Code)  →  url=http://localhost:3284/    healthcheck=http://localhost:3284/status
codex              →  url=http://localhost:3285/    healthcheck=http://localhost:3285/status

Both AgentAPI instances run on separate ports with no conflict. The port flows end-to-end: Terraform variable → agentapi server listener → install.sh MCP client URL → Coder app healthcheck.

@DevelopmentCats
Copy link
Copy Markdown
Collaborator

@qinkangdeid You will need to bump the versions in all of these modules. since we are adding a variable this would be a patch version bump for each script. If you would like we have a version bump script that is outlined in the CONTRIBUTING.md of the registry.

@DevelopmentCats
Copy link
Copy Markdown
Collaborator

Also I would update the modules with test cases taking into account this new change for the optionality in the agentapi port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants