Skip to content

fix(acp): probe opencode 2.x for acp --port/--hostname instead of applying the 1.x floor - #909

Merged
xintaofei merged 3 commits into
spacering-net:mainfrom
Liang-HZ:fix/opencode-v2-listen-flags
Oct 9, 2026
Merged

xintaofei merged 3 commits into
spacering-net:mainfrom
Liang-HZ:fix/opencode-v2-listen-flags

Conversation

@Liang-HZ

@Liang-HZ Liang-HZ commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #906

问题

0.32.3(#860)起,OpenCode 连接启动时会追加 --port 0 --hostname 127.0.0.1。但系统安装的 opencode 2.x 的 acp 不接受这两个参数——v2 已重构 acp(内部自建 serve --stdio --port 0,--port/--hostname 只在 opencode serve 上;v2.0.0 ~ v2.0.26 均如此)。v2 CLI 严格解析未知 flag:打印 usage 到 stdout 并 exit 1,而 stdout 正是 ACP 通道,连接在 initialize 之前就失败:

$ opencode acp --port 0 --hostname 127.0.0.1
ERRORS
  Unrecognized flag: --port in command opencode acp
  Unrecognized flag: --hostname in command opencode acp   # exit 1

修复

release_accepts_listen_flags 不再把 1.x 的版本下限外推到 2.x:major >= 2 返回“未知”,交给既有的 acp --help 实测(v2 实测没有这两个 flag → 保持裸 acp 启动;未来某个 2.x 重新支持也能自动跟上)。1.x 行为不变,#860 修复的场景不受影响。

验证

  • cargo test --no-default-features --features server-bin --lib acp::opencode_launch:15/15 通过(含新增用例:2.x 版本号 → 不猜测;fake 2.x 二进制 → 实测后裸 argv)
  • 真实二进制 opencode 2.0.24:裸 opencode acp 的 initialize 握手成功;带 --port/--hostname exit 1

注:手动验证(真实二进制)在 macOS (darwin-arm64) 完成;Windows / Linux 依赖 CI 矩阵(ubuntu / macos / windows 的编译与单测)验证 —— 本改动无平台特定代码,行为差异取决于 opencode 版本而非 OS。

Liang-HZ and others added 3 commits October 9, 2026 11:32
…uessing

opencode 2.0 rearchitected `acp`: it starts its own `serve --stdio --port 0`
child and declares neither listen flag, so `--port 0 --hostname 127.0.0.1`
makes every connection exit 1 with "Unrecognized flag" (its usage lands on
stdout — the ACP channel) before `initialize` answers.

`release_accepts_listen_flags` read "version >= LISTEN_FLAGS_MIN_VERSION
(1.0.43)" as "accepts", and the 2.x line inherited that reading, so the spacering-net#860
floor was carried across the major. Answer only the 1.x line from its
version; major 2 and up go to the `acp --help` probe, which reports v2's
absent flags and keeps the bare argv (and follows a later 2.x that re-adds
them).

Verified against opencode 2.0.24: bare `opencode acp` answers `initialize`;
`opencode acp --port 0 --hostname 127.0.0.1` exits 1.
Since 2.x goes to the `acp --help` probe, its "no flags" answer reaches the
same info line as a pre-1.0.43 build, which called it a build that
"predates `acp --port/--hostname`" with "no HTTP server". A 2.x build is
neither: it dropped the flags, and its `acp` runs a private
`serve --stdio --port 0` child on loopback. The line now says the build
does not accept the flags, and the comment covers both kinds of build.
`listen_args`'s doc now says only a release version below 2.0 settles the
question without asking the binary.
The 2.0.24 help fixture is now the binary's verbatim output, and the 2.x
stand-in prints it on stdout, as 2.x does (1.18 uses stderr), answering
`--version` with the real `opencode v2.0.24` banner. A new test pins the
rest of the 2.x contract: a managed 2.x label also asks `acp --help`
without running `--version`, and a 2.x whose help lists both flags gets
them. That second half is the only test that reads the help from stdout.
@xintaofei

Copy link
Copy Markdown
Collaborator

codeg work task 301 is done — #909 (1 file, +54/-12).

@xintaofei
xintaofei merged commit ead9e2f into spacering-net:main Oct 9, 2026
7 checks passed
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.

【bug】opencode 2.x 无法连接:0.32.3 起给 acp 追加的 --port/--hostname 被 v2 CLI 拒绝(附日志与根因)

2 participants