Description
The SDK's Horizon streaming connections silently stall when the underlying network changes (e.g. WiFi handoff, VPN reconnect) without closing the TCP connection cleanly, leaving the SSE stream appearing open but delivering no events. A health probe should send periodic heartbeat checks, detect stalled streams by measuring event interarrival time, and automatically tear down and reopen the stream connection when a stall is detected.
Technical Context
Add src/streamHealthProbe.ts. Monitors src/sse.ts and src/stream.ts connections. Tracks the timestamp of the last received event per stream ID. When Date.now() - lastEventAt > stalledThresholdMs (configurable, default 30 000), marks the stream as stalled and calls reconnect(). Emits streamStallDetected and streamAutoReset via src/events.ts. Integrates with src/health.ts.
Acceptance Criteria
Description
The SDK's Horizon streaming connections silently stall when the underlying network changes (e.g. WiFi handoff, VPN reconnect) without closing the TCP connection cleanly, leaving the SSE stream appearing open but delivering no events. A health probe should send periodic heartbeat checks, detect stalled streams by measuring event interarrival time, and automatically tear down and reopen the stream connection when a stall is detected.
Technical Context
Add
src/streamHealthProbe.ts. Monitorssrc/sse.tsandsrc/stream.tsconnections. Tracks the timestamp of the last received event per stream ID. WhenDate.now() - lastEventAt > stalledThresholdMs(configurable, default 30 000), marks the stream as stalled and callsreconnect(). EmitsstreamStallDetectedandstreamAutoResetviasrc/events.ts. Integrates withsrc/health.ts.Acceptance Criteria
StreamHealthProbe.attach(streamId, stream)begins monitoring event interarrival time for the given streamstalledThresholdMs, emitsstreamStallDetectedand invokes the registeredonStallcallbackautoReset: truecauses the probe to close the stalled stream and invoke the stream factory to create a replacementsrc/cursorTracker.tsstreamStallDetectedfires andonStallis called