Repository navigation
fix(billing): re-throw on demotePublicAgentsOnTierDowngrade failure (closes #3694) - #3698
Merged
Merged
Conversation
…3694) When a Stripe webhook flips an org from a tier with API access to one without, demotePublicAgentsOnTierDowngrade must demote any public-marked agents to members_only and strip them from the org's brand.json — otherwise they stay publicly listed on a tier that doesn't allow public agents (silent entitlement leak). The call site at http.ts:3792 was wrapped in a try/catch that logged and continued. A transient DB error during demotion would silently leave stale public agents until the next tier change. Per js-protocol-expert review on #3691: "you've got an org row claiming the new tier with stale public agents — exactly the silent-swallow class you're trying to retire, just one layer down." Hoists the demote call outside the swallow-on-error block, alongside the core subscription UPDATE. They're a pair: UPDATE writes the new tier; demote enforces the corresponding agent visibility. Idempotent on retry (the helper takes FOR UPDATE on member_profiles, no-ops if no public agents remain) so a Stripe retry that re-fires the tier-downgrade webhook does the right thing. Closes the second of the three triage follow-ups from #3691. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
Closes #3694 (the second of three triage follow-ups from #3691).
When a Stripe webhook flips an org from a tier with API access to one without,
demotePublicAgentsOnTierDowngrademust demote anypublic-marked agents tomembers_onlyand strip them from the org's brand.json — otherwise they stay publicly listed on a tier that doesn't allow public agents (silent entitlement leak).The call site at
http.ts:3792was wrapped in atry/catchthat logged and continued. A transient DB error during demotion would silently leave stale public agents until the next tier change.Why hoist instead of just removing the inner try/catch
The previous structure had the demote call inside the outer swallow-on-error try, so removing the inner catch alone would let errors propagate to the outer swallow. Hoists the demote call outside that block, alongside the core subscription UPDATE — they're an entitlement pair:
membership_tierto the org rowmember_profiles+brand.jsonEither failing alone leaves a coherent state; both completing or both retrying is the correct behavior.
Idempotency check
Verified that
demotePublicAgentsOnTierDowngradeis safe to re-run after partial completion:member_profilesrow withFOR UPDATEpublic-visibility agents remain → returns null (no-op)remaining.length === currentAgents.lengthA Stripe retry that re-fires the tier-downgrade webhook will be a no-op if the previous attempt completed the agent visibility writes.
Test plan
npx tsc --noEmitcleanadmin-sync-revenue-backfill,admin-stripe-link-unlink)Refs
🤖 Generated with Claude Code