Skip to content

Fix: SSE events not visualized in standalone mode #35

@matiasdiaz21

Description

@matiasdiaz21

Problem

Agent Flow's visualizer fails to display real-time agent events when running
in standalone mode (pnpm run dev). Events are transmitted from the relay
server to the browser via Server-Sent Events (SSE), but are never visualized
on the canvas or processed by the simulation engine.

Symptoms

  • Browser console shows: [SSE] Connected to relay
  • Browser console shows: [SSE] Received message: agent-event
  • Browser displays: WAITING FOR AGENT SESSION (no agents rendered)
  • Events are buffered in sessionEventsRef but never delivered to simulation

Root Causes

  1. Unreliable PostMessage Pattern: Original code in use-vscode-bridge.ts
    attempts to route SSE messages through window.postMessage(), which doesn't
    reliably trigger message handlers in same-origin contexts. The VSCodeBridge's
    message handler is designed for cross-origin postMessage (VS Code extension ↔
    webview), not self-messaging.

  2. Missing Session Auto-Selection: When SSE events arrive before a session
    is selected (selectedSessionIdRef.current === null), they are routed to
    "background activity" instead of pendingEventsRef, preventing the simulation
    engine from ever receiving them.

Expected Behavior

  • SSE events should be processed directly in the hook
  • Session should auto-select on first event
  • Canvas should display agent and update in real-time
  • Timeline should populate with events

Steps to Reproduce

  1. Start relay: pnpm run dev
  2. Run Claude Code session: claude code "list files"
  3. Observe: Browser shows "WAITING FOR AGENT SESSION" instead of visualization

Impact

Standalone mode is completely non-functional without this fix.

For detailed technical analysis, see the related pull request and
FEAT_SSE_EVENT_PROCESSING.md documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions