Skip to content

fix(billing): re-read the usage gate often once a payer nears its limit - #9091

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/free-plan-usage-gate-fresh-read
Oct 15, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/free-plan-usage-gate-fresh-read

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The usage gate held a within-limit admission for 5 minutes, so a payer who crossed the limit kept running executions, tools, and copilot steps for up to that long — unbilled spend on free plans, spend past the cap on capped plans
  • An admission is now cached per entry by headroom: 10s when the payer or acting member is near its limit (headroom under the larger of $25 and 20% of the limit — every free-plan payer), the full 5 minutes otherwise, so paid pools with room keep today's cache and read load
  • Same rule for the direct-v1 account verdict cache used by copilot continuations
  • Refusal caching, unreadable-usage handling, and timeouts are unchanged

Type of Change

  • Bug fix

Testing

  • usage-gate-cache.test.ts: free payer (floor), large pool in its last 20% (share), member near its cap, ample headroom held for the full TTL — the three near-limit cases fail with the fix reverted
  • validate/route.test.ts: direct-v1 continuation near the limit is refused after the near-limit window — fails with the fix reverted
  • update-cost/route.test.ts passing; biome on changed files; full test/type-check/audits in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

The usage gate cached a within-limit admission for five minutes, so a payer
who crossed the limit kept running executions and copilot steps for up to
that long. On a free plan that is unbilled spend; on a capped plan it bills
past the cap. An admission is now held for 10s when the payer or the acting
member has less headroom than the larger of $25 and 20% of the limit (every
free-plan payer), and for the full five minutes otherwise. The direct-v1
account verdict cache follows the same rule.
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Oct 15, 2026 10:47pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable issues remain from this review.

Summary

The PR shortens cached usage admissions near a payer’s or member’s limit.

  • Usage checks refresh near-limit admissions after ten seconds.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Fresh usage answer] --> B{Admission allowed?}
  B -->|Yes| C{Payer or member near a limit?}
  C -->|Yes| D[Cache for 10 seconds]
  C -->|No| E[Cache for five minutes]
  B -->|No| F[Keep existing refusal behavior]
Loading

Reviews (2) · Last reviewed commit: "test(billing): drive the gate-cache cloc..." · Reviewed by Greptile

Comment thread apps/sim/app/api/copilot/api-keys/validate/route.test.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit c41323b into staging Oct 15, 2026
53 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/free-plan-usage-gate-fresh-read branch October 15, 2026 23:56

This branch was successfully deployed

1 active deployment
Preview — d00eefdb Deployed Oct 15, 2026 by vercel[bot]
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