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.

No anyOf leaves the Gemini declaration normaliser (#104)

github-actions[bot]14c40ad69283
diff --git a/gateway/app.py b/gateway/app.py
index 7d4c5111..d5f36234 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3181,21 +3181,22 @@ def _gemini_schema(node):
out["type"] = non_null[0] if non_null else "string"
if "null" in t:
out["nullable"] = True
- if "type" not in out and isinstance(out.get("anyOf"), list):
- # a nullable choice (zod's optional): the null member becomes `nullable`, one remaining member
- # becomes the node itself, several keep anyOf under the first member's type; without a type
- # the channel for gemini-3.5-flash answers "schema didn't specify the schema type field"
- members = [m for m in out["anyOf"] if isinstance(m, dict) and m.get("type") != "null"]
- if len(members) < len(out["anyOf"]):
+ if isinstance(out.get("anyOf"), list):
+ # No anyOf leaves this relay: one channel refuses an anyOf node without a type ("schema
+ # didn't specify the schema type field", gemini-3.5-flash) and another refuses one with
+ # anything beside it ("schema specified other fields alongside any_of", gemini-3.6-flash,
+ # both measured 2026-09-06 on TokenRouter). The null member becomes `nullable`; a choice of
+ # constants becomes one enum; any other choice becomes its first member under the node's
+ # own description, which is what the model reads.
+ members = [m for m in out.pop("anyOf") if isinstance(m, dict) and m.get("type") != "null"]
+ if len(members) < len(node.get("anyOf") or []):
out["nullable"] = True
- if len(members) == 1:
- out = {**members[0], **{k: v for k, v in out.items() if k != "anyOf"}}
- out.setdefault("type", members[0].get("type", "string"))
+ if members and all("enum" in m and "properties" not in m and "items" not in m for m in members):
+ out = {**members[0], **out, "enum": [x for m in members for x in m["enum"]]}
+ out.setdefault("type", "string")
elif members:
- out["anyOf"] = members
- out["type"] = members[0].get("type") or "string"
- else:
- out.pop("anyOf")
+ out = {**members[0], **out}
+ out.setdefault("type", members[0].get("type") or "string")
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_google_provider.py b/gateway/tests/test_google_provider.py
index 2a8f7a73..781ac98c 100644
--- a/gateway/tests/test_google_provider.py
+++ b/gateway/tests/test_google_provider.py
@@ -125,7 +125,7 @@ def test_a_harness_tool_schema_is_normalised_to_googles_subset():
item = out["properties"]["files"]["items"]
assert item["properties"]["end_line"] == {"description": "line", "type": "string"}
assert item["properties"]["count"] == {"type": "integer", "minimum": 0}
- assert item["properties"]["mode"] == {"type": "string", "anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
+ assert item["properties"]["mode"] == {"type": "string", "enum": ["a", "b"]}
assert item["properties"]["tag"] == {"type": "string", "nullable": True}
assert item["required"] == ["path"]
assert out["properties"]["opts"] == {"type": "object"}
@@ -147,6 +147,6 @@ def test_only_tool_parameters_change_and_an_empty_declaration_is_dropped():
def test_a_nullable_choice_gets_a_type():
# zod's optional integer: anyOf [integer, null] with no type; the 3.5-flash channel refuses it without one
assert gw._gemini_schema({"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"}) == {"type": "integer", "nullable": True, "description": "line"}
- two = gw._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}]})
- assert two["type"] == "string" and two["nullable"] is True and [m["type"] for m in two["anyOf"]] == ["string", "integer"]
+ two = gw._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}], "description": "either"})
+ assert two == {"type": "string", "nullable": True, "description": "either"} # no anyOf leaves the relay
assert gw._gemini_schema({"anyOf": [{"type": "null"}]}) == {"type": "string", "nullable": True}
diff --git a/runner/dsh_driver.py b/runner/dsh_driver.py
index 03ef6df5..20d0f984 100644
--- a/runner/dsh_driver.py
+++ b/runner/dsh_driver.py
@@ -140,21 +140,22 @@ def _gemini_schema(node):
out["type"] = non_null[0] if non_null else "string"
if "null" in t:
out["nullable"] = True
- if "type" not in out and isinstance(out.get("anyOf"), list):
- # a nullable choice (zod's optional): the null member becomes `nullable`, one remaining member
- # becomes the node itself, several keep anyOf under the first member's type; without a type
- # the channel for gemini-3.5-flash answers "schema didn't specify the schema type field"
- members = [m for m in out["anyOf"] if isinstance(m, dict) and m.get("type") != "null"]
- if len(members) < len(out["anyOf"]):
+ if isinstance(out.get("anyOf"), list):
+ # No anyOf leaves this relay: one channel refuses an anyOf node without a type ("schema
+ # didn't specify the schema type field", gemini-3.5-flash) and another refuses one with
+ # anything beside it ("schema specified other fields alongside any_of", gemini-3.6-flash,
+ # both measured 2026-09-06 on TokenRouter). The null member becomes `nullable`; a choice of
+ # constants becomes one enum; any other choice becomes its first member under the node's
+ # own description, which is what the model reads.
+ members = [m for m in out.pop("anyOf") if isinstance(m, dict) and m.get("type") != "null"]
+ if len(members) < len(node.get("anyOf") or []):
out["nullable"] = True
- if len(members) == 1:
- out = {**members[0], **{k: v for k, v in out.items() if k != "anyOf"}}
- out.setdefault("type", members[0].get("type", "string"))
+ if members and all("enum" in m and "properties" not in m and "items" not in m for m in members):
+ out = {**members[0], **out, "enum": [x for m in members for x in m["enum"]]}
+ out.setdefault("type", "string")
elif members:
- out["anyOf"] = members
- out["type"] = members[0].get("type") or "string"
- else:
- out.pop("anyOf")
+ out = {**members[0], **out}
+ out.setdefault("type", members[0].get("type") or "string")
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/runner/server.py b/runner/server.py
index e4750ad9..07f10dd9 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2311,21 +2311,22 @@ def _gemini_schema(node):
out["type"] = non_null[0] if non_null else "string"
if "null" in t:
out["nullable"] = True
- if "type" not in out and isinstance(out.get("anyOf"), list):
- # a nullable choice (zod's optional): the null member becomes `nullable`, one remaining member
- # becomes the node itself, several keep anyOf under the first member's type; without a type
- # the channel for gemini-3.5-flash answers "schema didn't specify the schema type field"
- members = [m for m in out["anyOf"] if isinstance(m, dict) and m.get("type") != "null"]
- if len(members) < len(out["anyOf"]):
+ if isinstance(out.get("anyOf"), list):
+ # No anyOf leaves this relay: one channel refuses an anyOf node without a type ("schema
+ # didn't specify the schema type field", gemini-3.5-flash) and another refuses one with
+ # anything beside it ("schema specified other fields alongside any_of", gemini-3.6-flash,
+ # both measured 2026-09-06 on TokenRouter). The null member becomes `nullable`; a choice of
+ # constants becomes one enum; any other choice becomes its first member under the node's
+ # own description, which is what the model reads.
+ members = [m for m in out.pop("anyOf") if isinstance(m, dict) and m.get("type") != "null"]
+ if len(members) < len(node.get("anyOf") or []):
out["nullable"] = True
- if len(members) == 1:
- out = {**members[0], **{k: v for k, v in out.items() if k != "anyOf"}}
- out.setdefault("type", members[0].get("type", "string"))
+ if members and all("enum" in m and "properties" not in m and "items" not in m for m in members):
+ out = {**members[0], **out, "enum": [x for m in members for x in m["enum"]]}
+ out.setdefault("type", "string")
elif members:
- out["anyOf"] = members
- out["type"] = members[0].get("type") or "string"
- else:
- out.pop("anyOf")
+ out = {**members[0], **out}
+ out.setdefault("type", members[0].get("type") or "string")
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/runner/tests/test_dsh_driver_gemini_schema.py b/runner/tests/test_dsh_driver_gemini_schema.py
index f6734973..104b2261 100644
--- a/runner/tests/test_dsh_driver_gemini_schema.py
+++ b/runner/tests/test_dsh_driver_gemini_schema.py
@@ -22,7 +22,7 @@ def test_a_harness_tool_schema_is_normalised_to_googles_subset():
item = out["properties"]["files"]["items"]
assert item["properties"]["end_line"] == {"description": "line", "type": "string"}
assert item["properties"]["count"] == {"type": "integer", "minimum": 0}
- assert item["properties"]["mode"] == {"type": "string", "anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
+ assert item["properties"]["mode"] == {"type": "string", "enum": ["a", "b"]}
assert item["properties"]["tag"] == {"type": "string", "nullable": True}
assert item["required"] == ["path"]
assert out["properties"]["opts"] == {"type": "object"}
@@ -44,6 +44,6 @@ def test_only_tool_parameters_change_and_an_empty_declaration_is_dropped():
def test_a_nullable_choice_gets_a_type():
# zod's optional integer: anyOf [integer, null] with no type; the 3.5-flash channel refuses it without one
assert dsh_driver._gemini_schema({"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"}) == {"type": "integer", "nullable": True, "description": "line"}
- two = dsh_driver._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}]})
- assert two["type"] == "string" and two["nullable"] is True and [m["type"] for m in two["anyOf"]] == ["string", "integer"]
+ two = dsh_driver._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}], "description": "either"})
+ assert two == {"type": "string", "nullable": True, "description": "either"} # no anyOf leaves the relay
assert dsh_driver._gemini_schema({"anyOf": [{"type": "null"}]}) == {"type": "string", "nullable": True}
diff --git a/runner/tests/test_relay_gemini_schema.py b/runner/tests/test_relay_gemini_schema.py
index 4640adfc..8d534966 100644
--- a/runner/tests/test_relay_gemini_schema.py
+++ b/runner/tests/test_relay_gemini_schema.py
@@ -22,7 +22,7 @@ def test_a_harness_tool_schema_is_normalised_to_googles_subset():
item = out["properties"]["files"]["items"]
assert item["properties"]["end_line"] == {"description": "line", "type": "string"}
assert item["properties"]["count"] == {"type": "integer", "minimum": 0}
- assert item["properties"]["mode"] == {"type": "string", "anyOf": [{"enum": ["a"], "type": "string"}, {"enum": ["b"], "type": "string"}]}
+ assert item["properties"]["mode"] == {"type": "string", "enum": ["a", "b"]}
assert item["properties"]["tag"] == {"type": "string", "nullable": True}
assert item["required"] == ["path"]
assert out["properties"]["opts"] == {"type": "object"}
@@ -44,6 +44,6 @@ def test_only_tool_parameters_change_and_an_empty_declaration_is_dropped():
def test_a_nullable_choice_gets_a_type():
# zod's optional integer: anyOf [integer, null] with no type; the 3.5-flash channel refuses it without one
assert server._gemini_schema({"anyOf": [{"type": "integer"}, {"type": "null"}], "description": "line"}) == {"type": "integer", "nullable": True, "description": "line"}
- two = server._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}]})
- assert two["type"] == "string" and two["nullable"] is True and [m["type"] for m in two["anyOf"]] == ["string", "integer"]
+ two = server._gemini_schema({"anyOf": [{"type": "string"}, {"type": "integer"}, {"type": "null"}], "description": "either"})
+ assert two == {"type": "string", "nullable": True, "description": "either"} # no anyOf leaves the relay
assert server._gemini_schema({"anyOf": [{"type": "null"}]}) == {"type": "string", "nullable": True}