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.

gemini: the three copies of the tool-schema repair agree, and a test keeps them agreeing (#484)

Rudy Mizrahi Celekli03f6770fe8ac
diff --git a/gateway/app.py b/gateway/app.py
index 2d25992a..9222a138 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3966,6 +3966,14 @@ def _gemini_schema(node):
elif members:
out = {**members[0], **out}
out.setdefault("type", members[0].get("type") or "string")
+ if isinstance(out.get("enum"), list) and None in out["enum"]:
+ # A nullable enum spelled the JSON-schema way ({"type": ["string", "null"], "enum": [..., null]},
+ # grok's todo_write status) is refused whole: "Enum values must share one supported primitive
+ # type" (gemini-3.5-flash-lite through Vercel, 2026-09-27). The null member is `nullable`.
+ out["enum"] = [x for x in out["enum"] if x is not None]
+ out["nullable"] = True
+ if not out["enum"]:
+ out.pop("enum")
if "type" not in out and "anyOf" not in out:
out["type"] = "object" if "properties" in out else ("array" if "items" in out else "string")
if out.get("type") == "array" and "items" not in out:
diff --git a/gateway/tests/test_gemini_schema_parity.py b/gateway/tests/test_gemini_schema_parity.py
new file mode 100644
index 00000000..af578e29
--- /dev/null
+++ b/gateway/tests/test_gemini_schema_parity.py
@@ -0,0 +1,100 @@
+"""The Gemini tool-schema repair and the thought-signature reader exist three times: in the
+runner's relay (runner/server.py), in the DeepSeek Harness driver's own relay (runner/dsh_driver.py)
+and on the gateway's API front (gateway/app.py). Until there is one implementation (#382), one
+corpus goes through all three and the answers must agree, so a repair made in one copy fails here
+until it is made in the others.
+
+It already had: the nullable-enum repair ({"type": ["string", "null"], "enum": [..., null]}, refused
+whole by Google's validator, 2026-09-27) was in the runner's copy only, so a dsh turn or a gateway
+tool declaration carrying grok's todo_write status still sent the null member to Google.
+"""
+import copy
+import json
+import os
+import pathlib
+import sys
+
+import pytest
+
+_ROOT = pathlib.Path(__file__).resolve().parents[2]
+sys.path.insert(0, str(_ROOT / "gateway"))
+sys.path.insert(0, str(_ROOT / "runner"))
+os.environ.setdefault("HR_BACKING", "local")
+import app # noqa: E402
+import dsh_driver # noqa: E402
+import server # noqa: E402
+
+COPIES = {"runner relay": server, "dsh driver": dsh_driver, "gateway": app}
+
+SCHEMAS = [
+ # the shapes each repair in _gemini_schema exists for
+ {"$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": False,
+ "properties": {"p": {"type": "string"}}, "required": ["p", "gone"]},
+ {"type": "object", "properties": {"mode": {"oneOf": [{"const": "a"}, {"const": "b"}]}}},
+ {"type": "object", "properties": {"n": {"type": "integer", "exclusiveMinimum": 0, "exclusiveMaximum": 9}}},
+ {"type": "object", "properties": {"tag": {"type": ["string", "null"]}}},
+ {"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"},
+ {"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}], "description": "either"},
+ {"anyOf": [{"type": "string", "enum": ["x"]}, {"type": "string", "enum": ["y"]}]},
+ {"anyOf": [{"type": "null"}]},
+ {"type": ["string", "null"], "enum": ["pending", "in_progress", "completed", None]}, # grok's todo_write status
+ {"enum": [None]},
+ {"type": "object", "properties": {}},
+ {"type": "array"},
+ {"type": "array", "items": [{"type": "integer"}]},
+ {"type": "array", "items": []},
+ {"description": "no type at all"},
+ {"properties": {"a": {"items": {"type": "string"}}}},
+ {"type": "object", "properties": {"x": {"type": "string"}}, "required": ["y"]},
+]
+
+
+def _answers(fn, *args):
+ out = {}
+ for name, mod in COPIES.items():
+ out[name] = getattr(mod, fn)(*copy.deepcopy(args))
+ return out
+
+
[email protected]("schema", SCHEMAS, ids=[str(i) for i in range(len(SCHEMAS))])
+def test_every_copy_normalises_a_schema_the_same_way(schema):
+ got = _answers("_gemini_schema", schema)
+ assert got["dsh driver"] == got["runner relay"], got
+ assert got["gateway"] == got["runner relay"], got
+
+
+def test_every_copy_rewrites_a_request_body_the_same_way():
+ tools = [{"type": "function", "function": {"name": f"t{i}", "parameters": s}} for i, s in enumerate(SCHEMAS)]
+ body = json.dumps({"model": "google/gemini-3.8-flash", "messages": [{"role": "user", "content": "hi"}],
+ "tools": tools}).encode()
+ got = {k: json.loads(v) for k, v in _answers("_with_gemini_schemas", body).items()}
+ assert got["dsh driver"] == got["runner relay"]
+ assert got["gateway"] == got["runner relay"]
+ plain = b'{"model": "google/gemini-3.8-flash", "messages": []}'
+ for name, mod in COPIES.items():
+ assert mod._with_gemini_schemas(plain) == plain, name
+
+
+SIGNATURE_DOCS = [
+ {"choices": [{"delta": {"tool_calls": [{"id": "call_1", "extra_content": {"google": {"thought_signature": "sigA"}}}]}}]},
+ {"choices": [{"message": {"tool_calls": [{"id": "call_2", "extra_content": {"google": {"thought_signature": "sigB"}}},
+ {"id": "call_3"}]}}]},
+ {"choices": [{"delta": {"tool_calls": [{"id": "", "extra_content": {"google": {"thought_signature": "s"}}},
+ {"id": "call_4", "extra_content": {"google": {"thought_signature": ""}}},
+ {"id": "call_5", "extra_content": "not a dict"}, "not a call"]}}]},
+ {"choices": ["not a choice", {"delta": "not a dict"}]},
+ {},
+]
+
+
[email protected]("doc", SIGNATURE_DOCS, ids=[str(i) for i in range(len(SIGNATURE_DOCS))])
+def test_every_copy_reads_the_same_thought_signatures(doc):
+ got = _answers("_google_signatures_in", doc)
+ assert got["dsh driver"] == got["runner relay"], got
+ assert got["gateway"] == got["runner relay"], got
+
+
+def test_a_nullable_enum_loses_its_null_member_in_every_copy():
+ for name, mod in COPIES.items():
+ out = mod._gemini_schema({"type": ["string", "null"], "enum": ["a", None]})
+ assert out == {"type": "string", "enum": ["a"], "nullable": True}, (name, out)
diff --git a/runner/dsh_driver.py b/runner/dsh_driver.py
index 8b32768f..5ee8cde2 100644
--- a/runner/dsh_driver.py
+++ b/runner/dsh_driver.py
@@ -178,6 +178,14 @@ def _gemini_schema(node):
elif members:
out = {**members[0], **out}
out.setdefault("type", members[0].get("type") or "string")
+ if isinstance(out.get("enum"), list) and None in out["enum"]:
+ # A nullable enum spelled the JSON-schema way ({"type": ["string", "null"], "enum": [..., null]},
+ # grok's todo_write status) is refused whole: "Enum values must share one supported primitive
+ # type" (gemini-3.5-flash-lite through Vercel, 2026-09-27). The null member is `nullable`.
+ out["enum"] = [x for x in out["enum"] if x is not None]
+ out["nullable"] = True
+ if not out["enum"]:
+ out.pop("enum")
if "type" not in out and "anyOf" not in out:
out["type"] = "object" if "properties" in out else ("array" if "items" in out else "string")
if out.get("type") == "array" and "items" not in out: