fix(agent): assign dedicated server port to opencode ACP spawns - #983
Open
leehom0123 wants to merge 1 commit into
Open
fix(agent): assign dedicated server port to opencode ACP spawns#983leehom0123 wants to merge 1 commit into
leehom0123 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the global opencode config pinning
server.port(e.g.~/.config/opencode/opencode.jsonc), the second concurrent OpenCode conversation fails to start withUSER_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 withServeErrorbefore the ACPinitializehandshake completes. An explicit--portdoes override the config.Change
pin_opencode_port()appends an OS-allocated free loopback--portto 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--portis respected.Testing
--portrespected, non-opencode binaries untouched, Windows paths with spaces.server.portpinned: two concurrent OpenCode conversations now both reach a healthy runtime (previously the second died withServeError); opencode custom-agent creation succeeds while the pinned port is occupied.cargo test -p aionui-ai-agent --lib: passes except pre-existing Windows-onlyterminal::testsfailures (missingecho/shell binaries), identical on unmodifiedmain.