Skip to content

Horizon Streaming Health Probe with Auto-Reset #536

Description

@Kingsman-99

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

  • StreamHealthProbe.attach(streamId, stream) begins monitoring event interarrival time for the given stream
  • When no event is received within stalledThresholdMs, emits streamStallDetected and invokes the registered onStall callback
  • autoReset: true causes the probe to close the stalled stream and invoke the stream factory to create a replacement
  • After auto-reset, resumes from the last persisted cursor via src/cursorTracker.ts
  • Unit tests simulate a stalled stream (no events for > threshold) and assert streamStallDetected fires and onStall is called
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions