You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scale MiMo token-plan percent fraction to 0-100 - #789
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:
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.
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.
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 | 7 | 1
❌ Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Ui Changes Include Windows Proof
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
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: scaling the MiMo token-plan percent fraction to a 0–100 range.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Provider Data Stays Siloed
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
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/usagereturnspercentas a 0-1 fraction ("percent": 0.37).snapshot_from_partsinrust/src/providers/mimo/mod.rspasseditem.percentstraight intoRateWindowas 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 withlimit <= 0no longer drives the bar. Win-CodexBar'sUsageSnapshot.primaryis not optional, so it falls back to the existing "No token-plan usage" placeholder.percentalready made the usage payload fail to decode and get dropped, as it does on the Mac (try?inMiMoUsageFetcher.swift). A test now covers it.Tests
New unit tests in
rust/src/providers/mimo/mod.rs, using the parity pack'stokenPlan/usagepayload (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_limitmimo_token_usage_without_percent_is_ignoredThe first three fail on
mainand pass with this change.Commands run
cargo fmt --all -- --check: passcargo test --manifest-path rust/Cargo.toml: pass (3750 passed, 0 failed, 1 ignored)cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: passOnly
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