Port upstream 0.60.5: Kimi accepts monthly-only and partial ratio-pool Code API responses (stacked on #697) - #730
Conversation
Upstream 0.60.5 steipete#3694: accept Code API responses that report any supported window. Weekly is the primary lane and the 5-hour rate limit the secondary, matching the web path; an absent weekly quota stays an informational placeholder; the monthly pool is the Total usage lane and web enrichment only fills in a missing one. A response without any supported window is a parse error. A monthly-only snapshot drives Automatic metric selection.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. Comment |
UI proof (browser-use)Result: PASS on build
At the maintainer's direction, this proof drove the app's WebView2 over CDP with the browser-use CLI instead of CUA. It used no keyboard, mouse or focus. The proof windows stayed on the second display, and the kit settings turned the global shortcut off. Setup
Results
ValidationRun in the lane-A worktree on Rust 1.98.0.
ScreenshotsAll paths are under
The raw browser-use output is in Not blocking (found on
|
Summary
The Kimi Code API (
/coding/v1/usages) can report quota as ratio pools (usages.limit_5h,limit_7d,limit_month_total) and may leave some of them out. Before this change, a response without a usablelimit_5hpool failed with "unusable session quota pool", so a monthly-only account showed an error, and a ratio-pool response put the 5-hour pool under the "Weekly" label and the 7-day pool under "Rate Limit". This PR follows upstream 0.60.5 (PR steipete#3697, fixing steipete#3694), which v0.70.0 still uses.limit_7dpool, else the legacyusagecounters.limit_5hpool, else the first legacylimitsentry.limit_month_totalpool becomes thekimi-monthly"Total usage" lane with no browser sign-in. Web enrichment only fills that lane when the API did not report a usable one.Upstream reference
51ed16bdd3abe35ec53af99818e1b5f0d2a631d3("fix(kimi): decode Code API ratio quota pools", fixes Kimi Code (API key): ratio-pool /coding/v1/usages response fails to decode — "The data couldn’t be read because it is missing." steipete/CodexBar#3694), released in v0.60.5.KimiUsageSnapshot.toUsageSnapshotandKimiRatioPoolTests.swift, which add the 0.63.0 zero-placeholder cases already ported here.Ported / Deferred
rust/src/providers/kimi/):code_api::snapshot_from_code_api_responsebuilds each lane from its pool or falls back to that lane's legacy counters, and puts the monthly pool in thekimi-monthlyextra lane. It returns upstream's error when no window is usable.apply_subscription_windowskeeps an API monthly pool and only fills a missing one.is_equivalent_to_weekly_windowtreats a missing weekly as never equivalent, so the "Code 7-day" row is not hidden by a weekly placeholder.KimiProvider::automatic_metric_missing_core_is_terminalreturnsfalse. The trait doc incore/provider.rsnames this case.KimiRatioPoolTestscase is inratio_pool.rs, in upstream lane order. The 0.60.5 web-enrichment test (status 200 and 503) runs at the enrichment seam:fetch_via_code_apiapplies web stats only when the call succeeds.code_api.rstests now expect upstream lane order.monthly_blocking_tests.rschecks that an exhausted Code API monthly pool blocks both Code windows, and that a monthly-only response has nothing to block.usage_metric.rschecks that a monthly-only Kimi snapshot resolves Automatic, Session and Weekly to Total usage.docs/PROVIDERS.md, and a CHANGELOG entry.nil.UsageSnapshot.primaryis not optional here, so a missing weekly is an informational placeholder, the same shape as the existing "No active 5h session" row.nil. Both behaviors were already there before this PR.window, its window minutes stay unknown. Upstream assumes 300 minutes. A zerolimit_5hplaceholder is therefore not replaced by those counters. This behavior was already there before this PR.selectSingleMetricUsageWindowandProviderGrid'sgridPercent) do this for every provider with an informational primary.rust/src/core/provider.rswas already 1508 lines at the base and grows by 1 doc-comment line. Every other changed source file is under 1000 lines.Validation
Run on
bfb026a3.7b6e2688only adds the docs and the CHANGELOG line.cargo +1.98.0 fmt --all --check7b6e2688)cargo +1.98.0 clippy --workspace --all-targets -- -D warnings7b6e2688)cargo +1.98.0 test -p codexbar providers::kimicargo +1.98.0 test -p codexbar-desktop-tauri usage_metriccargo +1.98.0 test -p codexbarcargo +1.98.0 test -p codexbar-desktop-tauribootstrap_payload_exposes_every_provider_variant, see note belowpnpmcheck-locale, lint, test, build)The desktop failure is environment-dependent: the test reads the host's settings. It is the known #684 failure, fixed by #711, and fails the same way at the base.
Affected areas
UI proof
PASS on
7b6e2688: #730 (comment) (browser-use over WebView2 CDP, per the maintainer).monthly-only(upstream's Kimi Code (API key): ratio-pool /coding/v1/usages response fails to decode — "The data couldn’t be read because it is missing." steipete/CodexBar#3694 sample),monthly-42,missing-weekly,lanes,exhaustedandempty.monthly-only,lanesandexhausted.This PR stays a draft because it is stacked on #697.