Skip to content

feat: Add usage limit detection and upgrade prompt#1791

Open
charlesvien wants to merge 16 commits intomainfrom
04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling
Open

feat: Add usage limit detection and upgrade prompt#1791
charlesvien wants to merge 16 commits intomainfrom
04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented Apr 21, 2026

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

Copy link
Copy Markdown
Member Author

charlesvien commented Apr 21, 2026

@charlesvien charlesvien changed the title Add usage limit detection and upgrade prompt feat: Add usage limit detection and upgrade prompt Apr 21, 2026
@charlesvien charlesvien marked this pull request as ready for review April 22, 2026 00:47
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 22, 2026

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 thread apps/code/src/renderer/features/billing/stores/usageLimitStore.ts Outdated
Comment thread apps/code/src/renderer/components/MainLayout.tsx Outdated
@charlesvien charlesvien force-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch 2 times, most recently from 694fedc to ec7e74b Compare April 22, 2026 03:55
@charlesvien charlesvien force-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch from 49b3880 to ed3eff5 Compare April 22, 2026 08:03
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab left a comment

Choose a reason for hiding this comment

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

LGTM, nice work 🚢

const hasAlertedRef = useRef(false);

useEffect(() => {
if (!billingEnabled || !seatLoaded || isPro || !usage) return;
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.

nit: I'm seeing this condition replicated in a 5+ spots, it might be worth to extract these checks into their own helper.

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