Skip to content

The agent that grows with you

fix: Gemini/Copilot signatures survive reloads; an error body can't switch off DeepSeek replay

Tekniumf691e7b7fb07
diff --git a/agent/message_sanitization.py b/agent/message_sanitization.py
index 080c4009e93..f0eb59cb49b 100644
--- a/agent/message_sanitization.py
+++ b/agent/message_sanitization.py
@@ -646,6 +646,8 @@ _REASONING_ECHO_RULES: tuple = (
("kimi", frozenset({"kimi-coding", "kimi-coding-cn"}), frozenset(), (), ("api.kimi.com", "moonshot.ai", "moonshot.cn")),
("deepseek", frozenset(), frozenset({"deepseek"}), ("deepseek",), ("api.deepseek.com",)),
("mimo", frozenset(), frozenset({"xiaomi"}), ("mimo",), ("api.xiaomimimo.com", "xiaomimimo.com")),
+ # Portal stealth model that 400s on a tool-call turn without reasoning_content (f86276d2ebc).
+ ("missingno", frozenset(), frozenset(), ("stealth/missingno",), ()),
)
_REASONING_ECHO_RULE_BY_FAMILY = {rule[0]: rule for rule in _REASONING_ECHO_RULES}
@@ -872,7 +874,12 @@ def apply_reasoning_content_policy(
else:
api_msg.pop(R, None)
if carriers is not None and RD not in carriers:
- api_msg.pop(RD, None)
+ # Private ``*.native_assistant`` records (Gemini/Copilot carriers) survive: the transport lifts
+ # them onto the route that reads them and filters them from every other wire.
+ private = [d for d in api_msg.pop(RD, None) or () if isinstance(d, dict)
+ and str(d.get("type") or "").endswith(".native_assistant")]
+ if private:
+ api_msg[RD] = private
def _reasoning_shape(msg: dict) -> tuple:
@@ -904,7 +911,7 @@ def reapply_reasoning_echo(api_messages: list, needs_thinking_pad: bool, carrier
_UNKNOWN_FIELD_PHRASES = (
"extra inputs are not permitted", "is unsupported", "no such field", "unknown field",
"unrecognized request argument", "unrecognized field", "unknown parameter", "unexpected field",
- "additional properties", "unknown key", "not allowed",
+ "additional propert", "unknown key",
)
_NAMED_FIELD_RES = {
RC: re.compile(r"(?<![\w])reasoning_content(?![\w])"),
@@ -975,7 +982,13 @@ def record_reasoning_field_rejection(agent: Any, error_body: Any, sent_messages:
(provider, host, model) for the rest of the session. A repeat rejection of an already
recorded key returns empty, so recovery can never loop. History is never touched.
"""
+ if getattr(agent, "api_mode", "chat_completions") != "chat_completions":
+ return frozenset()
fields = rejected_reasoning_fields(error_body, sent_messages)
+ if needs_reasoning_echo(getattr(agent, "provider", ""), getattr(agent, "model", ""), getattr(agent, "base_url", "")):
+ # Must-echo routes 400 on any tool turn WITHOUT reasoning_content; a body naming it is a
+ # value complaint ("must not be empty"), never a schema that lacks the field.
+ fields -= {RC}
if not fields:
return frozenset()
new = fields - rejected_reasoning_carriers(agent)
diff --git a/tests/agent/test_reasoning_replay_routes.py b/tests/agent/test_reasoning_replay_routes.py
index e8182b72598..a2f57764404 100644
--- a/tests/agent/test_reasoning_replay_routes.py
+++ b/tests/agent/test_reasoning_replay_routes.py
@@ -119,3 +119,33 @@ def test_named_field_rejection_strips_once_per_model_and_never_loops(tmp_path):
# A sibling model on the same gateway keeps every carrier.
sibling = reasoning_replay_route("chat_completions", "nous", "moonshotai/kimi-k3", lane.base_url)
assert "reasoning_details" in sibling.carriers
+
+
+def test_route_shaping_keeps_private_native_carrier_for_the_transport():
+ """A resumed Gemini/Copilot row carries its signature only as a private reasoning_details record;
+ route shaping must leave it for ``shape_wire_carriers`` even on routes that never read the array."""
+ from agent.message_sanitization import apply_reasoning_content_policy, reasoning_replay_route
+ from agent.reasoning_carriers import CARRIER_TYPE, shape_wire_carriers
+
+ base = "https://generativelanguage.googleapis.com/v1beta/openai"
+ record = {"type": CARRIER_TYPE, "extra_content": {"google": {"thought_signature": "SIG"}}}
+ row = {"role": "assistant", "content": "391", "reasoning_details": [{"type": "reasoning.text", "text": "t"}, record]}
+ route = reasoning_replay_route("chat_completions", "gemini", "gemini-3.5-pro", base)
+ api = dict(row)
+ apply_reasoning_content_policy(row, api, route.pad, route.carriers)
+ wire = shape_wire_carriers([api], model="gemini-3.5-pro", base_url=base)[0]
+ assert wire["extra_content"] == record["extra_content"]
+ assert "reasoning_details" not in wire
+
+
+def test_value_complaint_never_strips_reasoning_content_from_a_must_echo_route():
+ from types import SimpleNamespace
+ from agent.message_sanitization import record_reasoning_field_rejection
+
+ agent = SimpleNamespace(provider="deepseek", model="deepseek-v4-flash", base_url="https://api.deepseek.com/v1",
+ api_mode="chat_completions", _reasoning_rejecting_routes={}, session_id=None)
+ sent = [{"role": "assistant", "content": "", "reasoning_content": " ", "tool_calls": [{"id": "c"}]}]
+ for body in ("reasoning_content is not allowed to be empty",
+ "Extra inputs are not permitted, field: 'messages[1].reasoning_content'"):
+ assert record_reasoning_field_rejection(agent, body, sent) == frozenset()
+ assert agent._reasoning_rejecting_routes == {}