Skip to content

Port upstream 0.67.0: count Mistral plan-covered tokens - #647

Open
Finesssee wants to merge 1 commit into
port/upstream-0.67.0from
port/micro-0.67.0-mistral-plan-tokens
Open

Finesssee wants to merge 1 commit into
port/upstream-0.67.0from
port/micro-0.67.0-mistral-plan-tokens

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Mistral token totals now count consumed units, while spend keeps counting billed units, so plan-covered usage (Le Chat, Vibe Code, included API allowance) is no longer reported as zero tokens.

  • BillingResponse gains chat and vibe_code.completion (JSON key vibe_code).
  • Tokens and cost aggregate across completion, chat, and vibe_code.completion; each model entry counts once toward model_count.
  • Per entry, tokens use value.or(value_paid); cost uses value_paid.or(value) times the price index.
  • Checked overflow still applies: TokenCounts::add_lane / add errors surface across all three categories.
  • ocr, connectors, audio, libraries, and fine-tuning stay cost-only.

Upstream reference

  • Release: CodexBar v0.67.0, Mistral plan-covered token counting (item 24 in the port audit).
  • Tag-pinned (v0.67.0) sources: Sources/CodexBarCore/Providers/Mistral/MistralModels.swift (chat, vibeCode, MistralVibeCodeUsageCategory), MistralUsageFetcher.swift (parseResponse, aggregateModel), docs/mistral.md; tests MistralTokenArithmeticTests.swift.

Ported / Deferred

  • Ported: the summary-level assertions of the upstream tests (plan-covered consumption across completion/chat/vibe_code with the fixture model at price 0.25, value/value_paid fallback, paid-zero not hiding overflow, checked overflow across API/chat/Vibe categories, cost-only categories not summing token lanes).
  • Deferred: the daily-bucket assertions (daily, last30DaysTokens); Win-CodexBar's Mistral provider has no daily buckets.
  • model_count follows the upstream loop (one increment per model entry per category), so a model name that appears in two categories is counted twice.

Validation

  • cargo +1.98.0 fmt --all: clean
  • cargo +1.98.0 test -p codexbar mistral -- --test-threads=4: 17 passed, 0 failed (6 new)
  • cargo +1.98.0 clippy -p codexbar --all-targets -- -D warnings: clean
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: not completed. The Tauri crate build script failed on a stale plugin-permissions path outside this worktree (...\cargo-target\cursor-cost-403\...\app_hide.toml); the Tauri crate is not touched by this PR.

Affected areas

  • Rust backend / provider (rust/src/providers/mistral/mod.rs)
  • Tauri shell
  • Frontend
  • Settings / bridge types

UI proof

Not applicable

… Vibe Code

Token totals now count consumed units (value, falling back to value_paid) across completion, chat, and vibe_code.completion; spend keeps counting billed units (value_paid, falling back to value). Other categories stay cost-only. Checked-overflow behavior applies across all three categories.
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 3fed7ccb-2152-4e90-b704-b60ea9fda3b5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude

Head reviewed: cc07049

Findings: none. The change matches the upstream 0.67.0 "mistral-plan-tokens" item: Le Chat (chat) and Vibe Code (vibe_code.completion) are aggregated with API completions; tokens count consumed units (value, falling back to value_paid) while spend counts billed units (value_paid, falling back to value); token sums stay checked for overflow; cost-only categories (ocr, connectors, audio, libraries) do not add to token lanes. The added tests cover each category, the fallbacks, cross-category aggregation, and the overflow path.

Nothing needed fixing, so no follow-up commit was pushed. Validation commands were not re-run because no files changed.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Validated 2026-10-02 at cc07049 (PR head):

  • Reviewed against the 0.67.0.md PR 17 spec (Mistral plan-covered tokens): the diff matches — chat + vibe_code.completion categories added to BillingResponse; token totals count consumed units (value falling back to value_paid) across completion/chat/vibe_code.completion; spend keeps counting billed units (value_paid falling back to value); model_count counts each model entry once; other categories (ocr, connectors, audio, libraries, fine-tuning) stay cost-only; checked-overflow (TokenCounts::add_lane) applies across all three token categories. Upstream MistralTokenArithmeticTests fixtures ported (input 1000 / output 500 / cached 300 / model 1 / cost 50; value-missing fallback 20 tokens cost 5; overflow across categories). No defects found; no changes needed.
  • cargo fmt --all --check — clean.
  • cargo test -p codexbar — 2166 passed / 0 failed / 1 ignored (mistral focused 17/17).
  • cargo test -p codexbar-desktop-tauri — 459 passed / 1 failed = the documented Isolate bootstrap payload test from real settings #684 bootstrap env baseline (79 vs 78, real-settings dependent; hermetic fix Make the bootstrap catalog test hermetic (#684) #711 is not on this base; also fails on unmodified base).
  • cargo clippy --all-targets -- -D warnings — the only three errors are the pre-existing main-history lint sites (alibabatokenplan/cli.rs:163 manual_range_contains, kiro/usage_limits.rs:315 + openai/subscription.rs:206 nonminimal_bool), all outside this diff (documented in QUEUE INTEGRATION FINDINGS; rustc 1.96 lint drift). The diff itself is clippy-clean.
  • No push needed (head cc07049 already on origin, verified via ls-remote); no fixes required.

Chain note: this PR gates #657 (Mistral plan detail) and through it #702/#717/#718; after #657 merges this head the chain is unblocked.

Finesssee added a commit that referenced this pull request Oct 2, 2026
Finesssee added a commit that referenced this pull request Oct 2, 2026
…ail lines (stacked on #647; keeps #697 monthly-block guards, adopts the #657 reset-description fallback and detail-line CSS)
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