Repository navigation
perf(website): stop polling the gateway from a hidden tab - #37549
Conversation
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff changes only how often five hidden-tab polls run. It adds or changes no control, label, string or rendered state, so the missing blind read leaves no evidence gap. [UX-REVIEWED] 728183d Description read[DESCRIPTION-READ] 1328407d9560be3b160a9e1fe2ddbbb144a58673d36dfd0febc2bdf22d5a226b That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change targets a real cost, the fix is small and easy to revert, and it removes nothing. Notes
[DESIGN-REVIEWED] 728183d Description read[DESCRIPTION-READ] 7b176c272d44390399abc9afa017ac7782473799fe83dde8f554b84254c87edc That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The helper is new, and every item is a timer swap that removes measured hidden-tab requests. The web-preview probe falls outside the frozen Goal, and the same pattern still runs at unfixed sites. Notes
What this change shipsInventory (7 items) — 5 justifiedIntent: a background Task Runner or Worlds tab stops loading the gateway and catches up when shown again. This is a FIX (perf).
[FIRST-PRINCIPLES-REVIEWED] 728183d Description read[DESCRIPTION-READ] 9889336589d166dd074f3b01bcde34ac750ebf9ee8a48c40806841f19fe1dcfa That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
|
Code change approver recommendation: ApproveWhy: the decider estimates an 8% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. The PR swaps five gateway-polling timers for a small helper, An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
…Worlds tab Five timers kept reading the gateway from a tab nobody was looking at: the Task Runner page (runs, every 3 s), the Worlds page and its popout (sessions and crons every 5 s, subagents every 3 s), the Worlds mini thread (every 2 s) and the web preview's liveness probe (every 5 s). pollWhileVisible (website/src/lib/pollWhileVisible.ts) repeats a tick only while document.visibilityState is not "hidden". When the page is shown again it ticks once at once and restarts the cadence. The five sites use it in place of their own setInterval or setTimeout chain. The first read on mount and the cadence while visible are unchanged. useAgentSync used a setTimeout chain that waited for each answer before arming the next read. It now ticks on an interval and skips a tick while the previous read of the same kind is still out, so a slow answer is still never overtaken.
6755609 to
728183d
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On this head the review read the full diff (8 files under website/src). It confirmed that pollWhileVisible starts no timer on a page that opens hidden, ticks once and starts one interval when the page is shown again, and removes its listener on stop. Planning on ProjectsPage still reads status directly, so a hidden tab does not stall an auto-run. The fake-timer tests restore real timers and never sleep. PR Readiness is green.
Done well: each helper test pins one branch, and the ProjectsPage test checks exact call counts through visible, hidden and shown-again phases.
Optional:
- useAgentSync now polls on a fixed interval with busy guards. Before, it waited for each answer and then scheduled the next read. So a visible Worlds page reads more often when the gateway is slow (a 2.5 s answer takes the gap from about 5.5 s to 3 s). You could gate only the re-arm on visibility, or change the body to say the visible cadence is now fixed-rate.
- The WebPreviewPanel change probes a dev-server URL on the chat side panel, not the gateway. That is outside the Goal's two pages, so you could drop that hunk.
- The new cronBusy/spawnBusy guards have no test. One fake-timer test with a pending api.crons promise would pin them. Separately,
documentVisiblein lib/pollRule.ts already covers the helper's inline visibility check.
Two changes landed on the built-in's page after the port base 33979525d8: - kirodotdev/KiroCrew#37549: the cron and subagent polls and the mini thread's 2-second refresh run only while the page is visible, tick once when it is shown again, and a cron or subagent read is skipped while the previous one is still out. - kirodotdev/KiroCrew#38097: the collapse toggle of the page and the pop-out draws a lucide chevron instead of a triangle glyph. PORTING.md lists both, and the committed bundle is rebuilt.
Problem / Motivation
Goal: A Task Runner or Worlds tab that nobody is looking at stops asking the gateway for data, and catches up the moment it is shown again.
Five timers kept reading the gateway from a hidden tab. In a stubbed dashboard, with the page told it is hidden, one minute of each page on main sends:
/projects)GET /api/taskrunnerevery 3 s)/worlds-popout)GET /api/spawnevery 3 s,GET /api/chat/slotsandGET /api/cronsevery 5 s)The chat page does not have this problem: it sends 0 requests while hidden, because its polls run through React Query, which pauses a hidden page.
Why it matters
People leave these pages open in a background tab for hours. Each such tab costs the gateway 20 to 44 requests a minute and wakes the tab's main thread for every answer, for a screen nobody sees. Each read also takes one of the browser's connections to the gateway.
Not a goal
useDashboardHealthProbe. It runs only while the gateway is unreachable, and a hidden tab still needs to reconnect.What changed (motivation → approach → change)
A hidden page shows nothing, so a read it makes is wasted.
pollWhileVisible(tick, ms)inwebsite/src/lib/pollWhileVisible.tsrepeatstickonly whiledocument.visibilityStateis nothidden. When the page is shown again it runstickonce at once and restarts the cadence from there.Five sites use it in place of their own timer:
website/src/pages/ProjectsPage.tsxwebsite/src/pages/WorldsPopout.tsxwebsite/src/hooks/useAgentSync.tswebsite/src/hooks/useSceneInteraction.tsxwebsite/src/components/WebPreviewPanel.tsxThe first read on mount and the cadence while visible are unchanged.
useAgentSyncused asetTimeoutchain that armed the next read after each answer. It now ticks on an interval and skips a tick while the previous read of the same kind is still out, so a slow answer is still never overtaken.Measurements
All numbers are mine, from one shared Linux host. The real built dashboard is served on 127.0.0.1;
/apiis answered byscripts/lib/stub-dashboard-api.mjs, and the websocket sends a status frame every 5 s as a live gateway does. Headless Chromium never reports a tab as hidden, so the page is told it is:document.visibilityStateanddocument.hiddenare overridden andvisibilitychangeis dispatched. The browser's own timer throttling for hidden tabs is therefore not part of these numbers. Each window is 60 s. The counts are requests that reached the server.Before: main @ 4c530d0. After: this head.
On return both pages read at once: Task Runner sends
GET /api/taskrunner, the popout sendsGET /api/crons,GET /api/spawnandGET /api/chat/slotswithin the first second. Both pages rendered before counting (the Task Runner header and empty state, the popout's scene tabs), with no page error.Not measured in a browser: the Worlds mini thread and the web preview probe (covered by the helper's unit test only), the embedded Worlds page (it shares
useAgentSyncwith the popout), main-thread time (the two runs were taken at different host load), and a real hidden tab with the browser's timer throttling.Backwards compatibility
Compatible: a visible page reads on the same cadence as before, and a page that comes back reads at once, so no screen shows older data than it did.
Removes nothing: no read, key or function is removed; a hidden page only stops repeating reads it would throw away.
Tests
website/src/lib/pollWhileVisible.test.ts: ticks on the cadence while visible and leaves the first tick to the caller; no tick and no timer while hidden; one tick at once on return, then the cadence from there; a page that opens hidden starts when first shown; a repeated visibility event adds no tick and no timer; stop clears the timer and the listener.website/src/test/ProjectsPage.test.tsx: the Task Runner page reads its runs every 3 s, sends nothing for 60 s while hidden, reads once when shown again and resumes.vitest runon those two files plus theWorldsPopout,useAgentSync*,UseSceneInteractionCoverageandWebPreviewPanelsuites (10 files, 274 tests, all pass);tsc -p tsconfig.app.jsonclean; eslint on the changed files clean; comment-history, brand and line-cap gates pass.Manual verification
The request counts above, taken from the built dashboard in Chromium before and after. Not verified by hand: the web preview panel with a dev server that stops while the tab is hidden.
Screenshots / video
Why no screenshot: only timers change; a visible page renders and reads exactly as before.
Related Issues
N/A. Found in the Chrome modern-web-guidance review of the dashboard (efficient-background-processing).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.