Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

fix(runner): opencode config must match the RELEASED schema, not the source tree

richard-epsillad639b0517200
diff --git a/runner/server.py b/runner/server.py
index 648a33c5..d7d10d7e 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2119,9 +2119,13 @@ def _opencode_denies(tools_disabled: list[str] | None) -> dict:
def _opencode_mcp(servers: list[dict] | None) -> dict:
- """opencode `mcp.servers.<name>`: a tagged union on `type` (packages/core/src/config/mcp.ts).
- local => {command:[...]}, remote => {url, headers}. oauth is pinned false: an interactive
- OAuth dance has nowhere to happen in a sandbox, and leaving it unset invites one."""
+ """opencode `mcp.<name>`: a tagged union on `type`, local => {command:[...]},
+ remote => {url, headers}. oauth is pinned false: an interactive OAuth dance has nowhere to
+ happen in a sandbox, and leaving it unset invites one.
+
+ Shape taken from the PUBLISHED schema (https://opencode.ai/config.json), not from the repo's
+ source tree. The tree is ahead of the release and disagrees with it: source nests servers under
+ `mcp.servers` and gives `timeout` an object, the shipped binary wants a flat `mcp.<name>` map."""
out: dict = {}
for i, sv in enumerate(servers or []):
if not isinstance(sv, dict):
@@ -2179,14 +2183,16 @@ def _opencode_config(auth: Auth, model: str, cwd: str, mcp_servers: list[dict] |
}
mcp = _opencode_mcp(mcp_servers)
if mcp:
- cfg["mcp"] = {"servers": mcp}
+ cfg["mcp"] = mcp
denies = _opencode_denies(tools_disabled)
if denies:
cfg["permission"] = denies
if skills_dir:
- # `skills` takes arbitrary paths, so the directory _write_skills already produced is named
- # here directly. No mirroring into a per-CLI home, which is the trap codex and hermes set.
- cfg["skills"] = [skills_dir]
+ # `skills.paths` takes arbitrary directories, so the one _write_skills already produced is
+ # named here directly. No mirroring into a per-CLI home, which is the trap codex and hermes
+ # set. Shape is {paths, urls} per the published schema; the source tree's bare array is a
+ # newer form the released binary rejects outright ("Expected object | undefined").
+ cfg["skills"] = {"paths": [skills_dir]}
pathlib.Path(cwd, "opencode.json").write_text(json.dumps(cfg, indent=2))
return f"hr/{model}"
@@ -2281,8 +2287,19 @@ def _opencode_to_claude(obj: dict, state: dict) -> list[dict]:
if t == "error":
# The CLI can exit 0 on a provider error, so this event is the only truthful failure
# signal — the same trap pi has.
+ # Real shape, captured from a live 401 against the relay:
+ # {"type":"error","sessionID":...,"error":{"name":"APIError",
+ # "data":{"message":"...","statusCode":401,...}}}
+ # The message is nested under `data`, so reading `error.message` yields nothing and the
+ # user gets a stringified dict. Try the nested form first, then the flat one.
err = obj.get("error")
- state["_oc_error"] = str(err.get("message") if isinstance(err, dict) else err or "opencode error")
+ msg = ""
+ if isinstance(err, dict):
+ data = err.get("data") if isinstance(err.get("data"), dict) else {}
+ msg = str(data.get("message") or err.get("message") or err.get("name") or "")
+ elif err:
+ msg = str(err)
+ state["_oc_error"] = msg or "opencode error"
return pre
return pre
diff --git a/runner/tests/test_opencode_normalize.py b/runner/tests/test_opencode_normalize.py
index 6b27b87a..d428d72a 100644
--- a/runner/tests/test_opencode_normalize.py
+++ b/runner/tests/test_opencode_normalize.py
@@ -98,6 +98,28 @@ def test_usage_ignores_a_missing_or_malformed_payload():
assert state.get("_oc_usage", {}).get("input_tokens", 0) == 0
+def test_mcp_is_a_flat_name_to_server_map_not_nested_under_servers():
+ """The RELEASED schema (opencode.ai/config.json) is `mcp.<name>`. The repo source tree is ahead
+ of the release and nests under `mcp.servers`; writing that shape makes the shipped binary
+ refuse the whole config."""
+ d = tempfile.mkdtemp()
+ _opencode_config(Auth(api_key="k", base_url="https://relay.example/v1"), "gpt-5.4", d,
+ [{"name": "docs", "url": "https://mcp.example/sse"}], None, None, "openai-api")
+ cfg = _json.loads(open(f"{d}/opencode.json").read())
+ assert "servers" not in cfg["mcp"]
+ assert cfg["mcp"]["docs"]["type"] == "remote"
+
+
+def test_skills_is_an_object_with_paths_not_a_bare_array():
+ """The released binary rejects a bare array: "Expected object | undefined, got [...] skills".
+ This is the shape that actually failed a live turn."""
+ d = tempfile.mkdtemp()
+ _opencode_config(Auth(api_key="k", base_url="https://relay.example/v1"), "gpt-5.4", d, None,
+ "/ws/.harness/skills", None, "openai-api")
+ cfg = _json.loads(open(f"{d}/opencode.json").read())
+ assert cfg["skills"] == {"paths": ["/ws/.harness/skills"]}
+
+
def test_mcp_remote_pins_oauth_off_and_keeps_headers():
"""An interactive OAuth dance has nowhere to happen in a sandbox."""
out = _opencode_mcp([{"name": "docs", "url": "https://mcp.example/sse",
@@ -233,3 +255,18 @@ def test_a_gpt_model_through_the_router_uses_the_responses_package():
def test_everything_else_falls_to_openai_compatible():
assert _npm_for("qwen3.7-max", "openai-api") == "@ai-sdk/openai-compatible"
assert _npm_for("deepseek-v4-pro", "openai-api") == "@ai-sdk/openai-compatible"
+
+
+def test_error_message_is_read_from_the_real_nested_shape():
+ """Captured from a live 401 against the relay: the message is under error.data.message, not
+ error.message. Reading the flat key gave the user a stringified dict."""
+ _, state = _run([_ev("error", error={"name": "APIError",
+ "data": {"message": "Authentication failed.", "statusCode": 401}})])
+ assert state["_oc_error"] == "Authentication failed."
+
+
+def test_error_falls_back_to_the_flat_message_then_the_name():
+ _, s1 = _run([_ev("error", error={"message": "flat form"})])
+ assert s1["_oc_error"] == "flat form"
+ _, s2 = _run([_ev("error", error={"name": "APIError"})])
+ assert s2["_oc_error"] == "APIError"