Skip to content

feat: Add usage limit detection and upgrade prompt#1750

Closed
charlesvien wants to merge 3 commits intomainfrom
04-20-add_usage_limit_detection_and_upgrade_prompt
Closed

feat: Add usage limit detection and upgrade prompt#1750
charlesvien wants to merge 3 commits intomainfrom
04-20-add_usage_limit_detection_and_upgrade_prompt

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented Apr 21, 2026

Problem

Free-tier users have no visibility into usage limits until requests start failing silently.

Changes

  1. Extract useUsage hook from PlanUsageSettings into shared billing/hooks for reuse
  2. Add useUsageLimitDetection hook to detect when free users exceed sustained/burst limits
  3. Add UsageLimitModal with context-aware messaging (mid-task vs idle)
  4. Add SidebarUsageBar showing usage percentage and upgrade link
  5. Gate all billing UI behind posthog-code-billing feature flag

How did you test this?

Manually

@charlesvien charlesvien changed the title Add usage limit detection and upgrade prompt feat: Add usage limit detection and upgrade prompt Apr 21, 2026
Copy link
Copy Markdown
Member Author

charlesvien commented Apr 21, 2026

@charlesvien charlesvien marked this pull request as ready for review April 21, 2026 03:47
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch from 93df89e to 200093b Compare April 21, 2026 03:48
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from 149e7bd to 1bfa879 Compare April 21, 2026 03:48
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 21, 2026

Prompt To Fix All With AI
This 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

Comment thread apps/code/src/renderer/features/billing/components/SidebarUsageBar.tsx Outdated
Comment thread apps/code/src/renderer/components/MainLayout.tsx
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from fd97931 to 6d13e10 Compare April 21, 2026 03:56
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch from 200093b to b51fcb1 Compare April 21, 2026 03:56
@charlesvien charlesvien marked this pull request as draft April 21, 2026 04:47
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from 6d13e10 to f4b8464 Compare April 21, 2026 18:57
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch 2 times, most recently from 7353f59 to 28d67c4 Compare April 21, 2026 19:07
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from f4b8464 to 9ea6dd3 Compare April 21, 2026 19:07
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch from 28d67c4 to f3aebc9 Compare April 21, 2026 19:25
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from 9ea6dd3 to fed1d49 Compare April 21, 2026 19:25
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch from f3aebc9 to a595db2 Compare April 21, 2026 19:28
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from fed1d49 to 56233bb Compare April 21, 2026 19:28
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch from a595db2 to bd70b17 Compare April 21, 2026 19:47
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from 56233bb to 8e826ff Compare April 21, 2026 19:47
@charlesvien charlesvien force-pushed the 04-20-add_auto_permission_mode_for_claude_adapter branch 2 times, most recently from fe61322 to d027c20 Compare April 21, 2026 19:57
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from 8e826ff to 6d9995e Compare April 21, 2026 19:57
@charlesvien charlesvien changed the base branch from 04-20-add_auto_permission_mode_for_claude_adapter to graphite-base/1750 April 21, 2026 20:05
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from 6d9995e to a4b94db Compare April 21, 2026 20:06
@graphite-app graphite-app Bot changed the base branch from graphite-base/1750 to main April 21, 2026 20:06
@charlesvien charlesvien force-pushed the 04-20-add_usage_limit_detection_and_upgrade_prompt branch from a4b94db to 2d129b1 Compare April 21, 2026 20:06
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.

1 participant