Skip to content

feat: Add usage limit detection and upgrade prompt#1851

Merged
charlesvien merged 22 commits intomainfrom
04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling
Apr 23, 2026
Merged

feat: Add usage limit detection and upgrade prompt#1851
charlesvien merged 22 commits intomainfrom
04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented Apr 23, 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 23, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

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

greptile-apps Bot commented Apr 23, 2026

Prompt To Fix All With AI
This is a comment left during a code review.
Path: apps/code/src/shared/types/seat.ts
Line: 23

Comment:
**`PLAN_PRO` constant value changed — may break existing Pro seats**

The `PLAN_PRO` key was renamed from `"posthog-code-200-20260301"` to `"posthog-code-pro-200-20260301"`. Any existing seats stored in the database with the old `plan_key` value would no longer be matched by `isProPlan()`, causing those users to be treated as Free. This is safe only if the backend was already using the new key (making the old constant a bug) or if a migration has been coordinated. Worth explicitly confirming which direction the change goes before merging.

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/features/billing/components/SidebarUsageBar.tsx
Line: 49

Comment:
**`Math.ceil` vs `Math.round` inconsistency**

The text label uses `Math.round(usagePercent)` but the bar width uses `Math.ceil(usagePercent)`. At, say, 50.4% usage the label reads "50%" while the bar fills to 51%, making them visually disagree. Consider using the same rounding for both.

```suggestion
          style={{ width: `${Math.min(Math.round(usagePercent), 100)}%` }}
```

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/features/settings/components/sections/PlanUsageSettings.tsx
Line: 196

Comment:
**Spinner shown indefinitely when billing is disabled**

When `billingEnabled` is `false`, the condition `isLoading || !billingEnabled` shows a `<Spinner>` forever. In practice this section is probably only reachable when billing is enabled, but if it ever renders with `billingEnabled = false` the UI will spin indefinitely with no explanation. A cleaner approach would be to return `null` early, or show the "seat is loading" state rather than a persistent spinner.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: packages/agent/src/utils/gateway.ts
Line: 30-32

Comment:
**Missing `/v1/` version prefix**

All other gateway URL helpers (`getGatewayUsageUrl`, `getLlmGatewayUrl`) include a `/v1/` path segment, but `getGatewayInvalidatePlanCacheUrl` goes directly to `/invalidate-plan-cache`. If the backend endpoint lives under `/v1/invalidate-plan-cache`, every call will 404. Confirm the expected path with the gateway team.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Fix lint warnings across codebase" | Re-trigger Greptile

Comment thread apps/code/src/shared/types/seat.ts
Comment thread apps/code/src/renderer/features/billing/components/SidebarUsageBar.tsx Outdated
Comment thread packages/agent/src/utils/gateway.ts
@charlesvien charlesvien force-pushed the 04-21-add_fullscreen_expand_to_plan_preview branch from 578c274 to dc01db2 Compare April 23, 2026 01:31
@charlesvien charlesvien force-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch from d736f8f to 6e33eb0 Compare April 23, 2026 01:31
@charlesvien charlesvien changed the base branch from 04-21-add_fullscreen_expand_to_plan_preview to graphite-base/1851 April 23, 2026 01:32
@charlesvien charlesvien force-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch from 6e33eb0 to b580e94 Compare April 23, 2026 01:33
@charlesvien charlesvien changed the base branch from graphite-base/1851 to main April 23, 2026 01:33
@charlesvien charlesvien force-pushed the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch from dd42679 to 567e006 Compare April 23, 2026 01:56
@charlesvien charlesvien merged commit 05bd036 into main Apr 23, 2026
16 checks passed
@charlesvien charlesvien deleted the 04-21-extract_shared_isusageexceeded_util_and_gate_usage_polling branch April 23, 2026 03:48
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