🤖 fix: self-heal stale chat subscriptions after sleep/wake #1356
+363
−23
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.
Problem
In mux server mode (browser UI), after idle time or sleep/wake, the chat UI can stop reflecting live stream state:
Root Cause
The transcript is not updated optimistically on send; it updates only via the streaming subscription
workspace.onChat. Any failure where the async iterator stalls without ending/throwing produces exactly this UX: the RPC send succeeds, but the UI never receives thetype:"message"/ stream events that drive the transcript.Solution
1. connectionEpoch tracking
APIProviderincrements aconnectionEpochon each new connection.WorkspaceStorerestarts all subscriptions when the epoch changes, preventing stale iterators from the old connection.2. Subscription watchdog
Monitors all chat subscriptions and auto-restarts them if:
caught-upreceived within 15s (buffering stall)3. UI feedback
New
SubscriptionStatusIndicatorshows "Reconnecting chat stream…" when a subscription is being restarted, so users know recovery is in progress.4. Diagnostics
Added logging for WS close events (code/reason) and ping failures to help debug future connection issues.
Testing
make static-checkpassesGenerated with
mux• Model:anthropic:claude-opus-4-5• Thinking:high