feat(sse): harden SSE and replace polling with push - #362
Merged
Conversation
Rewrites the main SSE events endpoint to use actix_web_lab::sse::Sse with with_keep_alive(30s), matching the pattern already used by the log stream handlers. Prevents proxies and load balancers from closing idle SSE connections.
Adds an AtomicUsize counter to AppState that tracks active SSE event stream connections. New connections are rejected with 429 when at the cap. A drop guard ensures the counter decrements when the stream task ends (client disconnect or channel close). Prevents runaway browser tabs from exhausting server resources. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dashboard, headless, and integrity progress templates were polling the server at 1-15s intervals even though the SSE infrastructure already broadcasts events for the exact state changes they care about. Switch each to use its matching sse:* trigger with a long (30-60s) fallback poll for resilience. Removes the redundant hand-rolled EventSource script in headless.html since the HTMX SSE extension (wired globally in base.html) now handles it natively via the sse:headlessChanged trigger. Kept polling where it's the right pattern: operation tracking (transient element, no per-op event), stash (external profile data, no event), and proxy metrics (high-frequency counters, pushing would be worse). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sse:*event with a long (30-60s) fallback poll for resilienceKept polling where it's the right pattern: operation tracking (transient element, no per-op event), stash (external profile data, no event), and proxy metrics (high-frequency counters).
Test plan
Implemented with the help of Claude Code