From 182c09b80bdd71e2dd21d8421a158ffced8f3bc6 Mon Sep 17 00:00:00 2001 From: webtecnica <75556242+webtecnica@users.noreply.github.com> Date: Wed, 22 Jul 2026 16:59:29 -0300 Subject: [PATCH] fix(agent): prevent agent hang after tool call completes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a tool call completes, the conversation loop does to start the next API call. Between the last (from tool completion in tool_executor.py) and the next one (at the start of the next API call), there is a gap. If anything during this gap takes time — context compression, slow provider prefill, or other post-tool processing — the combined inactivity window can exceed the gateway's inactivity_timeout (default 120s). The gateway kills the session and the user sees 'agent never returns a final response', even though the tool call itself succeeded in 0.1-0.2s. Fix: call right before so the gateway sees a fresh timestamp immediately after tool results are posted, regardless of how long the follow-up API call takes. Fixes #69559 --- agent/conversation_loop.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py index a234213e32ca..2f452cadb49b 100644 --- a/agent/conversation_loop.py +++ b/agent/conversation_loop.py @@ -5865,6 +5865,17 @@ def run_conversation( # Save session log incrementally (so progress is visible even if interrupted) agent._session_messages = messages + # Touch activity before continuing so the gateway's + # inactivity monitor never sees a stale timestamp + # between tool completion and the start of the next + # API call. Without this, a tool-call result (which + # takes ~0s to process) followed by slow post-tool + # processing (compression, persist) and a slow + # follow-up API call can exceed the gateway inactivity + # timeout (HERMES_AGENT_TIMEOUT, default 1800s) and the + # gateway kills the session before the next activity + # touch fires (#69559, #69131). + agent._touch_activity(f"tool results posted, continuing iteration #{api_call_count}") # Continue loop for next response continue