Skip to content

fix(kimi): refresh expired usage tokens#7883

Open
bbingz wants to merge 6 commits into
stablyai:mainfrom
bbingz:fix/kimi-usage-refresh
Open

fix(kimi): refresh expired usage tokens#7883
bbingz wants to merge 6 commits into
stablyai:mainfrom
bbingz:fix/kimi-usage-refresh

Conversation

@bbingz

@bbingz bbingz commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Refresh expired Kimi Code usage access tokens with the CLI's OAuth refresh endpoint before polling /usages.
  • Persist rotated Kimi credentials atomically with 0600 permissions so background usage polling keeps working after the CLI exits.
  • Re-read credentials when the Kimi CLI wins a concurrent refresh race, avoiding a false usage error.

Test Plan

  • pnpm exec vitest run --config config/vitest.config.ts src/main/rate-limits/kimi-fetcher.test.ts
  • pnpm run typecheck
  • pnpm run lint

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@bbingz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 25 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 reviews.

How do review 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 refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3d2a4e89-52eb-4dc4-b561-4a88756d493a

📥 Commits

Reviewing files that changed from the base of the PR and between 935befe and b111896.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json
📝 Walkthrough

Walkthrough

Adds endpoint-scoped Kimi credential resolution and a locked OAuth refresh flow with credential validation, atomic persistence, unauthorized handling, and race detection. Updates the rate-limit fetcher to refresh expired credentials and use resolved endpoints. Expands tests for locking, concurrency, persistence, refresh failures, CLI races, missing refresh tokens, and endpoint-specific files.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Fill in all required sections from the template, including Screenshots (or No visual change), Testing checklist, AI Review Report, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main user-visible change: refreshing expired Kimi usage tokens.
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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/rate-limits/kimi-fetcher.test.ts (1)

37-43: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the rename destination.

The mock updates fsState.credentials for any renameSync(from, to), and the refresh test only checks from. A regression that renames the temp file to the wrong target path would still pass; assert to is the expected credentials path or make the mock only commit when to matches it.

Also applies to: 190-193


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a5ccc8e7-cba3-4431-9e27-1810fe7b62b5

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1a777 and bfd9cc7.

📒 Files selected for processing (3)
  • src/main/rate-limits/kimi-fetcher.test.ts
  • src/main/rate-limits/kimi-fetcher.ts
  • src/main/rate-limits/kimi-oauth-refresh.ts

Comment thread src/main/rate-limits/kimi-oauth-refresh.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a19983bf-d43e-41e0-b1d7-01a97f719e26

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec55f4 and 7ff6925.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • package.json
  • src/main/rate-limits/kimi-credential-location.ts
  • src/main/rate-limits/kimi-fetcher.test.ts
  • src/main/rate-limits/kimi-fetcher.ts
  • src/main/rate-limits/kimi-oauth-refresh.test.ts
  • src/main/rate-limits/kimi-oauth-refresh.ts

Comment thread src/main/rate-limits/kimi-credential-location.ts Outdated
@bbingz bbingz force-pushed the fix/kimi-usage-refresh branch from 935befe to 7496c75 Compare July 10, 2026 10:17
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.

2 participants