feat: Add usage limit detection and upgrade prompt#1750
Closed
charlesvien wants to merge 3 commits intomainfrom
Closed
feat: Add usage limit detection and upgrade prompt#1750charlesvien wants to merge 3 commits intomainfrom
charlesvien wants to merge 3 commits intomainfrom
Conversation
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Apr 21, 2026
93df89e to
200093b
Compare
149e7bd to
1bfa879
Compare
Prompt To Fix All With AIThis is a comment left during a code review.
Path: apps/code/src/renderer/features/billing/components/SidebarUsageBar.tsx
Line: 16-18
Comment:
**Duplicated `isExceeded` logic (OnceAndOnlyOnce violation)**
The same three-field check (`is_rate_limited || sustained.exceeded || burst.exceeded`) is written inline here and again as the `isExceeded` helper function in `useUsageLimitDetection.ts`. If the limit-detection criteria ever change (e.g. a new bucket is added), both places need updating. Extract `isExceeded` from `useUsageLimitDetection` into a shared util (e.g. `billing/utils.ts`) and import it here.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: apps/code/src/renderer/components/MainLayout.tsx
Line: 46
Comment:
**Usage API polled for every user, regardless of billing flag or plan**
`useUsageLimitDetection()` is called unconditionally here, which internally calls `useUsage()` unconditionally (React hooks rule prevents conditional calls at the call-site, but the query itself has no `enabled` guard). The result is that a usage API request fires every 60 seconds for Pro users and for users without the `posthog-code-billing` flag — whose data is immediately discarded by the early-return inside the `useEffect`.
Consider threading an `enabled` option through `useUsage` so the query can be disabled upfront:
```ts
// useUsage.ts
export function useUsage({ enabled = true }: { enabled?: boolean } = {}) {
const { data: usage, isLoading } = useQuery({
...trpc.llmGateway.usage.queryOptions(),
enabled,
refetchInterval: focused && enabled ? USAGE_REFETCH_INTERVAL_MS : false,
refetchIntervalInBackground: false,
});
return { usage: usage ?? null, isLoading };
}
```
Then in `useUsageLimitDetection`:
```ts
const { usage } = useUsage({ enabled: billingEnabled && !isPro });
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Add usage limit detection and upgrade pr..." | Re-trigger Greptile |
fd97931 to
6d13e10
Compare
200093b to
b51fcb1
Compare
6d13e10 to
f4b8464
Compare
7353f59 to
28d67c4
Compare
f4b8464 to
9ea6dd3
Compare
28d67c4 to
f3aebc9
Compare
9ea6dd3 to
fed1d49
Compare
f3aebc9 to
a595db2
Compare
fed1d49 to
56233bb
Compare
a595db2 to
bd70b17
Compare
56233bb to
8e826ff
Compare
fe61322 to
d027c20
Compare
8e826ff to
6d9995e
Compare
6d9995e to
a4b94db
Compare
d027c20 to
8a9408d
Compare
a4b94db to
2d129b1
Compare
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.

Problem
Free-tier users have no visibility into usage limits until requests start failing silently.
Changes
How did you test this?
Manually