🤖 fix: add heartbeat pattern to onChat for reliable stall detection #1909
+27
−11
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
Adds a heartbeat pattern to the
onChatsubscription to reliably distinguish dead connections from intentionally idle streams during long operations.Background
The previous stall detection used a 60s timeout while checking if a stream was active. This caused false positives during long tool operations (bash with 5+ min timeout, subagent calls) where it's normal to have no events for extended periods. The retry would call
resetChatStateForReplay()which clears the aggregator and triggers a full UI repaint—noticeable and disruptive to users.Implementation
heartbeatevent every 5s unconditionally in theonChathandlerNow if 10s pass with no events (including heartbeats), the connection is genuinely dead → resubscribe. Long operations no longer trigger false stalls since heartbeats keep flowing.
Generated with
mux• Model:anthropic:claude-opus-4-5• Thinking:high• Cost:$1.30