Skip to content

fix(usage-analysis): prevent blank page on cold start and improve error handling#661

Merged
rajbos merged 2 commits intomainfrom
rajbos/fix-usage-analysis-tab-658
Apr 24, 2026
Merged

fix(usage-analysis): prevent blank page on cold start and improve error handling#661
rajbos merged 2 commits intomainfrom
rajbos/fix-usage-analysis-tab-658

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 24, 2026

Summary

Fixes #658 — Usage Analysis tab could show nothing (stuck on loading spinner or blank page) on cold start.

Root Cause Analysis

Investigated the full data flow from showUsageAnalysis()calculateUsageAnalysisStats()postMessagesanitizeStats()renderLayout() and identified multiple resilience gaps in the cold-start path (first time opening Usage Analysis with no cached stats):

  1. Error = spinner forever: If calculateUsageAnalysisStats failed, .catch() only logged the error — no message was sent to the webview, leaving the user stuck on "⏳ Loading usage analysis…" indefinitely.

  2. sanitizeStats dropped fields: The sanitization function only returned {today, last30Days, month, lastUpdated, backendConfigured}, stripping locale, customizationMatrix, missedPotential, currentWorkspacePaths, and suppressedUnknownTools. On cold start (where window.__INITIAL_USAGE__ is null), fallbacks to initial data don't help — the customization matrix shows "no workspaces", suppressed tools reappear, etc.

  3. Null sanitization = silent failure: If sanitizeStats returned null, the message handler did nothing — no error, no retry, no feedback.

  4. bootstrap() had no error handling: void bootstrap() with no .catch() — if the toolkit import or anything else threw, the user saw a completely blank page.

  5. Stale async results: The panel could be closed and reopened while a calculation was still in flight, allowing stale results to post into a new panel.

Changes

vscode-extension/src/extension.ts

  • Send updateStatsError message to the webview when background calculation fails
  • Capture panel reference before async work; only post if the panel hasn't been recreated

vscode-extension/src/webview/usage/main.ts

  • sanitizeStats: Now validates and passes through all fields (with shape-level validation for nested objects like customizationMatrix and missedPotential)
  • Message handler: Handle updateStatsError and null sanitization result with user-friendly error + refresh button
  • bootstrap(): Wrapped in .catch() with fallback error UI (plain HTML, not toolkit-dependent)
  • Loading timeout: 30s non-fatal "taking longer than expected" hint with refresh button (cleared when data arrives)

Testing

  • npm run compile passes (type-check + lint + build)
  • No changes to test files; existing tests unaffected

rajbos and others added 2 commits April 24, 2026 14:47
…or handling

Fixes #658 — Usage Analysis tab could show nothing (stuck on loading
spinner or blank page) when:
- Background stats calculation failed with no feedback to the webview
- sanitizeStats dropped fields needed for rendering (locale, matrix,
  missed potential, workspace paths, suppressed tools)
- bootstrap() had no error handling (blank page if toolkit import fails)
- No timeout for the loading state (spinner forever)

Changes:
- extension.ts: send updateStatsError to webview on calculation failure;
  guard against stale async results posting into a recreated panel
- webview/usage/main.ts: sanitizeStats now validates and passes through
  all fields; handle updateStatsError and null sanitization with error
  message + refresh button; bootstrap wraps in .catch() with fallback;
  30s non-fatal loading timeout with refresh hint

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…essions

Starting with Copilot 1.117+, chat sessions are stored under
workspaceStorage/<hash>/GitHub.copilot/chatSessions/ instead of the
older GitHub.copilot-chat/chatSessions/ path. Users on the unified
Copilot extension (e.g. v0.45.x) had zero session data discovered.

Add GitHub.copilot and github.copilot (case-sensitive variant) to:
- workspaceStorage candidate list in discover()
- globalStorage recursive scan
- isCopilotChatSessionPath() path predicate
- Module doc comment discovery scope list

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos merged commit 2d007b1 into main Apr 24, 2026
17 checks passed
@rajbos rajbos deleted the rajbos/fix-usage-analysis-tab-658 branch April 24, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][vscode] Usage Analysis tab error

1 participant