Skip to content

feat: Redis Streams event bus for reliable WebSocket delivery (RELIABILITY-003) #306

Closed

Description

@vybe

Summary

The current WebSocket broadcast in main.py uses in-process iteration with bare except: pass error handling. At scale (30+ agents, 50+ WebSocket connections), clients silently miss critical events — collaboration updates, health alerts, execution status changes — with no way to recover missed messages on reconnect.

Solution

Replace the in-process broadcast with Redis Streams as the event bus. Redis is already running. Streams provide:

  • Persistent event log with configurable retention (e.g., last 1000 events or 1 hour)
  • Replay on reconnect via XRANGE — clients that disconnect and reconnect get missed events
  • Consumer groups for at-least-once delivery semantics
  • Built-in backpressure via BLOCK parameter on XREAD

Scope

  • Replace ConnectionManager.broadcast() with Redis Stream publish (XADD)
  • Each WebSocket connection reads from Redis Stream (XREAD BLOCK)
  • Track per-client last-seen event ID; on reconnect, replay from that point
  • Add stream trimming (MAXLEN ~10000 or time-based) to prevent unbounded growth
  • Replace FilteredWebSocketManager broadcast with stream consumer that filters by user permissions
  • Remove except: pass pattern — errors now tracked per-client with eviction after N failures

Acceptance Criteria

  • All real-time events (agent_activity, agent_collaboration, process events, health) flow through Redis Streams
  • WebSocket clients that disconnect and reconnect receive missed events (up to retention window)
  • Failed sends to a client are logged and client is evicted after 3 consecutive failures
  • Stream auto-trims to prevent unbounded Redis memory growth
  • Existing WebSocket event format unchanged (backward compatible for frontend)
  • ~100 lines to replace ConnectionManager, zero new infrastructure

Key Files

  • src/backend/main.py — replace ConnectionManager and FilteredWebSocketManager
  • src/backend/services/activity_service.py — publish to stream instead of direct broadcast
  • src/frontend/src/utils/websocket.js — send last-event-ID on reconnect

Dependencies

None — Redis already running.

Activity

  1. added
    priority-p1
    type-feature
    on Apr 11, 2026
  2. vybe commented on Apr 20, 2026

    @vybe
    ContributorAuthor

    Promoted to next priority (2026-04-20)

    Per orchestration simplification re-plan — this is the keystone that unlocks Tier 2.5:

    • Dissolves bug: long-running backend→agent task calls dropped when uvicorn worker recycles #408 (long-running backend→agent HTTP call gets replaced by push completion; no FaF+polling layer needed)
    • Unblocks CAPACITY-CONSOLIDATE (state transitions move to event consumer, which simplifies the drain logic before the three queue classes are merged)
    • Unblocks CLEANUP-COLLAPSE (agent becomes authoritative for "is this running?"; most of the 9-path watchdog pyramid retires after a 2-week soak)

    See docs/planning/ORCHESTRATION_RELIABILITY_2026-04.md — Tier 2.5.

    Scope reminder

    • XADD / XREAD with reconnect replay
    • Frontend lastEventId support
    • Stream trim via MAXLEN ~10000
    • WebSocket event shape unchanged (additive)
    • Push ships alongside existing HTTP path initially — opt-in per agent until proven

    After landing

    Gate CLEANUP-COLLAPSE on "#306 in prod ≥2 weeks, zero orphan recoveries observed."

  3. added
    status-in-progress
    on Apr 20, 2026
  4. self-assigned this
    on Apr 20, 2026
  5. added
    complexity-medium
    theme-reliability
    type-epic
    on Jun 3, 2026
  6. removed
    status-in-progress
    on Aug 7, 2026
  7. added a commit that references this issue on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-mediumpriority-p1theme-reliabilitytype-epictype-feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions