Skip to content

fix(minimax): handle CN percent-only quotas#531

Open
lyizhou wants to merge 2 commits into
robinebers:mainfrom
lyizhou:fix/minimax-cn-percent-fallback
Open

fix(minimax): handle CN percent-only quotas#531
lyizhou wants to merge 2 commits into
robinebers:mainfrom
lyizhou:fix/minimax-cn-percent-fallback

Conversation

@lyizhou
Copy link
Copy Markdown

@lyizhou lyizhou commented Jun 1, 2026

Summary

  • handle MiniMax CN Coding Plan responses where current_interval_total_count is 0 but current_interval_remaining_percent is present
  • avoid selecting CN count totals that round down to 0 prompts after the model-call-to-prompt conversion
  • document the percent fallback and add a regression test based on a sanitized MiniMax CN payload

Problem

Some MiniMax CN Coding Plan accounts return a usable percentage quota but no count total for the general model, for example:

model_name = general
current_interval_total_count = 0
current_interval_usage_count = 0
current_interval_remaining_percent = 94
current_weekly_total_count = 0
current_weekly_usage_count = 0
current_weekly_remaining_percent = 99

The existing plugin expects a positive current_interval_total_count. For CN, small model-call totals can also round down to 0 prompts after dividing by 15. That produces a progress line with limit: 0, which the runtime rejects with:

progress line at index 0 invalid limit: 0

Fix

When counts are unavailable but current_interval_remaining_percent is valid, the MiniMax plugin now returns a percent progress line with limit: 100. For the example above, the line renders as used: 6, limit: 100, format: { kind: "percent" }.

Testing

  • npm install --no-package-lock
  • npm exec vitest -- run plugins/minimax/plugin.test.js
    • 43 tests passed

Summary by cubic

Adds a percent-based fallback to the MiniMax CN plugin and avoids zero-limit progress lines by skipping CN totals that round to 0 prompts. This fixes rejected progress lines and shows accurate usage when only percentages are provided.

  • Bug Fixes
    • Return a percent progress line (limit: 100) when current_interval_total_count is 0 but current_interval_remaining_percent exists.
    • For CN, skip totals that round to 0 prompts after the model-call→prompt conversion and prefer the general model when only percent data is available.
    • Update docs and add tests for percent-only CN quotas and for cases where small-count rows come first.

Written for commit ea42413. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • MiniMax provider now supports percent-based usage display when explicit usage counts are unavailable and better detects plan titles.
  • Documentation

    • Updated MiniMax docs to document the new percent-based progress field and show percent-rendering behavior.
  • Tests

    • Added tests covering percent-based remaining-usage fallback and rendering scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f51eacab-14a0-498c-bd54-767c44086e1a

📥 Commits

Reviewing files that changed from the base of the PR and between ee0dc14 and ea42413.

📒 Files selected for processing (3)
  • docs/providers/minimax.md
  • plugins/minimax/plugin.js
  • plugins/minimax/plugin.test.js
✅ Files skipped from review due to trivial changes (1)
  • docs/providers/minimax.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/minimax/plugin.js

📝 Walkthrough

Walkthrough

This PR extends the MiniMax provider to support percent-based usage reporting. When API responses lack count totals but provide a remaining-percentage field, the plugin converts that into used/total values and formats the output as a percent-based session line.

Changes

MiniMax percent-based usage fallback

Layer / File(s) Summary
Documentation of percent usage field
docs/providers/minimax.md
Documented the optional current_interval_remaining_percent payload field and added guidance to render percent-based progress lines when count totals are unavailable.
Parsing percent fallback and session formatting
plugins/minimax/plugin.js
Remains entry selection now applies display multipliers to prevent CN-vs-GLOBAL scaling issues. Added percent-based fallback logic to read remaining percentage (validated 0–100), compute used = 100 - remainingPercent with fixed total = 100, mark results with formatKind: "percent", reorganize computed timing/plan fields, and update probe to emit percent-formatted session lines when appropriate.
Tests for percent fallback
plugins/minimax/plugin.test.js
Added CN tests verifying percent-fallback behavior, plan name inference, computed used/limit values, and that the produced session line has { kind: "percent" }.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(minimax): handle CN percent-only quotas' directly and specifically describes the main change: adding support for MiniMax CN responses that provide quota as a percentage when numeric counts are unavailable.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/minimax/plugin.js (1)

247-257: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Selection can still pick a CN entry that formats to limit: 0.

Because chosen starts as modelRemains[0], a first CN entry like total=3 can survive selection even when it fails Math.round(total / 15) > 0. That bypasses percent fallback and later yields limit: 0 in Line 397. Please avoid defaulting to the first row; select only a displayable-count candidate or a valid percent candidate.

