broadcast_sse_event is never called — live event timeline is dead #1

Closed
opened 2026-04-05 14:49:22 +00:00 by alee · 0 comments
Owner

Severity: bug (feature gap masquerading as a feature)
Files: vigilar/web/blueprints/events.py, vigilar/web/static/js/app.js, vigilar/web/templates/kiosk/ambient.html

The frontend subscribes to /events/stream via EventSource from both app.js:59 and kiosk/ambient.html:445. The server-side /stream endpoint (events.py:69) correctly hands out a queue.Queue per client and drains it to the SSE stream. However, broadcast_sse_event (events.py:18) is never called anywhere in the codebase — no producer ever pushes events into the subscriber queues. Clients receive only the initial {"type": "connected"} message and periodic keepalives; the event timeline never updates live. A page refresh is required to see new events.

Phone push via VAPID works independently and is unaffected.

Root cause: Flask runs in its own process. The events subsystem emits to MQTT (vigilar/events/*), but nothing in the Flask app subscribes to those topics to forward them into broadcast_sse_event.

Fix sketch:

  • In the Flask app factory, spin up a background thread that connects to MQTT, subscribes to the relevant event topics, and calls broadcast_sse_event(payload) on each message.
  • Ensure graceful shutdown (join the thread, disconnect the bus) on app teardown.
  • Add a test that publishes an event to MQTT and asserts an SSE client receives it.

Alternative: delete broadcast_sse_event, the /stream endpoint, and the client-side EventSource usage, and document that timeline updates require a refresh.

**Severity:** bug (feature gap masquerading as a feature) **Files:** `vigilar/web/blueprints/events.py`, `vigilar/web/static/js/app.js`, `vigilar/web/templates/kiosk/ambient.html` The frontend subscribes to `/events/stream` via `EventSource` from both `app.js:59` and `kiosk/ambient.html:445`. The server-side `/stream` endpoint (`events.py:69`) correctly hands out a `queue.Queue` per client and drains it to the SSE stream. However, **`broadcast_sse_event` (`events.py:18`) is never called anywhere in the codebase** — no producer ever pushes events into the subscriber queues. Clients receive only the initial `{"type": "connected"}` message and periodic keepalives; the event timeline never updates live. A page refresh is required to see new events. Phone push via VAPID works independently and is unaffected. **Root cause:** Flask runs in its own process. The events subsystem emits to MQTT (`vigilar/events/*`), but nothing in the Flask app subscribes to those topics to forward them into `broadcast_sse_event`. **Fix sketch:** - In the Flask app factory, spin up a background thread that connects to MQTT, subscribes to the relevant event topics, and calls `broadcast_sse_event(payload)` on each message. - Ensure graceful shutdown (join the thread, disconnect the bus) on app teardown. - Add a test that publishes an event to MQTT and asserts an SSE client receives it. **Alternative:** delete `broadcast_sse_event`, the `/stream` endpoint, and the client-side `EventSource` usage, and document that timeline updates require a refresh.
alee closed this issue 2026-04-05 16:55:27 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alee/vigilar#1