fix(sse): tune broadcast capacity and recover lagged subscribers #58

Closed
rawdaGastan wants to merge 0 commits from development_sse_buffer_resync into development
Member

Summary

Makes the SSE broadcast channel capacity tunable and stops the dashboard from silently going stale when a subscriber falls behind.

Closes #51

Changes

  • crates/hero_router/src/config.rs: new env var ROUTER_SSE_BUFFER (default 1024, must be > 0); new RouterConfig.sse_buffer field and .sse_buffer(usize) builder; tests extended.
  • crates/hero_router/src/main.rs: SseBroadcaster::new(64) -> SseBroadcaster::new(cfg.sse_buffer).
  • crates/hero_router/src/server/sse.rs: doc comment on SseBroadcaster::new documents the env var, the lagged-subscriber semantics, and the resync recovery path.
  • crates/hero_router/src/server/routes.rs: sse_handler no longer silently drops Err(_) via .ok(). BroadcastStreamRecvError::Lagged(n) now emits tracing::warn! and yields event: resync\ndata: {"dropped":n}\n\n. Closed channel still terminates the stream cleanly.
  • crates/hero_router/static/js/dashboard.js: initSSE() registers a resync listener that logs the drop count and calls the existing idempotent reloadSidebar().

Test Results

cargo test -p hero_router -- 71 passed, 0 failed. cargo build -p hero_router clean.

Notes

  • 1024 is 16x the previous capacity; each slot is one short SSE-frame String, so worst-case memory is well under a MiB.
  • BroadcastStreamRecvError currently has only Lagged(u64) in tokio-stream 0.1; closed channels are signalled by None from the stream wrapper. Match is exhaustive today; future variants will surface as a compile error -- intentional.
## Summary Makes the SSE broadcast channel capacity tunable and stops the dashboard from silently going stale when a subscriber falls behind. ## Related Issue Closes https://forge.ourworld.tf/lhumina_code/hero_router/issues/51 ## Changes - `crates/hero_router/src/config.rs`: new env var `ROUTER_SSE_BUFFER` (default 1024, must be > 0); new `RouterConfig.sse_buffer` field and `.sse_buffer(usize)` builder; tests extended. - `crates/hero_router/src/main.rs`: `SseBroadcaster::new(64)` -> `SseBroadcaster::new(cfg.sse_buffer)`. - `crates/hero_router/src/server/sse.rs`: doc comment on `SseBroadcaster::new` documents the env var, the lagged-subscriber semantics, and the `resync` recovery path. - `crates/hero_router/src/server/routes.rs`: `sse_handler` no longer silently drops `Err(_)` via `.ok()`. `BroadcastStreamRecvError::Lagged(n)` now emits `tracing::warn!` and yields `event: resync\ndata: {"dropped":n}\n\n`. Closed channel still terminates the stream cleanly. - `crates/hero_router/static/js/dashboard.js`: `initSSE()` registers a `resync` listener that logs the drop count and calls the existing idempotent `reloadSidebar()`. ## Test Results `cargo test -p hero_router` -- 71 passed, 0 failed. `cargo build -p hero_router` clean. ## Notes - 1024 is 16x the previous capacity; each slot is one short SSE-frame `String`, so worst-case memory is well under a MiB. - `BroadcastStreamRecvError` currently has only `Lagged(u64)` in `tokio-stream 0.1`; closed channels are signalled by `None` from the stream wrapper. Match is exhaustive today; future variants will surface as a compile error -- intentional.
fix(sse): tune broadcast capacity and recover lagged subscribers
All checks were successful
Build & Test / check (push) Successful in 1m49s
Build & Test / check (pull_request) Successful in 2m27s
8429b12cc1
Replace the hard-coded 64-slot SSE broadcast channel with a tunable
capacity (env var ROUTER_SSE_BUFFER, default 1024) and stop silently
dropping receiver errors. Lagged subscribers now receive an explicit
`resync` SSE event with the dropped-event count; the dashboard listens
for it and reloads the sidebar so the UI re-syncs to authoritative
state instead of showing stale data after a burst of scan events.

#51
despiegk closed this pull request 2026-04-28 01:58:56 +00:00
All checks were successful
Build & Test / check (push) Successful in 1m49s
Build & Test / check (pull_request) Successful in 2m27s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_router!58
No description provided.