Skip to content

fix(opencode): do not append --port to the acp launch command - #1177

Merged
catatafishen merged 1 commit into
catatafishen:masterfrom
BambinoSK:fix/opencode-acp-port
Oct 12, 2026
Merged

catatafishen merged 1 commit into
catatafishen:masterfrom
BambinoSK:fix/opencode-acp-port

Conversation

@BambinoSK

Copy link
Copy Markdown
Contributor

Fixes #1176.

Problem

Since the subagent transcript feature, starting the OpenCode agent fails immediately:

java.io.IOException: Agent process exited unexpectedly (exit code 1):
ERROR | Unrecognized flag: --port in command opencode acp

OpenCodeClient.addServerPort appended --port <free port> to the opencode acp launch command. OpenCode 2's acp command has no --port flag: its command spec (packages/cli/src/commands/commands.ts on dev) defines exactly one flag, --login, and the parser exits on unknown flags. Reproduced with opencode v2.0.27:

$ opencode acp --port 39287
ERROR | Unrecognized flag: --port in command opencode acp   (exit 1)

The CLI docs table for acp lists --port/--hostname/--mdns/--cors, but those are the serve/web flags; the acp handler spawns its own internal server (opencode serve --stdio --port 0) with a random per-launch password, so an external client cannot reach it with or without the flag. The same flag removal already hit OpenCode's own VS Code extension (anomalyco/opencode#49085).

What this PR does

  • Stops appending --port to the opencode acp launch command, so OpenCode sessions start again.
  • Keeps honoring an explicit --port passed in the agent profile's extra CLI arguments (user override), still publishing it to the transcript endpoint.
  • Without an explicit port the transcript endpoint stays cleared with a log warning, reusing the existing graceful-degradation path; the loadSubAgentTranscript error message is updated to match.
  • Renames addServerPort to recordServerPort to reflect that it no longer adds flags.

Subagent transcripts (#1173) remain unavailable with this change until the feature is reworked on a supported mechanism (the pinned-port approach cannot reach the server opencode acp spawns internally).

Verification

  • :plugin-core:compileJava + compileTestJava pass
  • *OpenCodeClientBehaviorTest* passes, including two new regression tests pinning that recordServerPort never appends flags (with and without an explicit --port)
  • *OpenCodeClientModelRoutingTest*, *OpenCodeServerEndpointTest*, *OpenCodeSessionHttpClientTest* pass
  • :plugin-core:buildPlugin succeeds; installed the zip and verified an OpenCode 2 session launches from the agent dropdown, with the No --port pinned warning in the IDE log instead of the Unrecognized flag crash

Closes #1176

OpenCode 2's acp command has no --port flag and exits on unknown flags,
so the auto-injected flag from the subagent transcript feature broke
every OpenCode session launch. Only an explicit --port from the agent
profile's extra CLI arguments is honored now; without one the transcript
endpoint stays cleared and the feature degrades gracefully.
@github-actions

Copy link
Copy Markdown

⚠️ ClusterFuzzLite — Maintainer Security Review Required

A maintainer needs to approve the ClusterFuzzLite PR fuzzing workflow run for this fork PR.

Before approving, please review the code changes from BambinoSK/agentbridge@af5d1185 to confirm there is no code that could:

  • Exfiltrate the CFLITE_STORAGE_REPO_TOKEN CI secret
  • Abuse CI infrastructure or the fuzz corpus storage repository

The fuzz targets from the fork branch will be compiled and executed with access to repository secrets. Rubber-stamping this approval without reviewing the code is a security risk.

This comment is posted automatically whenever ClusterFuzzLite is triggered on a fork PR.

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...afishen/agentbridge/client/acp/OpenCodeClient.java 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@catatafishen

Copy link
Copy Markdown
Owner

Thanks, I hadn't tested that on opencode 2.x.x
I'll need to add a version gate, but that can come in the next commit!

@catatafishen
catatafishen merged commit c04bc20 into catatafishen:master Oct 12, 2026
19 of 20 checks passed
catatafishen pushed a commit that referenced this pull request Oct 12, 2026
….x keeps subagent transcripts

OpenCode 2's `acp` command has no --port flag and exits on it ("Unrecognized flag: --port"),
so the port pinned for the subagent transcript feature (#1173) stopped every 2.x session from
starting (#1176). OpenCode 1.x accepts the flag and the transcript depends on it.

- AcpClient.finalizeCommand: new hook, called once the binary is resolved and validated, so a
  client can run the binary before deciding on flags. buildCommand runs before resolution.
- OpenCodeVersionProbe: runs `<binary> --version` with the launch environment (5 s timeout) and
  extracts the version. The version OpenCode reports in the ACP initialize response arrives too
  late for a launch flag.
- OpenCodeClient.pinServerPort: explicit --port from the profile is kept as is; 1.x gets a free
  port appended; 2.x or an undeterminable version gets none, with the reason logged.
- On 2.x there is no transcript source yet. loadSubAgentTranscript returns null there instead of
  throwing, since an IOException becomes a chat error entry after every sub-agent. A missing
  address on 1.x (before launch, after stop) is still an error.

Supersedes the removal of the port in #1177, which would also have dropped transcripts for 1.x.

Fixes #1176

This branch is waiting to be deployed

1 waiting deployment
fuzzing-gate — af5d1185 Waiting Oct 12, 2026 by BambinoSK via Maintainer approval gate (fork PR) #1632
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.

OpenCode agent fails to start: Unrecognized flag --port (acp command has no port flag)

2 participants