fix(usage): separate subscription refresh from local refresh - #81
Conversation
|
Warning Review limit reached
More reviews will be available in 38 minutes and 6 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
Walkthrough本 PR 将订阅额度获取从本地报表刷新中拆分出来,新增 Usage Tab 的 provider 白名单、专用环境变量与刷新语义,并同步更新 Kimi、Z.ai、MiniMax Token Plan 的凭据读取、TUI 状态/帮助行、以及多语言 README 与 ADR。 Changes订阅额度边界与提供方流程
Sequence Diagram(s)sequenceDiagram
participant App
participant FetchEnabled as fetch_enabled
participant FetchProviders as fetch_providers
participant UsageProvider
App->>FetchEnabled: 启用的 provider IDs
FetchEnabled->>FetchProviders: 选中的 providers
FetchProviders->>UsageProvider: fetch()
UsageProvider-->>FetchProviders: outputs / error
FetchProviders-->>App: UsageFetchBatch
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
942ba1e to
7aa540e
Compare
Require the TUI Usage tab to opt into subscription providers before fetching remote quota data. Keep global r scoped to local report refreshes and use u for Usage-tab subscription refreshes. Closes #80
7aa540e to
1a9af1b
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/tokscale-cli/src/commands/usage/kimi.rs`:
- Around line 389-394: The refresh flow in kimi.rs only persists credentials
when refreshed.refresh_token is present, so an access token returned with
expires_in but no new refresh token is never saved. Update the refresh handling
around the stored_refresh_token and save_credentials logic to fall back to the
existing stored_refresh_token when refreshed.refresh_token is None, and still
persist the new access_token and expires_in. Ensure the code path that handles
token refresh keeps the old refresh token instead of requiring a new one every
time.
In `@crates/tokscale-cli/src/commands/usage/mod.rs`:
- Around line 89-90: `UsageProviderId` is missing the explicit `kimi-code` alias
for the `Kimi` provider, so configs using that name are not recognized. Update
the provider matching in `UsageProviderId`’s parsing logic to accept both `kimi`
and `kimi-code` as `Self::Kimi`, keeping the existing alias handling style used
for the other provider IDs.
In `@crates/tokscale-cli/src/tui/app.rs`:
- Around line 527-533: `App::new_with_cached_data()` is still loading
`Settings::load()` and then immediately calling
`maybe_fetch_subscription_usage_on_usage_entry()`, so Usage-tab tests can pick
up developer-local `usageProviders` and trigger real fetch behavior. Update the
`App` construction path to use isolated test settings for `make_usage_app()` and
`make_app_on()` in `usage.rs` and `footer.rs`, or guard the initial auto-fetch
inside `App::new_with_cached_data()` with `#[cfg(test)]` so tests do not depend
on local configuration or spawn subscription fetch threads.
In `@crates/tokscale-cli/src/tui/ui/footer.rs`:
- Around line 477-488: Replace the substring-based filtering in
subscription_status_message with an explicit subscription-only check instead of
matching any status containing “usage” or “subscription.” Update the App status
handling so usage-related messages like “Jumped to today’s usage” and “Returned
to daily usage” are not reused by usage_status_row_line; ideally add a dedicated
subscription status field or a strict whitelist of known subscription messages.
Use the subscription_status_message helper and the usage_status_row_line call
site to locate and narrow this logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 02b05219-6cd1-46cb-bd25-e2e00ddd7373
📒 Files selected for processing (15)
README.ja.mdREADME.ko.mdREADME.mdREADME.zh-cn.mdcrates/tokscale-cli/src/commands/usage/helpers.rscrates/tokscale-cli/src/commands/usage/kimi.rscrates/tokscale-cli/src/commands/usage/minimax.rscrates/tokscale-cli/src/commands/usage/minimax_tokenplan.rscrates/tokscale-cli/src/commands/usage/mod.rscrates/tokscale-cli/src/commands/usage/zai.rscrates/tokscale-cli/src/tui/app.rscrates/tokscale-cli/src/tui/settings.rscrates/tokscale-cli/src/tui/ui/footer.rscrates/tokscale-cli/src/tui/ui/usage.rsdocs/adr/0014-explicit-subscription-usage-boundary.md
💤 Files with no reviewable changes (1)
- crates/tokscale-cli/src/commands/usage/minimax.rs
There was a problem hiding this comment.
7 issues found across 15 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-cli/src/tui/ui/footer.rs">
<violation number="1" location="crates/tokscale-cli/src/tui/ui/footer.rs:237">
P3: Usage help row omits the `e` export shortcut even though the key remains active. Footer guidance is inconsistent with actual keybindings.</violation>
</file>
<file name="crates/tokscale-cli/src/tui/ui/usage.rs">
<violation number="1" location="crates/tokscale-cli/src/tui/ui/usage.rs:96">
P2: Usage loading text is keyed off local-report loading, so it can falsely claim subscription fetch is in progress. This breaks the new local-vs-subscription separation and misleads users in cache-display mode.</violation>
</file>
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
What changed
usageProviders.usageProviderslist as cache-display mode: the Usage tab may show cached data, but it will not send remote subscription requests.rscoped to local report refreshes; subscription refresh isuin the Usage tab only.minimax-token-plan-cnorminimax-token-plan-global.TOKSCALE_USAGE_KIMI_CODING_PLAN_API_KEY, while retaining Kimi Code OAuth credentials.Provider credential policy
Purpose-specific subscription credentials only:
TOKSCALE_USAGE_ZAI_CODING_PLAN_API_KEYTOKSCALE_USAGE_KIMI_CODING_PLAN_API_KEYor Kimi Code OAuth credentialsTOKSCALE_USAGE_MINIMAX_TOKEN_PLAN_CN_KEYTOKSCALE_USAGE_MINIMAX_TOKEN_PLAN_GLOBAL_KEYGeneral provider API keys such as
ZAI_API_KEY,GLM_API_KEY,KIMI_API_KEY,MINIMAX_API_KEY, andMINIMAX_API_TOKENare intentionally ignored for subscription quota lookups.Validation
cargo fmt --all -- --checkcargo test -p tokscale-cli usage -- --nocapturecargo test -p tokscale-cli footer -- --nocapturecargo test -p tokscale-cli app::tests::test_usage -- --nocapturecargo test -p tokscale-clicargo testCloses #80
Summary by CodeRabbit
新功能
u、r、R在 Usage 与本地报告中的不同刷新行为。文档