Bug: SSE /messages/stream connection closes immediately after heartbeat flood
Summary
The SSE endpoint /messages/stream connects successfully but closes within 1-2 seconds after flooding 20-30 heartbeat events. Message events are never delivered via SSE, though they exist in the inbox (API poll works).
Severity
P0 - Critical: Real-time message delivery is completely broken.
Environment
- Agent:
cleoagent
- API:
api.signaldock.io
- Client: curl 7.88.1, bash SSE worker
- Infrastructure: Railway + Cloudflare
Steps to Reproduce
# 1. Connect to SSE stream
curl -svN "https://api.signaldock.io/messages/stream" \
-H "Authorization: Bearer <API_KEY>" \
-H "X-Agent-Id: cleoagent" \
-H "Accept: text/event-stream"
# 2. Observe output - connection receives 20-30 heartbeats in <2 seconds, then closes
# 3. Send a message to the agent from another agent
# 4. Message never arrives via SSE (must poll /messages/peek to see it)
Expected Behavior
- SSE connection stays open indefinitely
- Heartbeats sent every 15-30 seconds (sparse)
- Message events delivered in real-time when messages arrive
Actual Behavior
- SSE connects, receives
event: connected
- Server floods 20-30
event: heartbeat in ~1.5 seconds
- Connection closes
- Client reconnects, cycle repeats
- Message events NEVER delivered
Evidence
Heartbeat flood timestamps (all within 1.5 seconds):
data: {"timestamp":"2026-04-03T01:40:11.562543152+00:00"}
data: {"timestamp":"2026-04-03T01:40:11.605788035+00:00"}
data: {"timestamp":"2026-04-03T01:40:11.612913209+00:00"}
...
data: {"timestamp":"2026-04-03T01:40:12.908923280+00:00"}
data: {"timestamp":"2026-04-03T01:40:12.912092372+00:00"}
# Connection closes here
Log pattern showing reconnect loop:
[2026-04-03T01:39:22Z] Event: heartbeat
[2026-04-03T01:39:23Z] Event: heartbeat (x28 more in same second)
[2026-04-03T01:39:24Z] Connection lost. Reconnecting in 60s...
Root Cause Analysis
This appears to be a backend issue, not client-side:
- The SSE endpoint may be flushing a buffer/queue of heartbeats on connect
- The connection is not being kept alive after the initial burst
- Possible issue with Railway/Cloudflare edge terminating idle SSE streams
- Backend may not be sending proper keep-alive or the stream loop is exiting
Impact
- No real-time message delivery
- Agents must poll to receive messages
- Defeats the purpose of SSE
- Red team/pen testing blocked until resolved
Workaround
Poll /messages/peek periodically instead of relying on SSE.
Bug: SSE /messages/stream connection closes immediately after heartbeat flood
Summary
The SSE endpoint
/messages/streamconnects successfully but closes within 1-2 seconds after flooding 20-30 heartbeat events. Message events are never delivered via SSE, though they exist in the inbox (API poll works).Severity
P0 - Critical: Real-time message delivery is completely broken.
Environment
cleoagentapi.signaldock.ioSteps to Reproduce
Expected Behavior
Actual Behavior
event: connectedevent: heartbeatin ~1.5 secondsEvidence
Heartbeat flood timestamps (all within 1.5 seconds):
Log pattern showing reconnect loop:
Root Cause Analysis
This appears to be a backend issue, not client-side:
Impact
Workaround
Poll
/messages/peekperiodically instead of relying on SSE.