Repository navigation
fix(web): follow the token-sharing usage-limit contract - #6971
Merged
Merged
Conversation
The gateway stores the ChatGPT plan limit to show the partner notice. The record never gated a request. Three gaps made the notice wrong. Read the documented sharing code. `subscription_sharing_usage_limit_exceeded` is the code OpenAI returns for this integration. The reader knew only `usage_limit_reached` and `insufficient_quota`, so a sharing limit wrote no record and the person saw a raw error with no way forward. Open the ChatGPT usage settings page. The notice opened the Codex dashboard. That page does not list the weekly limit a person sets for one app. An app limit and the plan allowance are separate meters. Clear the record when a request through the connection succeeds. OpenAI reports no reset time for an app limit, and a reset a person applies in ChatGPT restores the allowance early. The record outlived the limit, and only a reconnect or the recorded window cleared it.
Guard the `after` call that clears a recorded limit. `after` throws outside a request scope. The unguarded call could reject the sync and fail a request that already succeeded. Treat `token_expired` as a terminal refresh failure. OpenAI's "Errors and recovery" reference names it with the unusable refresh tokens. Kilo retried it and moved a request to another billing path instead of showing the reconnect message.
iscekic
marked this pull request as ready for review
September 29, 2026 18:32
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (8 files)
Verified the new sharing-limit marker, the settings URL, the success-path clear via Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
eshurakov
approved these changes
Sep 29, 2026
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Kilo stores the ChatGPT plan limit only to show the partner usage-limit notice. The record never gated a request: routing checks only
is_enabledandstatus === 'connected'(routing.ts:178). Three gaps made the notice wrong, and one gap made recovery wrong.subscription_sharing_usage_limit_exceededfor this integration. The reader knew onlyusage_limit_reachedandinsufficient_quota, so a sharing limit wrote no record. The person saw a raw 429 with no "Manage usage" action.https://chatgpt.com/settings/usage.token_expiredwas retryable. OpenAI's "Errors and recovery" reference names it with the unusable refresh tokens. Kilo retried it and served the request on another billing path instead of showing the reconnect message.The clear-on-success write runs in
after(). A guard stops a scheduling failure from changing the outcome of a request that succeeded.Verification
No manual test. A manual test needs a ChatGPT Plus or Pro subscription in the exhausted app-limit state, and no such account was available. Automated checks instead:
pnpm exec jest src/lib/ai-gateway/openai-chatgpt— 7 suites, 118 tests, including a real-database round trip for record and clear.pnpm exec jest src/lib/ai-gateway src/routers/openai-chatgpt-router.test.ts src/components/chatgpt— 668 tests.pnpm typecheck,pnpm lint, and the format check.Visual Changes
N/A
Reviewer Notes
usage_limit_reached_athas one reader,openAiChatGpt.status.insufficient_quotastays in the marker list. Our own partner key can answer with it, which would mis-attribute a platform quota to the person's plan. Not fixed here.