Skip to content

fix(tools): refresh activity heartbeat while a tool call is in flight (salvage #84522) - #86646

Merged
teknium1 merged 2 commits into
mainfrom
fix/tool-activity-heartbeat
Aug 15, 2026
Merged

fix(tools): refresh activity heartbeat while a tool call is in flight (salvage #84522)#86646
teknium1 merged 2 commits into
mainfrom
fix/tool-activity-heartbeat

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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 once seconds_since_activity exceeds 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 at executing tool: X and 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 reporting last_activity=executing tool: terminal.

Changes

  • agent/tool_executor.py: a daemon-thread heartbeat inside _run_agent_tool_execution_middleware refreshes agent._touch_activity every 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 in try/finally (always tears down, even when execute() raises); never started when a guardrail/authorization block short-circuits before dispatch.
  • A genuinely hung tool stays bounded by the tool layer's own deadlines (terminal timeout, concurrent batch deadline, and the new timeouts.tools.sequential_call bound 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.
  • No new config or env vars; constant 30s cadence stays far below the 1800s watchdog.

Verification

  • tests/run_agent/test_tool_activity_heartbeat.py: 5 passed (heartbeat cadence, stop-on-return, stop-on-raise, guardrail short-circuit, concurrent path).
  • Sabotage run: reverting agent/tool_executor.py to main with the tests kept → 5 failed, proving the regression tests bite.

Infographic

tool-heartbeat

Ufonik88 and others added 2 commits August 14, 2026 20:52
…#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.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Aug 15, 2026
@github-actions

github-actions Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

running on e23a1fe — chore: contributor mapping for Ufonik88


Still running 1 job: CI timing report

⚠️ Warnings

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.

@teknium1
teknium1 merged commit 1d95888 into main Aug 15, 2026
47 checks passed
@teknium1
teknium1 deleted the fix/tool-activity-heartbeat branch August 15, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway turn-inactivity watchdog abandons turns whose tool call runs silently >30 min

3 participants