fix(quota): elevate tier on quota-suspended resources during upgrade#240
Merged
mastermanas805 merged 3 commits intoJun 4, 2026
Merged
Conversation
ElevateResourceTiersByTeam (Razorpay subscription.charged webhook) filtered
on status IN ('active','paused'), so a tier upgrade did NOT raise the cap on
a quota-suspended resource. The worker's storage-quota enforcer flips a row
to status='suspended' when it exceeds its tier cap; without the elevation
reaching that row, "upgrade to restore access" was a no-op for the very
resource that tripped the limit — it stayed below the new (larger) cap's
reach.
Add 'suspended' to the status filter so the upgrade lifts the suspended row
to the new tier. This raises the cap only — it does NOT flip status back to
'active' or reverse the provider-side CONNECT/ACL REVOKE. That unsuspend
transition (re-measure usage against the new cap, status->active, provider
re-grant, resource.quota_unsuspended audit) lives in the WORKER's storage
scanner (sweep finding #3, out of this repo). Documented as a worker
follow-up in the function doc + test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
P1 (sweep finding #4) — quota-suspend recovery trap.
models.ElevateResourceTiersByTeam(called from the Razorpaysubscription.chargedupgrade webhook) filtered onstatus IN ('active','paused'), so a tier upgrade did not raise the cap on a quota-suspended resource.The worker's storage-quota enforcer flips a row to
status='suspended'when it exceeds its tier cap (migration 049). Because the elevation skipped suspended rows, "upgrade to restore access" was a no-op for the exact resource that tripped the limit — it kept its old (smaller) tier and stayed below the new cap's reach.Fix
Add
'suspended'to the status filter:This raises the cap only. It deliberately does not flip
statusback to'active'or reverse the provider-side CONNECT/ACLREVOKE— that unsuspend transition (re-measure usage against the new cap →status='active'+ provider re-grant +resource.quota_unsuspendedaudit) lives in the worker's storage scanner (sweep finding #3, out of this repo). I investigated the api tree: there is no api-side unsuspend path, and the suspend/unsuspend lifecycle audit kinds inaudit_kinds.goare explicitly documented as worker-produced. Documented the worker follow-up in the function doc + test.Caveat noted (from the sweep): for postgres/mongo a REVOKE-while-suspended can also block the customer from self-service deleting data to get under cap — so the worker's tier-aware re-measure (which an elevated tier now satisfies) is the recovery path, not customer delete. That's the #3 worker half.
Tests (pass against test Postgres)
TestElevate_Suspended_TierElevated— suspend@hobby-cap →ElevateResourceTiersByTeam(pro)→ suspended row's tier IS elevated to pro (status stayssuspended, pinning the worker boundary).TestElevate_SuspendedFilterIncludesSuspended— registry-style guard: inserts one row per non-terminal status (active/paused/suspended), asserts all three are elevated; fails if a future edit drops any from the filter.Worker follow-up (out of scope for this PR)
Sweep #3: worker storage scanner skips
status='suspended'rows so usage freezes and it never auto-unsuspends. Fix the worker to scanstatus IN ('active','suspended')(or re-measure live in the unsuspend loop) so an elevated-tier suspended resource gets re-evaluated and unsuspended.🤖 Generated with Claude Code