feat(dashboard): live anomaly badge — background poll every 30s#154
Merged
Conversation
surpradhan
commented
Jun 26, 2026
surpradhan
left a comment
Owner
Author
There was a problem hiding this comment.
R1 findings (all addressed in 21ce12e): (1) poll kept running after 401 → now clears interval on Unauthorized; (2) badge queried different range than panel → now reads shared-since/shared-until via toIso(); (3) poll fired while tab hidden → early return on document.hidden; (4) duplicate banner line + bare fire-and-forget call → fixed (void keyword). R2: both reviewers approve, zero actionable items. 243/243, lint clean. Approve.
Start a 30-second poll after initial page load that fetches GET /analytics/anomalies and keeps the anomalies-badge count and pdot-analyze alert dot current without requiring a tab visit. - refreshAnomalyBadge(): fetches the count, updates badge + dot; if the user is already on the Anomalies tab it delegates to renderAnomalies() for a full refresh instead - startAnomalyPoll(): clears any prior interval, fires an immediate fetch, then schedules repeats at ANOMALY_POLL_MS (30s) - Wired into loadAll() after first successful data fetch so the poll only starts once the user is authenticated - Respects the current sensitivity threshold (ad-threshold) input so the badge reflects the same cutoff the user configured - Errors silenced — badge stays stale rather than flashing on transient network hiccups
- Stop poll on 401: clearInterval when fetchJson throws Unauthorized so a re-auth page stop issuing background requests; poll restarts via startAnomalyPoll() on the next successful loadAll() - Include shared-since/shared-until in the badge query so the count matches the same filter set the Anomalies panel uses; prevents badge showing a different number than the panel when date filters are active - Skip tick when document.hidden to avoid background network requests while the tab is backgrounded or screen is locked - Remove duplicate separator banner line before the block comment - Use void refreshAnomalyBadge() in startAnomalyPoll() to mark the intentional fire-and-forget clearly
21ce12e to
bb2d1be
Compare
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.
What does this PR do?
Keeps the anomaly badge and Analyze nav dot current without requiring the user to visit the Anomalies sub-tab. A 30-second background poll fetches the anomaly count after page load and updates the UI silently.
Changes
src/public/dashboard.htmlonly — no backend changesANOMALY_POLL_MS = 30_000constantrefreshAnomalyBadge()— fetchesGET /analytics/anomalies(with current threshold if set); if the user is already on the Anomalies tab it callsrenderAnomalies()for a full refresh, otherwise updates only the badge count andpdot-analyzedotstartAnomalyPoll()— clears any prior interval, fires an immediate fetch, then schedules repeatsloadAll()after first successful data fetch (authenticated path only)How to test
Checklist
Part of UX polish sprint (PR-D of 4, stacked on PR-C)