Skip to content

fix(dashboard): resolve Unknown plan display in Provider Limits - #2004

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.0from
congvc-dev:fix/unknown-plan-display
May 7, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.0from
congvc-dev:fix/unknown-plan-display

Conversation

@congvc-dev

Copy link
Copy Markdown
Contributor

Root cause

Two separate code paths produced a literal "Unknown" string when plan data was unavailable, and the Provider Limits UI treated that as a valid plan value and displayed it as a badge label:

  1. open-sse/services/usage.ts — GLM and both Claude legacy fallback sites used || "Unknown" instead of || null. Downstream UI code has no way to distinguish between a provider that returned the string "Unknown" and one that simply has no plan.
  2. src/lib/oauth/providers/claude.tsmapTokens did not extract plan information from the OAuth token payload at all, so even when the Claude OAuth response included account_tier, plan, or subscription_type, none of it reached providerSpecificData.

Solution

open-sse/services/usage.ts

  • Replace || "Unknown" with || null at the GLM plan fallback and both Claude legacy return sites. null is the canonical "no plan available" sentinel the UI already knows how to handle.

src/lib/oauth/providers/claude.ts

  • Add extractClaudePlan that walks a priority chain: account_tier → plan → subscription_type → billing.plan (both in the token payload and in any userInfo extra data).
  • Update mapTokens to include providerSpecificData: { plan } when a non-empty plan string is found; omits the key entirely when nothing is present.

Test plan

  • tests/unit/claude-oauth-provider.test.ts — 3 new cases: priority ordering, userInfo fallback, undefined when no plan fields
  • tests/unit/provider-limits-ui.test.ts — 1 new case: providerSpecificData.plan used when live plan is null
  • npm run typecheck:core passes (zero type errors)
  • Both test files pass 100% in isolation (node --import tsx/esm --test)

- Replace || "Unknown" fallbacks with || null in usage.ts (GLM + Claude legacy)
- Add plan extraction to Claude OAuth mapTokens (account_tier > plan > subscription_type > billing.plan)
- Add unit tests for plan extraction and Provider Limits badge resolution
@congvc-dev
congvc-dev requested a review from diegosouzapw as a code owner May 6, 2026 15:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors plan handling by defaulting missing plans to null and introducing a robust extraction utility for Claude OAuth providers. The new logic scans multiple potential fields in the token and user info payloads to identify the user's subscription level. Accompanying tests verify the extraction order and UI integration. Feedback was provided to include the tier field in the extraction priority for Claude to maintain consistency with the usage service.

I am having trouble creating individual review comments. Click here to see my feedback.

src/lib/oauth/providers/claude.ts (28)

medium

The tier field should be included in the extraction priority chain. The modern Claude usage API (as seen in open-sse/services/usage.ts around line 1764) prioritizes the tier field over plan. Adding it here ensures consistency between the OAuth extraction logic and the usage service, increasing the likelihood of correctly identifying the user's plan from the token payload.

  return firstNonEmptyString(data.account_tier, data.tier, data.plan, data.subscription_type, billing.plan);

The original fix replaced || "Unknown" with || null for GLM and Claude
legacy (non-OAuth) paths. Per user clarification, "Unknown" is a valid
display fallback when no plan data exists — null-based fallbacks caused
the Provider Limits dashboard to show no badge rather than a clear
"Unknown" indicator.

Revert only the usage.ts changes. Claude OAuth mapTokens plan extraction
(claude.ts) and the associated tests remain unchanged.
@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.0 May 7, 2026 11:24
@diegosouzapw

Copy link
Copy Markdown
Owner

Thank you @congvc-dev for your contribution! This has been reviewed and is now merged into release/v3.8.0 for the upcoming release. Amazing work!

@diegosouzapw
diegosouzapw merged commit 61fb2ac into diegosouzapw:release/v3.8.0 May 7, 2026
67 checks passed
@congvc-dev
congvc-dev deleted the fix/unknown-plan-display branch May 8, 2026 03:23
@diegosouzapw diegosouzapw mentioned this pull request May 10, 2026
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.

2 participants