fix(web): wait for usage refresh completion - #5825
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 12e19a4 This is a well-structured bug fix that properly handles usage refresh state transitions, ensuring the UI waits for refresh completion rather than showing stale data. The changes are self-contained with comprehensive test coverage (157 lines of tests) and don't touch sensitive code paths. You can customize Macroscope's approvability policy. Learn more. |
What Changed
AsyncResult, so retries, terminal failures, and reconnects settle consistently.Why
The usage page intentionally waits for every environment before revealing totals, because rendering each response progressively makes every number jump. During a manual refresh, however, SWR retains the old summary; the previous state derivation counted that stale value as a current answer, so the old dashboard could remain visible with no scan indication. A failed refresh with a previous success could also leak that stale summary, while some terminal connection states could leave the gate pending.
This preserves the established loading decision and fixes the refresh-generation issues identified in review thread 1 and review thread 2.
Verification:
vp test run src/state/usageStatus.test.ts --project unit— 7 passedvp lintandvp fmt --checkon the four touched filesvp run --filter @t3tools/web typecheckgit diff upstream/main...HEAD --checkUI Changes
Captured against the same local, synthetic two-environment fixture. Alpha finishes in about 0.9s; Beta finishes in about 3.5s.
Watch the complete refresh settle from loaded → both scanning → one complete → fully loaded
Checklist
Built with GPT-5.6 Sol via the Codex harness in T3 Code.
Note
Fix usage refresh completion detection to wait for in-flight refreshes
deriveEnvironmentUsageStatusandderiveUsageSettlingStatein usageStatus.ts to centralize per-environment and page-level pending/partial state logic.isPending/error/summarynow accounts for transport connection phase (including transitions and terminal states), not just the SWRAsyncResultstate.UsageDeviceStripcomponent in UsagePage.tsx now shows a check only when the environment is non-pending with a summary, and shows an error immediately whenenvironment.erroris set.isPendingandisPartialflags now require non-pending answers before settling, so a refresh retaining a previous summary no longer prematurely marks the request as complete.Macroscope summarized 12e19a4.
Note
Low Risk
Focused web usage UI/state change with new unit tests; no auth, security, or data-pipeline impact.
Overview
Fixes the usage page treating stale SWR summaries as finished answers during a manual refresh, which could leave old totals visible with no scan indication.
Centralizes status logic in new
usageStatus.ts:deriveEnvironmentUsageStatuscombines connection phase (connecting/reconnecting vs terminal offline/error) withAsyncResult(waiting, initial, failure) for each environment;deriveUsageSettlingStateonly counts an environment as answered when it has a summary and is not pending.useUsagewires those helpers instead of inline checks.UsageDeviceStripusesisPendingfor the scanning state and shows errors before success vs in-flight rows.Adds unit tests for refresh generations, reconnect, terminal transport, retained summaries on disconnect, and failed refresh clearing stale data.
Reviewed by Cursor Bugbot for commit 12e19a4. Bugbot is set up for automated code reviews on this repo. Configure here.