fix(minimax): correct coding_plan usage_count as remaining quota#60222
Conversation
Greptile SummaryThis PR fixes an inverted usage percentage for the MiniMax coding plan in the menu bar. The MiniMax Key changes:
Confidence Score: 4/5Safe to merge — targeted, well-explained bug fix with correct logic and appropriate test coverage. The core logic change is straightforward and correct: moving misnamed API fields from USED_KEYS to REMAINING_KEYS fixes the inverted usedPercent calculation. Both the new unit test and the updated integration test confirm the expected outputs. The only minor gap is that the newly added weekly fields have no dedicated test case of their own, though their behaviour is identical to the interval fields which are tested. No regressions are introduced for other providers or unrelated MiniMax paths. No files require special attention; all three changed files are consistent and well-reasoned. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/provider-usage.fetch.minimax.ts
Line: 97-141
Comment:
**Consider adding a test for the new weekly fields**
`current_weekly_total_count` / `currentWeeklyTotalCount` (now in `TOTAL_KEYS`) and `current_weekly_usage_count` / `currentWeeklyUsageCount` (now in `REMAINING_KEYS`) are added together in this PR, but there is no test case that exercises the weekly path. The interval fields are covered by the new test in `src/infra/provider-usage.fetch.minimax.test.ts`, but a parallel case for the weekly fields would confirm they compose correctly through `deriveUsedPercent` in the same way:
```ts
{
name: "treats MiniMax current_weekly_usage_count as remaining quota (not consumed)",
payload: {
data: {
current_weekly_total_count: 200,
current_weekly_usage_count: 160,
plan_name: "Coding Plan Weekly",
},
},
expected: {
plan: "Coding Plan Weekly",
windows: [{ label: "5h", usedPercent: 20, resetAt: undefined }],
},
},
```
Not a blocker, but worth adding to prevent the same misunderstanding from creeping back in for the weekly variant.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "修复:MiniMax coding_plan 将 interval/weekly..." | Re-trigger Greptile |
| @@ -133,6 +133,12 @@ const REMAINING_KEYS = [ | |||
| "prompts_left", | |||
| "promptsLeft", | |||
| "left", | |||
| // MiniMax `/coding_plan/remains` misnames these: values are remaining quota, not consumed. | |||
| // See https://github.com/MiniMax-AI/MiniMax-M2/issues/99 | |||
| "current_interval_usage_count", | |||
| "currentIntervalUsageCount", | |||
| "current_weekly_usage_count", | |||
| "currentWeeklyUsageCount", | |||
There was a problem hiding this comment.
Consider adding a test for the new weekly fields
current_weekly_total_count / currentWeeklyTotalCount (now in TOTAL_KEYS) and current_weekly_usage_count / currentWeeklyUsageCount (now in REMAINING_KEYS) are added together in this PR, but there is no test case that exercises the weekly path. The interval fields are covered by the new test in src/infra/provider-usage.fetch.minimax.test.ts, but a parallel case for the weekly fields would confirm they compose correctly through deriveUsedPercent in the same way:
{
name: "treats MiniMax current_weekly_usage_count as remaining quota (not consumed)",
payload: {
data: {
current_weekly_total_count: 200,
current_weekly_usage_count: 160,
plan_name: "Coding Plan Weekly",
},
},
expected: {
plan: "Coding Plan Weekly",
windows: [{ label: "5h", usedPercent: 20, resetAt: undefined }],
},
},Not a blocker, but worth adding to prevent the same misunderstanding from creeping back in for the weekly variant.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/provider-usage.fetch.minimax.ts
Line: 97-141
Comment:
**Consider adding a test for the new weekly fields**
`current_weekly_total_count` / `currentWeeklyTotalCount` (now in `TOTAL_KEYS`) and `current_weekly_usage_count` / `currentWeeklyUsageCount` (now in `REMAINING_KEYS`) are added together in this PR, but there is no test case that exercises the weekly path. The interval fields are covered by the new test in `src/infra/provider-usage.fetch.minimax.test.ts`, but a parallel case for the weekly fields would confirm they compose correctly through `deriveUsedPercent` in the same way:
```ts
{
name: "treats MiniMax current_weekly_usage_count as remaining quota (not consumed)",
payload: {
data: {
current_weekly_total_count: 200,
current_weekly_usage_count: 160,
plan_name: "Coding Plan Weekly",
},
},
expected: {
plan: "Coding Plan Weekly",
windows: [{ label: "5h", usedPercent: 20, resetAt: undefined }],
},
},
```
Not a blocker, but worth adding to prevent the same misunderstanding from creeping back in for the weekly variant.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50d5083243
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "current_weekly_total_count", | ||
| "currentWeeklyTotalCount", |
There was a problem hiding this comment.
Match weekly totals with same-window remaining counters
Adding weekly keys to TOTAL_KEYS makes deriveUsedPercent able to mix windows, because it selects the first total key and first remaining key independently. When MiniMax returns current_interval_usage_count (interval remaining) but omits current_interval_total_count while still including current_weekly_total_count, the code computes usage as weekly_total - interval_remaining, which yields an invalid used percentage for the displayed window. The parser should only compute from matched interval/weekly key pairs.
Useful? React with 👍 / 👎.
|
Landed via temp rebase onto main.
|
Thanks @YangManBOBO! |
Summary
/coding_plan/remainsfieldscurrent_interval_usage_countandcurrent_weekly_usage_countare misleadingly named: values are remaining quota, not consumed usage (seecurrent_interval_usage_countfield is mislabeled — returns remaining quota, not consumed usage MiniMax-AI/MiniMax-M2#99). They were listed underUSED_KEYS, sousedPercentbecame remaining divided by total. macOS derives percent left as100 - usedPercent, which inverted the menu display ([Bug]: MiniMax usage display shows inverted percentage — "2% left" instead of "98% left" #60193).REMAINING_KEYS, add weekly total keys toTOTAL_KEYS, update integration test expectations, add a unit test.Change Type
Scope
Linked Issue
Root cause
MiniMax API field names suggest usage/consumed counts but return remaining counts; the parser treated them as consumed.
Regression test
src/infra/provider-usage.fetch.minimax.test.tsandsrc/infra/provider-usage.test.tsUser-visible changes
Usage summary should show correct percent remaining for MiniMax coding plan.
Security impact
Verification
pnpm test -- src/infra/provider-usage.fetch.minimax.test.ts src/infra/provider-usage.test.tsCompatibility