Emit heartbeats for long-running tool calls#733
Open
ilteris wants to merge 2 commits into
Open
Conversation
A tool_use only stops its heartbeat when the matching tool_result arrives. If a tool_use ends without one — turn cancelled, stream aborted, session torn down — the setInterval and its Map entry leak for the lifetime of the process. Add clearToolCallHeartbeatsForSession and call it from the prompt turn-end, cancel(), and (via cancel) teardown paths. Add a leak regression test and move the heartbeat tests into a dedicated describe block with their own fake-timer cleanup.
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.
Why
ACP clients commonly use tool lifecycle updates as the only observable liveness signal for an in-flight tool call. Between the initial
tool_calland the terminaltool_resultupdate, the bridge emits nothing — so a client cannot distinguish a healthy quiet tool from a wedged bridge or a dropped/delayed terminal update. In practice this trips client-side stall watchdogs and cancels a turn even though Claude is still working.This is fundamentally a transport-liveness gap, not a claim that any specific tool is slow. The heartbeat keeps the existing tool row alive without adding user-visible output or fake progress text, so a quiet-but-healthy tool is no longer indistinguishable from a hang.
Summary
tool_call.tool_call_updatenotifications (every 60s) while a tool remains pending.tool_resultarrives.tool_usecan terminate with notool_result— turn cancelled, stream aborted, or session torn down.clearToolCallHeartbeatsForSessionsweeps a session's timers, and is called from the prompt turn-end,cancel(), and (viacancel) teardown paths so an unresolved tool can't leak its interval for the lifetime of the process.Tests
tool_resultlands.clearToolCallHeartbeatsForSession, advancing timers past several intervals produces no further beats.describeblock with isolated fake-timer cleanup.Verification
npm test -- --run(301 passed)npm run buildnpm run check