Skip to content

opencode-acp-adapter: --server value is never validated — a trailing --server silently talks to the default serve, --server= / a flag-like value loop forever on 'Failed to parse URL', and a typo'd flag is silently ignored #6939

Closed

Description

@dezren39

opencode-acp-adapter: --server value is never validated — a trailing --server silently talks to the default serve, --server= / a flag-like value loop forever on "Failed to parse URL", and a typo'd flag is silently ignored

Summary

bin/opencode-acp-adapter.mjs takes its one operator flag, --server, with no validation at all. In parseServerUrl (lines 64–76 at def55caf48):

function parseServerUrl(argv) {
  let server = process.env.OPENCODE_ACP_SERVER || 'http://127.0.0.1:13420';
  for (let i = 0; i < argv.length; i += 1) {
    if (argv[i] === '--server' && argv[i + 1]) {
      server = argv[i + 1];
      i += 1;
    } else if (argv[i].startsWith('--server=')) {
      server = argv[i].slice('--server='.length);
    }
  }
  return server.replace(/\/+$/, '');
}
  • A trailing --server fails the argv[i + 1] truthiness check and is silently dropped — the adapter talks to the default http://127.0.0.1:13420 serve (or the env var) instead of the server the operator meant to name, with no warning anywhere.
  • --server= sets server to the empty string. Every request becomes a relative URL: the event stream (runEventStream, lines 226–257) logs Failed to parse URL from /api/event; reconnecting and retries every 1s forever, and session calls fail the same way — yet ACP initialize still succeeds, so the gateway sees a healthy agent whose every session is broken.
  • A flag-like value (--server --bogus-flag) is consumed verbatim as the URL: Failed to parse URL from --bogus-flag/api/event; reconnecting, same infinite loop.
  • A typo'd flag (--sever http://127.0.0.1:9) matches nothing in the loop and is silently ignored — again the default serve, no signal.

parseServerUrl is not exported and has no unit coverage: bin/opencode-acp-adapter.test.mjs only ever passes a well-formed --server http://127.0.0.1:<port> (line 105).

Evidence (verified this run, laptop, origin/main def55caf484833e062247c46e5b0c4bb719accd3)

Probe ~/git/fleet/probe-acp-server-arg/ — the real module on the laptop primary (md5 bd0bdaccb8c47bd031bb82a6b8149d08), driven over stdio JSON-RPC (initialize + session/new) with OPENCODE_ACP_ADAPTER_DEBUG=1; the startup debug line prints the resolved serverBase:

Invocation Observed
control: --server http://127.0.0.1:9 started; server=http://127.0.0.1:9; event stream fetch failed; reconnecting (connection refused on the named port — the named server is the one being dialled)
--server (trailing) started; server=http://127.0.0.1:13420 — the explicit flag silently dropped, default serve used
--server= started; server= — event stream error: Failed to parse URL from /api/event; reconnecting (1s retry loop, never exits); initialize still returns success
--server --bogus-flag started; server=--bogus-flag — event stream error: Failed to parse URL from --bogus-flag/api/event; reconnecting, same loop
--sever http://127.0.0.1:9 (typo) started; server=http://127.0.0.1:13420 — unknown flag silently ignored, default serve used

Why it matters

This adapter is the bridge between the ACP gateway (acpx/OpenClaw) and the standing OpenCode serve: prompts, sessions, and the server password resolved in serverPassword() all go to whatever serverBase resolves to. Silently falling back to the default serve means a mis-typed launch sends a session's prompts — authenticated with the standing server's credential — to a different server than the operator configured, and the only evidence is a debug line nobody has on by default. The empty/flag-like cases are the opposite failure with the same silence problem: the process never fails fast, initialize succeeds, and the misconfiguration surfaces only as an endless reconnect loop and per-session URL-parse errors that name no flag and no value.

This is the concrete instance for this script of the repo's strict-argv problem class (umbrella design #3352; sibling instances #3469 for the quota exporters, #3415, #3449) — those filings do not touch this file.

Acceptance criteria

  • --server with a missing (trailing), empty (--server= or --server ""), or flag-like (--…) value fails fast at startup: a usage error on stderr naming the flag and the offending value, non-zero exit, before the event stream starts and before any ACP traffic is served.
  • A --server value that is not a parseable http:/https: URL fails the same way at startup — never as a per-request Failed to parse URL reconnect loop.
  • The valid forms keep working unchanged: --server <url>, --server=<url>, trailing slashes stripped, OPENCODE_ACP_SERVER env fallback, and the built-in default when neither is given.
  • Regression tests in bin/opencode-acp-adapter.test.mjs cover: trailing --server, --server=, flag-like --server value, and a non-URL value — each asserting the fast non-zero exit naming --server; the existing well-formed --server control keeps passing and the full suite passes.
  • Unknown-argument handling (e.g. the --sever typo) follows the contract chosen under Design: unknown means stop — one strict argument contract for the repo's operator scripts #3352 — at minimum it must not silently change which server is dialled without a stderr signal.

Related: #3352 (umbrella strict-argv design), #3469 (same failure class in the three quota exporters — different files, different argv code).

Activity

  1. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  2. added
    queue/queued
    source/creator
    task/small-fix
    status/needs-triage
    priority/normal
    kind/bug
    effort/xs
    app/opencode-acp-adapter
    on Nov 7, 2026
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  5. added
    work/assigned
    queue/claimed
    and removed
    status/needs-triage
    queue/queued
    on Nov 8, 2026
  6. 15 remaining items

  7. added
    queue/parked
    status/parked
    queue/claimed
    status/in-progress
    and removed
    queue/claimed
    status/parked
    queue/parked
    on Nov 9, 2026
  8. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up — Agent: queue worker (repo-worker-code), lane code-n — Session/ID: task 11326, repo-queue-worker-shift-n 2026-11-09 run. Task 11326 (small_fix) for issue #6939: opencode-acp-adapter validate --server value. Fresh check: issue #6939 OPEN, no held/user/owned/do-not-merge/do-not-auto-edit labels. Execution lane = direct (row 3645), so this lane works it: validate --server in bin/opencode-acp-adapter.mjs per the issue acceptance criteria, with regression tests.

  9. removed
    status/in-progress
    queue/claimed
    work/assigned
    on Nov 9, 2026
  10. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — Agent: queue worker (repo-worker-code), lane code-n — Session/ID: task 11326, repo-queue-worker-shift-n 2026-11-09 run. Task 11326 (small_fix) for issue #6939 resumed from the prior attempt's pushed work (§10 resume, don't restart): branch queue/11326-6939-acp-server-validate / PR #8054 already carried the --server validation fix. Verified fresh this shift: node --test bin/opencode-acp-adapter.test.mjs — 18/18 pass on the laptop worktree at b1aa662 (8 new #6939 regression tests included); Codex review posted no concrete findings (its summary comment carried no finding threads and a usage-limit notice). Merged PR #8054 (squash) — merge sha b236b1d; issue #6939 CLOSED.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/opencode-acp-adaptereffort/xskind/bugpriority/normalsource/creatorstatus:donetask/small-fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions