fix(dashboard): resolve Unknown plan display in Provider Limits - #2004
diegosouzapw merged 2 commits into
Conversation
- 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
There was a problem hiding this comment.
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)
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.
|
Thank you @congvc-dev for your contribution! This has been reviewed and is now merged into |
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: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.src/lib/oauth/providers/claude.ts—mapTokensdid not extract plan information from the OAuth token payload at all, so even when the Claude OAuth response includedaccount_tier,plan, orsubscription_type, none of it reachedproviderSpecificData.Solution
open-sse/services/usage.ts|| "Unknown"with|| nullat the GLM plan fallback and both Claude legacy return sites.nullis the canonical "no plan available" sentinel the UI already knows how to handle.src/lib/oauth/providers/claude.tsextractClaudePlanthat walks a priority chain:account_tier → plan → subscription_type → billing.plan(both in the token payload and in anyuserInfoextra data).mapTokensto includeproviderSpecificData: { 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 fieldstests/unit/provider-limits-ui.test.ts— 1 new case:providerSpecificData.planused when live plan isnullnpm run typecheck:corepasses (zero type errors)node --import tsx/esm --test)