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(pi): a text-only channel must not be fed the session's images on replay

richard-epsillafa458ce51335
diff --git a/gateway/app.py b/gateway/app.py
index f6cf7717..f088e84c 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -4413,6 +4413,16 @@ _MODEL_CATALOG: dict[str, dict] = {
"mistral-medium-3.5", "step-3.7-flash"]},
}
_BARE_MODELS = {"", "claude", "codex", "anthropic", "bedrock", "openai", "hermes", "pi"}
+# Models whose serving CHANNEL refuses image input outright. Measured, not assumed — probed
+# 2026-08-19 on the TokenRouter connection with a data-URI image in a user message:
+# qwen3.7-max -> 400 InvalidParameter "Unexpected item type in content" (rejects the TYPE)
+# qwen3.8-max -> 400 about image DIMENSIONS (a 1x1 probe) — i.e. it accepts images
+# gemini-3.6-flash, deepseek-v4-pro, kimi-k3, mistral-medium-3.5, step-3.7-flash -> all 200
+# Consumed by the pi backend: pi replays a session's image tool-results to the CURRENT model
+# (a cross-model conversation is one session), so a text-only channel turns every follow-up in
+# an image-bearing session into a hard 400. Declared text-only, pi drops the image instead —
+# a degraded answer beats a dead conversation.
+_TEXT_ONLY_INPUT = {"qwen3.7-max"}
# Union of BOTH tables' values — a dict merge would drop the bedrock ids (shared keys, anthropic
# values win), silently rejecting the us.anthropic.* ids this set exists to allow.
_PROVIDER_CLAUDE_IDS = {v.lower() for v in [*_BEDROCK_CLAUDE.values(), *_ANTHROPIC_CLAUDE.values()]}
@@ -4797,6 +4807,8 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, s
"idempotency_key": f"{translator.resp_id}:{name}",
# token-level streaming (claude): runner adds --include-partial-messages + emits deltas
"partial_messages": bool(partial_messages),
+ # pi: whether this model's channel takes image input (see _TEXT_ONLY_INPUT)
+ "vision": model_req.strip().lower() not in _TEXT_ONLY_INPUT,
# codex streaming: run via the app-server protocol (item/agentMessage/delta)
"codex_appserver": bool(codex_appserver)}
# Stop requested while we were resolving the connection / provisioning the previous
diff --git a/runner/server.py b/runner/server.py
index f520d3d3..d2619af7 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -1098,11 +1098,19 @@ PI_PROVIDERS = {"anthropic", "openai", "azure", "openai-api", "tokenrouter"}
_PI_CLAUDE_MODEL = re.compile(r"(?:^|/)(?:us\.anthropic\.)?claude", re.I)
-def _pi_models_json(api: str, base_url: str, api_key: str, model: str) -> str:
+def _pi_models_json(api: str, base_url: str, api_key: str, model: str,
+ vision: bool = True) -> str:
"""A one-provider ~/.pi/agent/models.json ("hr") for a custom endpoint. Pi's anthropic client
appends /v1/messages to baseUrl while its openai clients expect the /v1 to already be there
(both read straight off pi's own docs/models.md examples), so the /v1 suffix is normalized
- per api instead of trusting how the integration happened to store the URL."""
+ per api instead of trusting how the integration happened to store the URL.
+
+ `input` is pi's capability gate, and it is load-bearing on RESUME: a session that once ran a
+ vision model can carry an image tool-result, which pi replays to the current model as a user
+ message with an image part — verified against a capturing sink. Declared text-only, pi drops
+ the image and the turn runs; declared vision on a model whose channel refuses images, the
+ whole turn dies on the provider's 400. The gateway says which models are text-only, from
+ live probes, so vision stays the default."""
base = (base_url or "").rstrip("/")
if api == "anthropic-messages":
base = base.removesuffix("/v1")
@@ -1111,7 +1119,7 @@ def _pi_models_json(api: str, base_url: str, api_key: str, model: str) -> str:
return json.dumps({"providers": {"hr": {
"baseUrl": base, "api": api, "apiKey": api_key,
"models": [{"id": model, "name": model, "reasoning": False,
- "input": ["text", "image"],
+ "input": ["text", "image"] if vision else ["text"],
"contextWindow": 200000, "maxTokens": 32000}],
}}}, indent=2)
@@ -1146,7 +1154,7 @@ def _pi_write_mcp(home: pathlib.Path, servers: list[dict] | None) -> bool:
def _build_pi(provider: str, auth: Auth, model: str, prompt: str, cwd: str, env: dict,
resume_session_id: str | None = None, mcp_servers: list[dict] | None = None,
- tools_disabled: list[str] | None = None) -> list[str]:
+ tools_disabled: list[str] | None = None, vision: bool = True) -> list[str]:
pr = provider or "anthropic"
if pr not in PI_PROVIDERS:
raise HTTPException(400, f"unknown pi provider '{pr}' (one of {sorted(PI_PROVIDERS)})")
@@ -1167,7 +1175,7 @@ def _build_pi(provider: str, auth: Auth, model: str, prompt: str, cwd: str, env:
else:
api = "openai-completions"
(home / ".pi" / "agent" / "models.json").write_text(
- _pi_models_json(api, auth.base_url, auth.api_key or "", model))
+ _pi_models_json(api, auth.base_url, auth.api_key or "", model, vision=vision))
pname = "hr"
else:
pname = pr
@@ -2225,6 +2233,7 @@ class TurnReq(BaseModel):
image_auth: dict | None = None # {base_url, api_key, model} for image generation via the broker
idempotency_key: str = "" # dedup a retried /turn: same key -> same turn, no re-exec
partial_messages: bool = False # claude: stream token-level deltas (--include-partial-messages)
+ vision: bool = True # pi: whether the model's channel accepts image input
codex_appserver: bool = False # codex: run via app-server (streams item/agentMessage/delta)
@@ -2324,7 +2333,7 @@ def turn(req: TurnReq, identifier: str = "") -> dict:
model = model or PI_DEFAULT_MODEL
cmd = _build_pi(req.provider, auth, model, req.prompt, cwd, env,
resume_session_id=req.resume_session_id, mcp_servers=req.mcp_servers,
- tools_disabled=req.tools_disabled)
+ tools_disabled=req.tools_disabled, vision=bool(req.vision))
else:
mcp_config = _write_mcp_config_claude(cwd, req.mcp_servers)
cmd = _build_claude(req.provider, auth, model, req.prompt, req.max_turns, cwd, env,
diff --git a/runner/tests/test_pi_normalize.py b/runner/tests/test_pi_normalize.py
index 904e44e6..3da1c1d9 100644
--- a/runner/tests/test_pi_normalize.py
+++ b/runner/tests/test_pi_normalize.py
@@ -208,3 +208,22 @@ def test_models_json_v1_normalization():
assert a["providers"]["hr"]["baseUrl"] == "https://x.example"
b = json.loads(_pi_models_json("openai-completions", "https://x.example", "k", "m"))
assert b["providers"]["hr"]["baseUrl"] == "https://x.example/v1"
+
+
+def test_build_text_only_model_declares_text_input(tmp_path):
+ """A text-only channel (qwen3.7-max via TokenRouter) must get input:["text"] — pi then DROPS
+ replayed image tool-results instead of sending a user+image message the channel 400s on.
+ Mechanism verified against a capturing sink: vision=True serialized the session's image as
+ a user message with an image part (the exact shape the provider rejected); vision=False
+ omitted it and the turn completed."""
+ cmd, _ = _cmdline(tmp_path, provider="tokenrouter", base_url="https://tr.example/v1",
+ model="qwen/qwen3.7-max", vision=False)
+ mj = json.loads((tmp_path / "home" / ".pi" / "agent" / "models.json").read_text())
+ assert mj["providers"]["hr"]["models"][0]["input"] == ["text"]
+
+
+def test_build_vision_default_keeps_image_input(tmp_path):
+ _cmdline(tmp_path, provider="tokenrouter", base_url="https://tr.example/v1",
+ model="moonshotai/kimi-k3")
+ mj = json.loads((tmp_path / "home" / ".pi" / "agent" / "models.json").read_text())
+ assert mj["providers"]["hr"]["models"][0]["input"] == ["text", "image"]