Dashboard app: extract stats orchestration into stats-controller module #76
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
app.jsowns status polling, stats polling, view show/hide, visibility handling, tab routing, auth bootstrap, and the stats-render token bookkeeping. PR5 added a five-variable mini state machine (statsTimer,statsActiveSessionId,statsPanelVisible,statsRenderToken,pendingStatsToken) plus eight mutation sites and arequestAnimationFrame-aware lifecycle. The module-level mutability was the proximate cause of two recent polling-lifecycle bugs — auth-submit and 401 handler both failed to invalidate the in-flight stats render.Source: PR5 multi-agent code review (Code quality & maintainability dimension)
File:
crates/cognix-server/assets/app.jsBranch:
phase-8/dashboard-ui-pr5-statsMotivation
Encapsulating stats orchestration in a
StatsControllerclosure (or class) co-locates the token-cancellation invariant with the state it protects. New polling callers — a future Improve tab, a metrics overlay — would consume the controller instead of bolting more module-level mutables alongside the existing five. The recent lifecycle fixes establish the right behavior; extracting now prevents the next caller from re-introducing the same class of bug.Why deferred from PR5
The refactor would touch every site PR5 patched for the auth-submit, 401, visibility, pageshow, and session-change handlers. Landing it in the same PR that introduced those fixes is high-blast-radius — the fixes need a release cycle of soak time against the existing structure before the structure changes underneath them.
Proposed work
crates/cognix-server/assets/stats-controller.jsexportingcreateStatsController({ getMount, getSessionId, pollMs })that ownsstatsTimer,pendingStatsToken,statsRenderToken, in-flight gating, and visibility/pageshow listeners.app.jswith a singleconst statsController = createStatsController(...)and forward the five lifecycle hooks (auth-submit, 401, visibility, pageshow, session-change) to controller methods (invalidate,start,stop).crates/cognix-server/src/transport/ui/tests/assets.rsNode contract test only if it asserts on the old function names; otherwise leave it asserting behavior, not structure.crates/cognix-server/src/transport/ui/assets.rs.Acceptance
app.jscontains zerolet stats*module-level declarations.e2e/dashboard/stats.spec.tspass with no test edits.transport/ui/tests/assets.rspasses.References
app.jsfrom PR5: auth-submit invalidation, 401 stop+invalidate, pageshow listener,runStatsRenderdrop-warning