Skip to content

feat(balances): describe the blocking cap on limit_reached - #3249

Merged
charlietlamb merged 8 commits into
charlie/alert-basis-firingfrom
charlie/alert-basis-limit-reached
Sep 3, 2026
Merged

feat(balances): describe the blocking cap on limit_reached#3249
charlietlamb merged 8 commits into
charlie/alert-basis-firingfrom
charlie/alert-basis-limit-reached

Conversation

@charlietlamb

@charlietlamb charlietlamb commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Layer 5 of 6 (limit_reached). Base: #3248.

balances.limit_reached carries a usage_limit block (limit, interval, anchor, usage, remaining, window bounds) when a usage limit blocked the event, resolved from the FullSubject through the same window-limit helper the alerts use. The schema also declares the filter field the payload was already sending.

Test: limit-reached-usage-limit-block.test.ts, green locally.

Greptile Summary

The PR expands balances.limit_reached so FullSubject-backed usage-limit events describe the blocking cap and its live window.

  • [Improvements, Bug fixes] Selects the tracked feature’s exhausted usage limit with the least remaining headroom and sources the filter from that same cap.
  • [API changes] Adds the optional filter and usage_limit fields to the shared webhook schema.
  • [Improvements] Adds integration coverage for unfiltered caps, filtered caps, and included-allowance events.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
server/src/internal/balances/trackWebhooks/checkLimitReached.ts Connects FullSubject-backed blocking-limit resolution to the limit-reached webhook and emits the selected cap and filter together.
server/src/internal/balances/trackWebhooks/limitReached/findBlockingUsageLimit.ts Resolves matching tracked-feature window limits, measures their current usage, and selects the exhausted cap with the least headroom.
shared/api/webhooks/balances/balancesLimitReached.ts Declares the previously emitted filter and the new optional usage-limit details in the shared webhook contract.
server/tests/integration/balances/track/limit-reached/limit-reached-usage-limit-block.test.ts Covers usage-limit window details, filtered-cap metadata, and omission for included-allowance events.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Track usage] --> B[Evaluate updated subject]
  B --> C{Usage limit blocked?}
  C -- No --> D[Emit limit event without usage_limit]
  C -- Yes --> E[Resolve tracked-feature window limits]
  E --> F[Select exhausted cap with least headroom]
  F --> G[Emit matching filter and usage_limit block]
Loading

Reviews (17): Last reviewed commit: "fix(balances): limit_reached filter alwa..." | Re-trigger Greptile

Context used:

@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

2 Skipped Deployments
Project Deployment Actions Updated
checkout Ignored Ignored Sep 3, 2026 5:38pm UTC
landing-page Ignored Ignored Sep 3, 2026 5:38pm UTC

Request Review

Comment thread server/src/internal/balances/trackWebhooks/checkLimitReached.ts

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

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread shared/api/webhooks/balances/balancesLimitReached.ts
Comment thread server/src/internal/balances/trackWebhooks/fireTrackWebhooks.ts Outdated
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 7dea514 to 90b5494 Compare September 3, 2026 12:40
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 90b5494 to 3fdd89b Compare September 3, 2026 12:41
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 3fdd89b to 5f97378 Compare September 3, 2026 12:43
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 5f97378 to 45006fb Compare September 3, 2026 12:44
Comment thread server/src/internal/balances/trackWebhooks/checkLimitReached.ts Outdated
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 45006fb to d27cbf9 Compare September 3, 2026 12:51
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from d27cbf9 to 125daa8 Compare September 3, 2026 12:53
Comment thread server/src/internal/balances/trackWebhooks/checkLimitReached.ts Outdated
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 125daa8 to 53928b4 Compare September 3, 2026 13:04
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 53928b4 to b978a0b Compare September 3, 2026 13:20
Comment thread server/src/internal/balances/trackWebhooks/checkLimitReached.ts Outdated
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch 2 times, most recently from f1c1a62 to eb7bb83 Compare September 3, 2026 14:10
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch 4 times, most recently from 1042127 to 924354e Compare September 3, 2026 15:49
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 924354e to 6920a1e Compare September 3, 2026 15:58
Comment thread server/src/internal/balances/trackWebhooks/limitReached/findBlockingUsageLimit.ts Outdated
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 6920a1e to b3c694b Compare September 3, 2026 16:03
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from b3c694b to be41d80 Compare September 3, 2026 16:15
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from be41d80 to 3f08772 Compare September 3, 2026 16:25
Comment thread server/src/internal/balances/trackWebhooks/limitReached/findBlockingUsageLimit.ts Outdated
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from 3f08772 to c552f5f Compare September 3, 2026 17:17
@charlietlamb
charlietlamb force-pushed the charlie/alert-basis-limit-reached branch from c552f5f to 3ecb60e Compare September 3, 2026 17:38
@charlietlamb
charlietlamb merged commit 5395836 into dev Sep 3, 2026
19 checks passed
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