The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): clean-EOF tool-call retry exhaustion no longer blames the network (#102766)
kshitijk4poora142d963e0e2
diff --git a/agent/turn_failure_copy.py b/agent/turn_failure_copy.pyindex f15409f192a..115231f66a8 100644--- a/agent/turn_failure_copy.py+++ b/agent/turn_failure_copy.py@@ -316,8 +316,7 @@ _ONE_OFF_COPY: Dict[str, str] = {# Rides failure_reason="truncated": args were cut mid-JSON but the model never reported# an output-length stop, so don't claim it hit one (#91717)."truncated_unreported": (- "The model's action arrived cut off partway through (finish_reason={finish_reason}), so "- "Hermes didn't run it. Nothing was changed. The model didn't report hitting its output "+ "The model's action arrived cut off partway through, so Hermes didn't run it. Nothing was changed. The model didn't report hitting its output ""limit, so this was most likely a dropped connection or a provider/router cutting the ""reply short. Send /retry; if it keeps happening, ask for the work in smaller steps."),@@ -326,6 +325,13 @@ _ONE_OFF_COPY: Dict[str, str] = {"so nothing was run. Check your network and send /retry; asking for the file in smaller ""pieces also helps."),+ # Rides failure_reason="truncated": clean EOF (no transport error, no finish_reason)+ # mid tool-call, retries exhausted — not a network problem on the user's side (#102766).+ "stream_closed_tool_call": (+ "{label} kept closing the stream before the model finished writing its action, without "+ "reporting an error, so nothing was run. This is usually the provider or a proxy in front "+ "of it cutting long replies short. Send /retry; asking for the work in smaller steps also helps."+ ),# Rides failure_reason="loop_error" (advisory; the turn is incomplete, not failed)."local_processing_error": ("Hermes hit an internal error while handling the model's reply and stopped this turn. "diff --git a/agent/turn_truncation.py b/agent/turn_truncation.pyindex 10bfe02c955..dbcdb42233d 100644--- a/agent/turn_truncation.py+++ b/agent/turn_truncation.py@@ -409,7 +409,17 @@ def _retry_truncated_tool_call(st: _Trunc, api_kwargs: Any) -> TruncationVerdict)return st.done("continue") # don't append the broken responseagent._flush_status_buffer()- if st.is_stub:+ _failure = FailoverReason.timeout.value if st.is_stub else "truncated"+ if st.is_stub and getattr(st.response, "_clean_eof", False):+ # #102766: no transport error — the server (or a proxy) closed the stream cleanly+ # without a finish_reason, so "check your network" copy / a timeout stamp would mislead.+ agent._vprint(+ f"{agent.log_prefix}⚠️ Server kept closing the stream mid tool-call after 4 retries — the action was not executed.",+ force=True, diagnostic=True,+ )+ _final_response = site_copy("stream_closed_tool_call", label=provider_label_for(agent.provider))+ _failure = "truncated"+ elif st.is_stub:agent._vprint(f"{agent.log_prefix}⚠️ Stream kept dropping mid tool-call after 4 retries — the action was not executed.",force=True, diagnostic=True,@@ -426,7 +436,7 @@ def _retry_truncated_tool_call(st: _Trunc, api_kwargs: Any) -> TruncationVerdictclose_interrupted_tool_sequence(st.messages, _final_response)return st.end_turn(_final_response, cleanup=False,- failure=(FailoverReason.timeout.value if st.is_stub else "truncated", True),+ failure=(_failure, True),)@@ -451,18 +461,17 @@ def recover_from_truncation(compression_attempts=compression_attempts,)st.window_filled = _prompt_filled_window(agent, response)- agent._vprint(- f"{agent.log_prefix}⚠️ Response truncated — server ended the stream without ever sending "- f"finish_reason (not a network drop)"- if st.is_stub and getattr(response, "_clean_eof", False) else- f"{agent.log_prefix}⚠️ Response truncated — stream ended before completion"- if st.is_stub else- f"{agent.log_prefix}⚠️ Response truncated (finish_reason='length') - the prompt filled the "- f"context window ({st.window_filled[0]:,}/{st.window_filled[1]:,} tokens)"- if st.window_filled else- f"{agent.log_prefix}⚠️ Response truncated (finish_reason='length') - model hit max output tokens",- force=True, diagnostic=True,- )+ if st.is_stub and getattr(response, "_clean_eof", False):+ _banner = ("Response truncated — server ended the stream without ever sending finish_reason "+ "(no transport error — the server or a proxy closed the stream cleanly)")+ elif st.is_stub:+ _banner = "Response truncated — stream ended before completion"+ elif st.window_filled:+ _banner = (f"Response truncated (finish_reason='length') - the prompt filled the context window "+ f"({st.window_filled[0]:,}/{st.window_filled[1]:,} tokens)")+ else:+ _banner = "Response truncated (finish_reason='length') - model hit max output tokens"+ agent._vprint(f"{agent.log_prefix}⚠️ {_banner}", force=True, diagnostic=True)# #106260: a context-overflow error after partial delivery must not seed a# continuation. _partial_stream_stub marks such stubs _overflow_terminal anddiff --git a/tests/agent/test_run_agent.py b/tests/agent/test_run_agent.pyindex ad8b64f0d65..31757e744ac 100644--- a/tests/agent/test_run_agent.py+++ b/tests/agent/test_run_agent.py@@ -4353,11 +4353,15 @@ class TestRunConversation:patch.object(agent, "_save_trajectory"),patch.object(agent, "_cleanup_task_resources"),):- agent.run_conversation("write the report")+ result = agent.run_conversation("write the report")text = " ".join(printed)assert "server ended the stream without ever sending finish_reason" in textassert "stream ended before completion" not in text+ # Retries exhausted: the final copy/reason must not blame the network either.+ assert "Check your network" not in result["final_response"]+ assert "kept closing the stream" in result["final_response"]+ assert result["failure_reason"] == "truncated"def test_transport_drop_stub_keeps_original_truncation_message(self, agent):"""Companion to the clean-EOF test above: a stub NOT tagged