Skip to content

Prefer the more exhausted Kimi reading - #856

Merged
Finesssee merged 2 commits into
mainfrom
fix/kimi-more-exhausted
Oct 14, 2026
Merged

Finesssee merged 2 commits into
mainfrom
fix/kimi-more-exhausted

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Port of upstream steipete#4311 (fixes steipete#4306). The Kimi usages endpoint can report the same quota window twice with different readings. In steipete#4306 a 5-hour counter showed 100/100 next to a zero 5-hour ratio, and Windows showed 0%.

New rule: a legacy counter replaces the ratio window only when it has the same duration, is reliable, resets within 2 s of the ratio reset, and shows a strictly higher percent (clamped to 0..100). Equal readings keep the ratio metadata. The zero-only check, the monthly-pool guard and the reliable-weekly guard are gone, matching upstream.

Stacked on #854 (silent test sounds); the diff collapses to one commit once #854 merges.

Tests

  • New exhausted_legacy_counter_beats_zero_session_ratio_with_monthly_pool (fixture from Kimi: contradictory legacy/ratio response renders 100% on exhausted 5h window steipete/CodexBar#4306): session 100% with "100/100 credits", monthly Total lane 55.31%.
  • Updated three tests that encoded the old rule (renamed to the upstream names): nonzero ratios vs counts use the more exhausted reading; a monthly pool no longer blocks weekly reconciliation; the session override no longer needs reliable weekly counters.
  • Fail-without-fix: with the old rule restored, the new and updated tests fail.
  • cargo test --manifest-path rust/Cargo.toml --lib -- kimi → 112 passed; full suite 4287 passed (worker run)
  • clippy -D warnings clean; cargo fmt --all -- --check clean

Windows keeps its N/M credits description wording.

Summary by CodeRabbit

  • Bug Fixes
    • Usage estimates now reflect the higher reported usage when a ratio reading and reliable legacy counters cover the same window and reset period.
    • Equal or higher ratio readings retain their existing window details, and counter-based percentages stay within the 0–100% range.

Factory Agent added 2 commits October 14, 2026 14:03
When a reliable legacy counter and a ratio pool describe the same 5-hour or weekly window with resets within two seconds, use the counter if it reports strictly more usage. Drop the older zero-only rule, the monthly-pool guard, and the reliable-weekly-counters guard, matching upstream steipete#4311 (fixes steipete#4306). Equal readings keep the ratio metadata.
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

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: a19899e4-f041-4b79-9060-f24336807b21
📥 Commits

Reviewing files that changed from the base of the PR and between 48c3f0e and 13e30cf.

📒 Files selected for processing: 3
  • rust/src/providers/kimi/code_api.rs
  • rust/src/providers/kimi/ratio_pool.rs
  • rust/src/sound.rs

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

📝 Walkthrough

The Kimi provider now reconciles ratio windows with matching legacy counts. Windows test builds discard sound playback requests without initializing the playback queue.

Changes: Kimi ratio reconciliation

Layer / File(s) Summary
Resolve ratio windows against legacy counts
rust/src/providers/kimi/ratio_pool.rs, rust/src/providers/kimi/code_api.rs
The resolver compares ratio readings with matching reliable counts. It uses a clamped count percentage only when that percentage is higher, while retaining ratio metadata on ties. Updated call sites and tests cover weekly and session windows, including matching counts alongside a monthly pool.

Windows test playback

Layer / File(s) Summary
Skip playback queue initialization in tests
rust/src/sound.rs
Windows test builds return success without initializing the playback queue. The test exercises all events under both sound themes.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 13e30

No current issue requiring a change before merge was established; normal checks remain appropriate.

Pre-merge checks: Passed 7 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Ui Changes Include Windows Proof Warning The Kimi changes alter visible usage data. resolved_ratio_window can change the session or weekly used_percent and reset description, and snapshot_from_code_api_response places those values in t… Add screenshots or a clear proof note that records validation on a fresh Windows build, including the corrected Kimi usage display (for example, the exhausted session window and its N/M credits description).
Passed 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 is a short imperative summary that accurately describes the primary Kimi quota reconciliation change.
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 change stays within Kimi quota reconciliation and Windows test sound handling. It does not transfer, log, persist, or send provider identity, plan, account label, or email data. The shared sound c…
Secrets Handled Safely Passed PASS. The pull request changes only Kimi quota reconciliation tests/logic and Windows test sound handling. Added lines contain no token, cookie, API key, OAuth credential, authorization header, loggin…
No Unapproved Dependencies Passed The pull request changes only three Rust source files: rust/src/providers/kimi/code_api.rs, rust/src/providers/kimi/ratio_pool.rs, and rust/src/sound.rs. It does not change any Cargo.toml, `pa…
Full details: Ui Changes Include Windows Proof

Explanation

The Kimi changes alter visible usage data. resolved_ratio_window can change the session or weekly used_percent and reset description, and snapshot_from_code_api_response places those values in the usage snapshot used by rendered usage output. The PR description mentions the Windows 0% issue and test results, but it includes no screenshot or proof note from a fresh Windows build.

  • 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 718c15e into main Oct 14, 2026
4 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.

Kimi: contradictory legacy/ratio response renders 100% on exhausted 5h window

1 participant