fix(tools): refresh activity heartbeat while a tool call is in flight (salvage #84522) - #86646
Merged
Conversation
…#84491) The gateway turn-inactivity watchdog (gateway/run.py::_watch_gateway_turn_inactivity) abandons a turn once seconds_since_activity exceeds the inactivity timeout (default 30 min). Activity was only stamped when a tool started and when it completed, so a tool call that runs silently for 30+ minutes (quiet builds, long pytest suites, large downloads, network waits with no output) froze the clock and the watchdog hard-abandoned a turn that was still making progress, reaping the tool's processes mid-execution (issue #84491). Add a daemon-thread heartbeat inside _run_agent_tool_execution_middleware that touches agent._touch_activity every 30s while the tool is in flight, until the call returns. Both the sequential and concurrent execution paths funnel through this single middleware, so one heartbeat covers every tool. The thread is stopped in a try/finally so it always tears down even if execute() raises, and is never started when a guardrail/authorization block short-circuits before dispatch. A genuinely hung tool remains bounded by the tool layer's own timeouts (terminal default 180s, concurrent batch deadline ~420s), so the heartbeat only extends the turn's life while the call is legitimately running. Verified by an independent reviewer (no security/logic defects); 5 unit/integration tests pass on Python 3.12 (upstream CI). The 30-min gateway backstop remains for turns whose agent loop itself stalls.
Contributor
૮ >ﻌ< ა ci reviewrunning on e23a1fe — chore: contributor mapping for Ufonik88 Still running 1 job:
|
This was referenced Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvage of #84522 by @Ufonik88 (first-time contributor — authorship preserved via cherry-pick), fixes #84491.
The gateway turn-inactivity watchdog (
gateway/run.py::_watch_gateway_turn_inactivity, default 1800s) abandons a turn onceseconds_since_activityexceeds the timeout. Activity was only stamped when a tool started and completed, so a tool call running silently for 30+ minutes (quiet builds, long pytest suites, large downloads) froze the clock atexecuting tool: Xand the watchdog hard-abandoned a turn that was still making real progress, reaping the tool's processes mid-execution — the live log in #84491 shows the watchdog abandoning a turn while itself reportinglast_activity=executing tool: terminal.Changes
agent/tool_executor.py: a daemon-thread heartbeat inside_run_agent_tool_execution_middlewarerefreshesagent._touch_activityevery 30s while a tool call is in flight. Both the sequential and concurrent paths funnel through this middleware, so one heartbeat covers every tool. Stopped intry/finally(always tears down, even whenexecute()raises); never started when a guardrail/authorization block short-circuits before dispatch.timeouts.tools.sequential_callbound from fix(agent): bound sequential tool calls — salvage #84795 + timeouts.tools.sequential_call (#85125 2a) #86311) — the heartbeat only keeps a legitimately running call alive; the 30-min gateway backstop remains for turns whose agent loop itself stalls.Verification
tests/run_agent/test_tool_activity_heartbeat.py: 5 passed (heartbeat cadence, stop-on-return, stop-on-raise, guardrail short-circuit, concurrent path).agent/tool_executor.pyto main with the tests kept → 5 failed, proving the regression tests bite.Infographic