fix(billing): key the usage email claim on the exact period start and anchor shared sums to their start - #8360
Merged
waleedlatif1 merged 3 commits intoSep 28, 2026
Conversation
… anchor shared sums to their start
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
waleedlatif1
deleted the
fix/usage-claim-exact-period-and-anchored-cache
branch
September 28, 2026 02:05
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
creditsPeriodon the period start's UTC day. Two distinct periods starting the same day with the same limit (a subscription replaced the day it began) shared one key, so the new period's email was suppressed. It now keys on the exact period start in epoch seconds, bound asbigintin both the pre-check SELECT and the claim UPDATE, which share one SQL builder. This has to land before v0.9.4 reaches main, because changing the key later would re-arm every current claimSET … PX TTL NXafter the sum finished, so a sum that ran long, or a SET resent after a reconnect, got a full fresh TTL on an older total. The write now anchors expiry to when the sum began:PX max(sumStartedAt + TTL + jitter − now, 5s) NX. The 5s floor keeps a slow sum briefly shared instead of re-run by every process. TSDoc states the resulting boundType of Change
Testing
usage-threshold-email.integration.ts: a period and its same-day replacement each deliver their own warning; it fails on staging's day keyreporting-usage-cache.integration.ts(real Redis):check:auditspassChecklist