Skip to content

fix(minimax): correct coding_plan usage_count as remaining quota#60222

Merged
steipete merged 1 commit intoopenclaw:mainfrom
YangManBOBO:fix/minimax-coding-plan-remaining-count
Apr 4, 2026
Merged

fix(minimax): correct coding_plan usage_count as remaining quota#60222
steipete merged 1 commit intoopenclaw:mainfrom
YangManBOBO:fix/minimax-coding-plan-remaining-count

Conversation

@YangManBOBO
Copy link
Copy Markdown

Summary

Change Type

  • Bug fix

Scope

  • Integrations

Linked Issue

Root cause

MiniMax API field names suggest usage/consumed counts but return remaining counts; the parser treated them as consumed.

Regression test

  • Unit tests in src/infra/provider-usage.fetch.minimax.test.ts and src/infra/provider-usage.test.ts

User-visible changes

Usage summary should show correct percent remaining for MiniMax coding plan.

Security impact

  • New permissions: No
  • Secrets / network / command execution / data scope: No

Verification

  • pnpm test -- src/infra/provider-usage.fetch.minimax.test.ts src/infra/provider-usage.test.ts

Compatibility

  • Backward compatible: Yes

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 3, 2026

Greptile Summary

This PR fixes an inverted usage percentage for the MiniMax coding plan in the menu bar. The MiniMax /coding_plan/remains endpoint misnames current_interval_usage_count and current_weekly_usage_count — despite the "usage" wording, these fields return remaining quota (not consumed quota), as documented in MiniMax-M2#99. The previous code placed them in USED_KEYS, so usedPercent ended up as remaining / total instead of used / total, inverting what the macOS menu bar displayed.

Key changes:

  • Moves current_interval_usage_count / currentIntervalUsageCount from USED_KEYS to REMAINING_KEYS.
  • Adds the weekly counterparts current_weekly_usage_count / currentWeeklyUsageCount to REMAINING_KEYS.
  • Adds current_weekly_total_count / currentWeeklyTotalCount to TOTAL_KEYS so the weekly denominator is recognized.
  • Updates the integration test in src/infra/provider-usage.test.ts to reflect usedPercent: 75 (not 25) for a record with total=120 and remaining=30.
  • Adds a focused unit test in src/infra/provider-usage.fetch.minimax.test.ts confirming current_interval_usage_count is treated as remaining quota.

Confidence Score: 4/5

Safe 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 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.

Reviews (1): Last reviewed commit: "修复:MiniMax coding_plan 将 interval/weekly..." | Re-trigger Greptile

Comment on lines 97 to +141
@@ -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",
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.

P2 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!

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +97 to +98
"current_weekly_total_count",
"currentWeeklyTotalCount",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@steipete steipete merged commit cca3540 into openclaw:main Apr 4, 2026
37 of 44 checks passed
@steipete
Copy link
Copy Markdown
Contributor

steipete commented Apr 4, 2026

Landed via temp rebase onto main.

  • Gate: pnpm test src/infra/provider-usage.fetch.minimax.test.ts, OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/infra/provider-usage.test.ts -t MiniMax, pnpm build
  • pnpm check: currently red on latest main from unrelated extensions/github-copilot/stream.test.ts:38 (TS2339: Property messages does not exist on type never)
  • Land commit:

@steipete
Copy link
Copy Markdown
Contributor

steipete commented Apr 4, 2026

  • Land commit: cd5133f50e81e578ab8650b0d0010e528677cc26
  • Merge commit: cca35404ea2fb77413aab3e68a74e0afa60ed202

Thanks @YangManBOBO!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MiniMax usage display shows inverted percentage — "2% left" instead of "98% left"

2 participants