Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

feat: Add usage limit detection and upgrade prompt - #1791

Closed
charlesvien wants to merge 19 commits into
graphite-base/1791from
04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling
Closed

feat: Add usage limit detection and upgrade prompt#1791
charlesvien wants to merge 19 commits into
graphite-base/1791from
04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling

Conversation

@charlesvien

@charlesviencharlesvien commented Apr 21, 2026

Copy link
Copy Markdown
Member

Problem

NOTE TO REVIEWER: You might not be able to test this without enabling the feature flag in a SEPERATE org, feel free to yolo stamp.

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

CleanShot 2026-04-21 at 22.43.53@2x.png

CleanShot 2026-04-21 at 22.10.51@2x.png

CleanShot 2026-04-21 at 22.44.01@2x.png

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
  6. Rremove assertBillingEnabled() from all store actions. The callers own that responsibility.

How did you test this?

Manually

@charlesvienGraphite App

charlesvien commented Apr 21, 2026

Copy link
Copy Markdown
MemberAuthor

@charlesviencharlesvien changed the title Add usage limit detection and upgrade promptfeat: Add usage limit detection and upgrade promptApr 21, 2026
@charlesvien
charlesvien marked this pull request as ready for review April 22, 2026 00:47
@greptile-apps

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/billing/stores/usageLimitStore.ts
Line: 22
Comment:
**Context cleared before close animation completes**`hide()` sets `context: null` at the same time as `isOpen: false`. Radix UI's `Dialog` plays an exit animation while its content is still mounted, so the description briefly switches from the "mid-task" copy to the "idle" copy mid-animation. Keeping `context` alive until the dialog is fully closed prevents the visual flicker.
```suggestion hide: () => set({ isOpen: false }),```
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: 44
Comment:
**Modal can be triggered before it is mounted**`useUsageLimitDetection()` runs unconditionally while `<UsageLimitModal />` is only rendered when `billingEnabled` is true. A mid-session flag flip from `true → false` leaves `isOpen: true` stranded in the store with no modal to render it. Consider hoisting the flag check to the call site or calling `hide()` when `billingEnabled` turns `false`.
How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Update seatStore.test.ts" | Re-trigger Greptile

Comment threadapps/code/src/renderer/features/billing/stores/usageLimitStore.ts Outdated
Comment threadapps/code/src/renderer/components/MainLayout.tsx Outdated
@charlesvien
charlesvienforce-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch 3 times, most recently from 49b3880 to ed3eff5CompareApril 22, 2026 08:03

@jonathanlabjonathanlab 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.

LGTM, nice work 🚢

Comment threadapps/code/src/renderer/features/billing/hooks/useUsageLimitDetection.ts Outdated
@charlesvien
charlesvienforce-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch 2 times, most recently from faf6b50 to 0d3ea48CompareApril 22, 2026 22:33
@charlesvien
charlesvienforce-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch from 0d3ea48 to a088ae4CompareApril 23, 2026 00:33
@charlesvien
charlesvien changed the base branch from main to graphite-base/1791April 23, 2026 01:24
@charlesvien
charlesvien deleted the branch graphite-base/1791April 23, 2026 01:24
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@charlesvien@jonathanlab