fix(usage): improve Claude and MiniMax plan label detection#2498
fix(usage): improve Claude and MiniMax plan label detection#2498Gi99lin wants to merge 3 commits into
Conversation
Parse MiniMax plan titles and infer tier from quota totals; skip generic Claude Code fallback when OAuth has no tier. UI maps default_claude_max_* and Starter badges correctly. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request enhances plan identification and normalization for MiniMax and Claude providers. Key changes include the addition of utility functions to extract and clean plan labels from API payloads, the implementation of usage-based plan inference for MiniMax, and refinements to the UI normalization logic to prevent false positives when matching plan tiers. Feedback suggests extending the use of word-boundary regex to other tier keywords like 'PRO' and 'LITE' to ensure consistent and robust detection across all providers.
| if (/(?:^|[^A-Z])MAX(?:[^A-Z]|$)/.test(upper)) { | ||
| return { key: "ultra", label: "Max", variant: "success", rank: 4, raw }; | ||
| } |
There was a problem hiding this comment.
The new regex for MAX correctly prevents false positives from substrings like MINIMAX. However, other tier keywords like PRO, LITE, or PLUS are still using upper.includes(), which could lead to similar issues if they appear as substrings in future provider names or labels (e.g., APPROVE, LITERAL). Consider applying a similar word-boundary regex to these checks for consistency and robustness.
Address PR review: share hasTierToken helper with MAX matching to avoid substring false positives across plan label normalization. Co-authored-by: Cursor <cursoragent@cursor.com>
|
|
||
| /** Match tier tokens as whole words (avoids MINIMAX → Max, APPROVE → Pro, etc.). */ | ||
| function hasTierToken(upper: string, token: string): boolean { | ||
| const pattern = new RegExp(`(?:^|[^A-Z])${token}(?:[^A-Z]|$)`); |
There was a problem hiding this comment.
WARNING: Unescaped regex injection risk
The token parameter is passed directly into new RegExp() without escaping special regex characters. While current callers use safe hardcoded tokens ("MAX", "PRO", "STARTER", "LITE", "PLUS"), future callers could accidentally pass tokens containing regex metacharacters like *, +, ., ?, [, ], causing unexpected behavior or ReDoS.
Consider using a regex escape utility: token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
| response.status === 403 || | ||
| apiStatusCode === 1004 || | ||
| authLikeMessage.test(combinedMessage) | ||
| authLikeStatusMessage.test(apiStatusMessage) |
There was a problem hiding this comment.
SUGGESTION: Narrowed auth error detection scope
Changed from testing combinedMessage (status_msg + raw response text) to only apiStatusMessage. If the upstream API returns auth-related errors in other response fields or the raw body (but not in status_msg), they won't be detected as auth failures anymore.
The fallback at line 422 (apiStatusMessage || combinedMessage) helps with error message formatting but not with detection. Consider whether combinedMessage should still be tested as a fallback condition.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Other Observations (not in diff)No issues found outside the diff. Files Reviewed (4 files)
Reviewed by qwen3.6-plus · 429,838 tokens |
Escape regex tokens in hasTierToken, apply word-boundary checks to PREMIUM/LIGHT/PAID, and add regression tests for MiniMax/APPROVE false positives. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Kilo Code Review could not run — your account is out of credits. Add credits or switch to a free model to enable reviews on this change. |
Summary
Claude Codeplan when OAuth has no tier; prefer bootstraporganization_rate_limit_tier; UI ignoresdefault_claude_aiorg type and mapsdefault_claude_max_*to Max badges.plan_name/ subscribe titles from API; infer Starter/Plus/Max from session quota totals when title is missing; tighten auth-error detection to API status message only.Complements PR #2496 (Antigravity tier only) — no overlap in scope.
Test plan
provider-limits-ui.test.ts— Claude bootstrap tiers, MiniMax title normalizationusage-service-hardening.test.ts— MiniMax plan fromplan_nameand inferred Max tier; Claude default plan is undefined without tier