Proposed fix
-    let chosen = modelRemains[0]
+    let chosen = null
+    let percentFallbackCandidate = null
     for (let i = 0; i < modelRemains.length; i += 1) {
       const item = modelRemains[i]
       if (!item || typeof item !== "object") continue
       const total = readNumber(item.current_interval_total_count ?? item.currentIntervalTotalCount)
-      if (total !== null && total > 0 && Math.round(total * displayMultiplierForSelection) > 0) {
+      if (total !== null && total > 0 && Math.round(total * displayMultiplierForSelection) > 0) {
         chosen = item
         break
       }
+      if (percentFallbackCandidate === null && (total === null || total <= 0)) {
+        const rp = readNumber(
+          item.current_interval_remaining_percent ?? item.currentIntervalRemainingPercent
+        )
+        if (rp !== null && rp >= 0 && rp <= 100) percentFallbackCandidate = item
+      }
     }
+    if (!chosen) chosen = percentFallbackCandidate
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/minimax/plugin.js` around lines 247 - 257, The current selection
logic defaults chosen to modelRemains[0], which can pick a CN entry that formats
to limit: 0; change the algorithm in the block using
displayMultiplierForSelection, modelRemains and readNumber so that chosen is not
pre-seeded (initialize chosen = null) and only assigned when an item passes the
displayable-count check (total !== null && Math.round(total *
displayMultiplierForSelection) > 0); after the loop, if chosen is still null,
fall back to the existing percent-selection path (the percent candidate logic)
instead of using the first element, ensuring any chosen candidate yields a
positive displayable count or a valid percent before it is used to compute
limit.
🧹 Nitpick comments (1)
plugins/minimax/plugin.test.js (1)

928-962: ⚡ Quick win

Add a reversed-order variant to lock the selection behavior.

This test is good, but it only passes with the percent-capable row first. Add a sibling case with the video (total=3) row first and percent row second to prevent reintroducing limit: 0 regressions from entry ordering.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/minimax/plugin.test.js` around lines 928 - 962, Add a sibling test
that mirrors the existing "falls back to CN remaining percent when count totals
are unavailable" case but with the model_remains array order reversed (place the
"video" entry with total=3 first and the "general" percent-capable entry second)
so selection logic is locked to content, not entry order; duplicate the existing
it(...) test as a new it(...) with the same assertions (expect result.plan,
lines[0].used, lines[0].limit, lines[0].format) and only change the mocked
ctx.host.http.request.mockReturnValue bodyText to provide the reversed array to
ensure the plugin.probe function (used via loadPlugin and plugin.probe(ctx))
still picks the percent-capable row and sets limit to 100.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/providers/minimax.md`:
- Line 68: Update the Output section in docs/providers/minimax.md to document
the percent-based Session format variant alongside the existing count-only
contract: describe the shape for the percent variant as format: { kind:
"percent" } with limit: 100, explain that progress lines may emit a percent when
totals are unavailable, and show how this maps to the Session output contract
(in addition to the existing count-based format) so readers can see both
formats.

---

Outside diff comments:
In `@plugins/minimax/plugin.js`:
- Around line 247-257: The current selection logic defaults chosen to
modelRemains[0], which can pick a CN entry that formats to limit: 0; change the
algorithm in the block using displayMultiplierForSelection, modelRemains and
readNumber so that chosen is not pre-seeded (initialize chosen = null) and only
assigned when an item passes the displayable-count check (total !== null &&
Math.round(total * displayMultiplierForSelection) > 0); after the loop, if
chosen is still null, fall back to the existing percent-selection path (the
percent candidate logic) instead of using the first element, ensuring any chosen
candidate yields a positive displayable count or a valid percent before it is
used to compute limit.

---

Nitpick comments:
In `@plugins/minimax/plugin.test.js`:
- Around line 928-962: Add a sibling test that mirrors the existing "falls back
to CN remaining percent when count totals are unavailable" case but with the
model_remains array order reversed (place the "video" entry with total=3 first
and the "general" percent-capable entry second) so selection logic is locked to
content, not entry order; duplicate the existing it(...) test as a new it(...)
with the same assertions (expect result.plan, lines[0].used, lines[0].limit,
lines[0].format) and only change the mocked
ctx.host.http.request.mockReturnValue bodyText to provide the reversed array to
ensure the plugin.probe function (used via loadPlugin and plugin.probe(ctx))
still picks the percent-capable row and sets limit to 100.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eec562b1-5913-419e-b8a5-a9dd96b39a62

📥 Commits

Reviewing files that changed from the base of the PR and between 810b122 and ee0dc14.

📒 Files selected for processing (3)
  • docs/providers/minimax.md
  • plugins/minimax/plugin.js
  • plugins/minimax/plugin.test.js

Comment thread docs/providers/minimax.md
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant