Skip to content

fix(web): wait for usage refresh completion - #5825

Open
caezium wants to merge 1 commit into
pingdotgg:mainfrom
caezium:agent/usage-refresh-gate
Open

fix(web): wait for usage refresh completion#5825
caezium wants to merge 1 commit into
pingdotgg:mainfrom
caezium:agent/usage-refresh-gate

Conversation

@caezium

@caezium caezium commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Treat a retained SWR usage summary as belonging to the previous request until that environment's current refresh finishes.
  • Derive each environment's usage state from both its connection phase and its current AsyncResult, so retries, terminal failures, and reconnects settle consistently.
  • Keep the existing wait-for-all product behavior while making the device strip show the current scan generation truthfully.
  • Add focused state tests for retained summaries, refresh failures, connecting/reconnecting environments, and terminal transport states.

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 passed
  • Targeted vp lint and vp fmt --check on the four touched files
  • vp run --filter @t3tools/web typecheck
  • git diff upstream/main...HEAD --check

UI Changes

Captured against the same local, synthetic two-environment fixture. Alpha finishes in about 0.9s; Beta finishes in about 3.5s.

Before: retained totals stay visible during refresh After: current device progress and skeleton
Before refresh After refresh

Watch the complete refresh settle from loaded → both scanning → one complete → fully loaded

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

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

  • Introduces deriveEnvironmentUsageStatus and deriveUsageSettlingState in usageStatus.ts to centralize per-environment and page-level pending/partial state logic.
  • Each environment's isPending/error/summary now accounts for transport connection phase (including transitions and terminal states), not just the SWR AsyncResult state.
  • The UsageDeviceStrip component in UsagePage.tsx now shows a check only when the environment is non-pending with a summary, and shows an error immediately when environment.error is set.
  • Behavioral Change: the hook's isPending and isPartial flags 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: deriveEnvironmentUsageStatus combines connection phase (connecting/reconnecting vs terminal offline/error) with AsyncResult (waiting, initial, failure) for each environment; deriveUsageSettlingState only counts an environment as answered when it has a summary and is not pending.

useUsage wires those helpers instead of inline checks. UsageDeviceStrip uses isPending for 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.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba121c6c-59e0-40aa-81c8-fea80fd5d938

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 9, 2026
@caezium
caezium marked this pull request as ready for review August 9, 2026 11:55
@macroscopeapp

macroscopeapp Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant