Skip to content

feat: Add reserve/pace indicator for Xiaomi MiMo token plan#1310

Open
AdrianSimionov wants to merge 5 commits into
steipete:mainfrom
AdrianSimionov:feat/mimo-reserve
Open

feat: Add reserve/pace indicator for Xiaomi MiMo token plan#1310
AdrianSimionov wants to merge 5 commits into
steipete:mainfrom
AdrianSimionov:feat/mimo-reserve

Conversation

@AdrianSimionov
Copy link
Copy Markdown

Adds green pace marker and 'X% in reserve' labels when MiMo token usage is below expected linear consumption for the monthly billing period.

  • Estimates 30/31-day window from planPeriodEnd for pace calculation
  • Uses UsagePace.weekly() via Abacus-style primary window path
  • Green stripe on progress bar when in reserve, red when in deficit
  • Menu card shows 'X% in reserve · Lasts until reset' detail

Shows green pace marker and "X% in reserve" labels when token usage
is below expected linear consumption for the monthly billing period.
Estimates 30/31-day window from planPeriodEnd for pace calculation.
@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented Jun 5, 2026

Codex review: needs changes before merge. Reviewed June 5, 2026, 12:40 AM ET / 04:40 UTC.

Summary
The PR adds MiMo primary-window pace calculation, reserve/deficit labels and progress markers in the menu card, plus focused MiMo provider tests.

Reproducibility: yes. for the patch defect: an annual plan with less than one month remaining satisfies monthWindow >= timeUntilReset and returns a monthly duration. I did not run tests because this review is read-only, but the source path is direct.

Review metrics: 1 noteworthy metric.

  • Changed surface: 5 files, +150/-7. The patch spans provider snapshot semantics, menu model selection, visible menu rendering, and tests, so the billing-window inference needs review beyond green compilation.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Fix or fail closed for annual plans in their final month.
  • [P2] Add a focused MiMoProviderTests case with less than one month remaining on an annual plan.
  • [P2] Run swift test --filter MiMoProviderTests and make check after the repair.

Risk before merge

  • [P1] Annual MiMo token-plan users inside the final month before reset can receive a monthly-paced reserve/deficit marker for annual credits.
  • [P1] The MiMo API context in the discussion still leaves a product/API question: either use reliable period-start/duration or plan metadata, or suppress pace when the window is ambiguous.

Maintainer options:

  1. Fix annual final-month inference (recommended)
    Before merge, make annual plans in their final month use the annual duration when reliably identifiable, or suppress the pace marker when the period length is ambiguous.
  2. Accept inferred-window policy explicitly
    Maintainers can choose to accept the inferred-window behavior only after documenting why MiMo reset date and plan metadata are reliable enough for user-facing pace labels.
  3. Pause until API semantics are known
    If MiMo does not expose enough data to distinguish monthly and annual final-month periods, pause this PR rather than shipping a misleading quota predictor.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Fix MiMo billing-window inference so annual token plans in their final month are not treated as monthly; prefer reliable plan duration/start metadata when available, otherwise fail closed by leaving windowMinutes nil for ambiguous periods. Add focused MiMoProviderTests for an annual plan with less than one month remaining and keep live provider/Keychain validation out of the test path.

Next step before merge

  • [P2] A narrow repair can preserve the branch by fixing annual final-month inference and adding focused tests, while leaving final product acceptance of inferred MiMo windows to maintainers.

Security
Cleared: The diff does not add dependencies, scripts, credential handling, or new network/auth surfaces beyond existing MiMo usage data rendering.

Review findings

  • [P1] Do not classify final-month annual plans as monthly — Sources/CodexBarCore/Providers/MiMo/MiMoUsageSnapshot.swift:56-57
Review details

Best possible solution:

Render MiMo pace only when the billing window can be reliably classified as monthly or annual, and fail closed with focused tests for ambiguous final-month annual periods.

Do we have a high-confidence way to reproduce the issue?

Yes, for the patch defect: an annual plan with less than one month remaining satisfies monthWindow >= timeUntilReset and returns a monthly duration. I did not run tests because this review is read-only, but the source path is direct.

Is this the best way to solve the issue?

No; the feature direction is useful, but the current inference is not the safest maintainable solution. The PR should use reliable period metadata or fail closed for ambiguous annual final-month windows before rendering pace.

Full review comments:

  • [P1] Do not classify final-month annual plans as monthly — Sources/CodexBarCore/Providers/MiMo/MiMoUsageSnapshot.swift:56-57
    This returns a one-month window whenever the remaining time is less than the month length. An annual MiMo plan inside its last month also satisfies that condition, so the new reserve/deficit marker is computed against roughly 30 days instead of the yearly credit period. Use reliable plan duration/start metadata or fail closed for ambiguous final-month annual periods before showing pace.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 65e39f4dcb3a.

Label changes

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a useful provider-specific feature with a blocking correctness issue, but the blast radius is limited to MiMo token-plan pace display.
  • merge-risk: 🚨 other: Merging as-is can show misleading reserve/deficit predictions for annual MiMo users, a live billing-semantics risk that normal CI cannot settle.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The PR includes an inspected screenshot showing the after-change MiMo menu card with the deficit marker and labels.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes an inspected screenshot showing the after-change MiMo menu card with the deficit marker and labels.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR includes an inspected screenshot showing the after-change MiMo menu card with the deficit marker and labels.
Evidence reviewed

Acceptance criteria:

  • [P1] swift test --filter MiMoProviderTests.
  • [P1] make check.

What I checked:

  • Repository policy read and applied: AGENTS.md was read fully; its guidance to prefer focused provider/parser tests and avoid live provider or Keychain-prompting validation applies to this MiMo provider review. (AGENTS.md:24, 65e39f4dcb3a)
  • Current main does not already implement MiMo pace: Current main leaves MiMo token-plan RateWindow.windowMinutes nil and routes weekly pace from the secondary window except for Abacus, so the requested MiMo primary-window pace behavior is not already on main. (Sources/CodexBarCore/Providers/MiMo/MiMoUsageSnapshot.swift:50, 65e39f4dcb3a)
  • Blocking final-month annual inference: At PR head, line 56 returns a one-month window whenever the remaining time is less than the inferred month length, which also matches annual plans in their final month. (Sources/CodexBarCore/Providers/MiMo/MiMoUsageSnapshot.swift:56, 4ae0d4897b39)
  • Annual coverage does not hit the ambiguous period: The added annual regression test covers 76 days remaining, which is still longer than a monthly window and does not exercise the final-month annual ambiguity. (Tests/CodexBarTests/MiMoProviderTests.swift:286, 4ae0d4897b39)
  • Real behavior proof inspected: The contributor's screenshot was downloaded and inspected; it shows the post-change MiMo menu card with an 85% used red deficit marker and deficit/runout labels. (4ae0d4897b39)
  • Relevant area history: Git history points to the MiMo provider introduction, session pace indicator work, and weekly pace menu work as the most relevant ownership trail for routing this review.

Likely related people:

  • Deb Pramanik: Commit f9a2918 added Xiaomi MiMo token-plan usage tracking, including the snapshot, fetcher, and MiMo provider tests now being extended. (role: introduced MiMo provider behavior; confidence: high; commits: f9a2918afcf1; files: Sources/CodexBarCore/Providers/MiMo/MiMoUsageSnapshot.swift, Sources/CodexBarCore/Providers/MiMo/MiMoUsageFetcher.swift, Tests/CodexBarTests/MiMoProviderTests.swift)
  • John Larkin: Commit 5cf2ea4 introduced the shared session pace indicator behavior that this PR reuses for MiMo. (role: pace indicator introducer; confidence: medium; commits: 5cf2ea404ae5; files: Sources/CodexBar/MenuCardView.swift, Sources/CodexBarCore/UsagePace.swift)
  • zhulijin1991: Commit 599c017 added weekly pace detail rendering in the Codex menu, adjacent to the menu-card detail path changed here. (role: weekly pace menu contributor; confidence: medium; commits: 599c017483ba; files: Sources/CodexBar/MenuCardView.swift, Tests/CodexBarTests/MenuCardModelCodexProjectionTests.swift)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

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: 060867c0c0

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +53 to +54
let twentyEightDays: TimeInterval = 28 * 24 * 60 * 60
return timeUntilReset > twentyEightDays ? 44_640 : 43_200
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 Do not infer 31-day MiMo windows from remaining time

For MiMo plans that reset at the end of a 30-day month, this classifies the first ~2 days as a 31-day window because timeUntilReset > 28 days; with a June 30 23:59:59 reset, a June 1 snapshot has almost 30 days remaining, so UsagePace.weekly treats it as already ~1 day elapsed and can show a false “3% in reserve” marker at the start of the cycle. The same problem is larger for February resets. Since the reset date is available, derive the month length from planPeriodEnd (or avoid showing pace until the actual window length is known) rather than using remaining time.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 5, 2026
Use Calendar.date(byAdding: .month, -1, to: periodEnd) to compute the
cycle start, then measure the exact window. This correctly handles
mid-month subscriptions (June 15 → May 15 = 31 days) and end-of-month
resets (June 30 → May 31 = 30 days via Calendar's end-of-month
preservation), instead of a >28-day heuristic that misclassified the
first ~2 days of a 30-day cycle as 31 days.
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jun 5, 2026
@AdrianSimionov
Copy link
Copy Markdown
Author

Behavior proof: MiMo token plan pace indicator showing 68% in deficit (red marker) at 85% usage with reset on June 30. The pace marker correctly reflects accelerated usage ahead of the linear projection.

mimo-reserve-pace-marker

[Screenshot showing: MiMo menu card with 85% used, red pace marker, "68% in deficit · Runs out in ~21h", resets 30 Jun]

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented Jun 5, 2026

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@AdrianSimionov
Copy link
Copy Markdown
Author

@codex review

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: ab9e76f5f8

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// subscriptions (e.g. reset June 15 → started May 15 → 31 days)
// and February resets (28/29 days).
let calendar = Calendar.current
guard let cycleStart = calendar.date(byAdding: .month, value: -1, to: periodEnd) else { return nil }
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 Account for annual MiMo token periods

When a MiMo account is on an annual token plan, currentPeriodEnd can be close to a year out (the MiMo docs list annual fixed-credit packages: https://platform.xiaomimimo.com/docs/en-US/tokenplan/subscription). Subtracting exactly one month makes windowMinutes about 30 days while resetsAt is many months away, so UsagePace.weekly rejects the window via timeUntilReset > duration and the new reserve/deficit indicator is absent for annual subscribers until the final month; if shown near the end, the expected pace is also based on the wrong duration. Please use the actual period start/duration from the API, or infer yearly vs monthly before setting windowMinutes.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 5, 2026
Calendar.current uses the system timezone, which makes month
subtraction non-deterministic (AEST: June 30 → May 31 = 30 days;
UTC: June 30 → May 30 = 31 days).  Use an explicit UTC calendar so
the window length is consistent across all environments.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 5, 2026
@AdrianSimionov
Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented Jun 5, 2026

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

Detect annual plans (>90 days to reset) and subtract one year
instead of one month when computing the billing cycle start.
Also fixes the UTC Calendar issue for end-of-month boundaries.
@AdrianSimionov
Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented Jun 5, 2026

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

Try subtracting one month first; if the resulting window does not
cover timeUntilReset, fall back to one year. Works correctly at
any point in monthly or annual billing cycles.
@AdrianSimionov
Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented Jun 5, 2026

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot removed the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Jun 5, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Jun 5, 2026
@AdrianSimionov
Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented Jun 5, 2026

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 5, 2026
@AdrianSimionov
Copy link
Copy Markdown
Author

API returns:

"planCode":"lite","planName":"Lite"

We need someone with the Yearly plan to tell us what the API returns.

Otherwise we could assume Monthly plans, which would catch majority of the use-cases, I cannot imagine someone paying for an yearly plan when AI is evolving so rapidly.

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

Labels

merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant