Skip to content

fix(agent): assign dedicated server port to opencode ACP spawns - #983

Open
leehom0123 wants to merge 1 commit into
iOfficeAI:mainfrom
leehom0123:fix/opencode-acp-dedicated-port
Open

fix(agent): assign dedicated server port to opencode ACP spawns#983
leehom0123 wants to merge 1 commit into
iOfficeAI:mainfrom
leehom0123:fix/opencode-acp-dedicated-port

Conversation

@leehom0123

Copy link
Copy Markdown

Problem

With the global opencode config pinning server.port (e.g. ~/.config/opencode/opencode.jsonc), the second concurrent OpenCode conversation fails to start with USER_AGENT_STARTUP_FAILED.

Each OpenCode conversation spawns its own opencode acp, which boots an internal HTTP server. The CLI default --port 0 (random) loses to the config value, so the second process fails to bind and exits with ServeError before the ACP initialize handshake completes. An explicit --port does override the config.

Change

pin_opencode_port() appends an OS-allocated free loopback --port to every opencode ACP launch that does not already carry an explicit one. Applied to both spawn paths: the conversation runtime factory and the custom-agent validation probe.

Detection matches the catalog backend (opencode) or the executable name (opencode/opencode.exe, including Windows paths with spaces); other ACP vendors are never touched. User/vendor-specified --port is respected.

Testing

  • 4 new unit tests: injection, idempotency, explicit --port respected, non-opencode binaries untouched, Windows paths with spaces.
  • Manual e2e on a machine with server.port pinned: two concurrent OpenCode conversations now both reach a healthy runtime (previously the second died with ServeError); opencode custom-agent creation succeeds while the pinned port is occupied.
  • cargo test -p aionui-ai-agent --lib: passes except pre-existing Windows-only terminal::tests failures (missing echo/shell binaries), identical on unmodified main.

Concurrent OpenCode conversations fail with USER_AGENT_STARTUP_FAILED when the global opencode config pins server.port: the second 'opencode acp' process cannot bind the port and exits before the ACP initialize handshake. Assign an explicit, OS-allocated free --port on every opencode spawn path (conversation factory and custom-agent validation probe), leaving any explicitly configured --port untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant