Skip to content

Scale MiMo token-plan percent fraction to 0-100 - #789

Merged
Finesssee merged 2 commits into
mainfrom
fix/mimo-percent-fraction
Oct 10, 2026
Merged

Finesssee merged 2 commits into
mainfrom
fix/mimo-percent-fraction

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Xiaomi MiMo card showed 0% used for the token plan when the Mac shows 37% (63% left) for the same payload. The Tokens bar now uses the right percentage.

Root cause

GET /api/v1/tokenPlan/usage returns percent as a 0-1 fraction ("percent": 0.37). snapshot_from_parts in rust/src/providers/mimo/mod.rs passed item.percent straight into RateWindow as a 0-100 value, so 0.37 rendered as 0%.

Fix (matches the Mac)

Mac reference: Sources/CodexBarCore/Providers/MiMo/MiMoUsageSnapshot.swift (toUsageSnapshot, v0.70.0):

  • usedPercent = max(0, min(100, tokenPercent * 100)): the fraction is now scaled by 100 and clamped to 0-100.
  • guard tokenLimit > 0 else { return nil }: a usage item with limit <= 0 no longer drives the bar. Win-CodexBar's UsageSnapshot.primary is not optional, so it falls back to the existing "No token-plan usage" placeholder.
  • A missing percent already made the usage payload fail to decode and get dropped, as it does on the Mac (try? in MiMoUsageFetcher.swift). A test now covers it.

Tests

New unit tests in rust/src/providers/mimo/mod.rs, using the parity pack's tokenPlan/usage payload (synthetic values) as the fixture:

  • mimo_token_percent_fraction_is_scaled_to_percentage (0.37 -> 37%)
  • mimo_token_percent_is_clamped_to_0_100 (1.5 -> 100, -0.2 -> 0)
  • mimo_token_window_requires_positive_limit
  • mimo_token_usage_without_percent_is_ignored

The first three fail on main and pass with this change.

Commands run

  • cargo fmt --all -- --check: pass
  • cargo test --manifest-path rust/Cargo.toml: pass (3750 passed, 0 failed, 1 ignored)
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: pass

Only rust/ changed. The Tauri shell manifest wasn't touched, so it wasn't run separately.

Found by the Mac-parity rig (pack MiMo).

Summary by CodeRabbit

  • Bug Fixes
    • MiMo token-plan usage percentages now display on a 0–100% scale, with values kept within that range.
    • If there is no valid usage limit or required percentage data is unavailable, usage displays as 0% with a “No token-plan usage” message. This keeps the usage display clear when a usable token-plan reading cannot be calculated.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: nesszer/Win-CodexBar/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c67f737e-658c-4bff-a88a-22f3cfe83b3e

📥 Commits

Reviewing files that changed from the base of the PR and between a703a71 and 78f2432.


📒 Files selected for processing (1)
  • rust/src/providers/mimo/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.



📝 Walkthrough

Walkthrough

MiMo token-plan snapshots scale fractional usage percentages to 0–100, clamp the result, and ignore usage items with non-positive limits. Tests cover scaling, clamping, zero limits, and payloads missing the required percent field.

Changes

MiMo token-plan usage

Layer / File(s) Summary
Token-plan snapshot parsing and tests
rust/src/providers/mimo/mod.rs
Snapshot parsing ignores usage items with non-positive limits and scales percentages to a clamped 0–100 value. Tests cover these cases and payloads that omit percent.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 78f24

The change corrects fractional percentage display and handles non-positive limits. Available evidence does not establish that a later usage item should be selected instead, so no actionable merge-blocking issue is demonstrated.

Pre-merge checks | Passed 7 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Ui Changes Include Windows Proof Warning The PR changes visible MiMo usage output. In rust/src/providers/mimo/mod.rs, it changes the primary window from the raw fraction to (item.percent * 100.0).clamp(0.0, 100.0) and changes the fallbac… Add screenshots or a proof note from a fresh Windows build to the PR description. The proof should show the MiMo token percentage and the relevant usage text in the Windows application or tray UI.
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: scaling the MiMo token-plan percent fraction to a 0–100 range.
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.
Provider Data Stays Siloed Passed The pull request changes only rust/src/providers/mimo/mod.rs, inside the MiMo provider silo. The production diff only filters MiMo token usage by positive limit and scales/clamps the MiMo percentage…
Secrets Handled Safely Passed The pull request changes only MiMo usage percentage handling and adds synthetic usage tests. The added literals contain no cookie values, API keys, OAuth credentials, authorization headers, or other c…
No Unapproved Dependencies Passed The pull request changes only rust/src/providers/mimo/mod.rs. It does not add or modify Cargo.toml, package.json, npm/yarn lockfiles, or the pinned pnpm packageManager version. The no-unapproved-depen…

Full details: Ui Changes Include Windows Proof

Explanation

The PR changes visible MiMo usage output. In rust/src/providers/mimo/mod.rs, it changes the primary window from the raw fraction to (item.percent * 100.0).clamp(0.0, 100.0) and changes the fallback text to No token-plan usage. The resulting used_percent and reset_description feed the usage and tray renderers, which display the percentage and description. The PR description states the Tokens bar changes, but it includes no screenshot and no proof note from a fresh Windows build. The listed Cargo checks and Mac reference do not satisfy the required Windows proof.


  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR




🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Finesssee
Finesssee merged commit 3226d2f into main Oct 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant