Skip to content

Add SSE heartbeat, polling fallback, and --poll flag#5

Merged
cmer merged 1 commit intomainfrom
cmer/sse-heartbeat-polling
Mar 8, 2026
Merged

Add SSE heartbeat, polling fallback, and --poll flag#5
cmer merged 1 commit intomainfrom
cmer/sse-heartbeat-polling

Conversation

@cmer
Copy link
Owner

@cmer cmer commented Mar 7, 2026

Summary

Adds reliable real-time dashboard updates even through problematic proxies like Cloudflare Quick Tunnels:

  • Server sends SSE heartbeats every 5s to prevent proxy idle timeouts
  • Client monitors heartbeats and falls back to polling if none arrive within 7.5s
  • Polling intelligently adapts: 1s when tab is visible, 5s when hidden
  • Auto-detects Cloudflare (.trycloudflare.com) and forces polling from the start
  • New --poll CLI flag to force polling mode for known SSE-incompatible environments
  • Connection mode displayed as tooltip: "Connected via SSE" or "Connected via polling"

Technical Details

  • API endpoints have Cache-Control: no-store to prevent proxy caching of stale responses
  • Named SSE events (event: heartbeat) are used so client can detect liveness
  • Reconnection attempts every 5s when SSE fails
  • Browser visibility API used to reduce server load when tab is backgrounded
  • Comprehensive test suite verifies heartbeat timing and format

All existing tests pass; 3 new heartbeat tests added.

🤖 Generated with Claude Code

…dates

- Server sends SSE heartbeats every 5s to keep connections alive through proxies
- Client monitors heartbeats; falls back to polling if none arrive within 7.5s
- Polling updates every 1s when tab is visible, 5s when hidden (visibility API)
- Auto-detect Cloudflare Quick Tunnel (.trycloudflare.com) and force polling
- Add --poll CLI flag to force polling mode (useful for known SSE-broken proxies)
- Tooltip shows connection mode: "Connected via SSE" or "Connected via polling"
- API responses have Cache-Control: no-store to prevent proxy caching
- Heartbeat tests verify timing and SSE format
- All existing tests pass

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@cmer cmer merged commit b9e749b into main Mar 8, 2026
3 checks passed
@cmer cmer deleted the cmer/sse-heartbeat-polling branch March 8, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant