Repository navigation
Description
Spun out of #3623 step 5 (#3691).
What
`http.ts:3782` swallows failures in `demotePublicAgentsOnTierDowngrade`:
```typescript
if (oldTier && oldTier !== subUpdate.membership_tier) {
const { demotePublicAgentsOnTierDowngrade } = await import('./services/agent-visibility-enforcement.js');
try {
await demotePublicAgentsOnTierDowngrade(...);
} catch (err) {
logger.warn({ err, orgId: org.workos_organization_id }, 'Failed to demote public agents on tier downgrade');
}
}
```
Failure mode: org's tier downgrades (or full cancellation), but the public-agent demotion fails transiently → agents stay marked public on a tier that doesn't include public agents → entitlement-class leak that persists silently until the next tier change or admin notice.
Why this matters
Per js-protocol-expert review on #3691:
"You've changed the failure surface: previously the SELECT failure was swallowed and the org silently skipped... but the bigger issue: the UPDATE's correctness depends on `oldTier` being read from the current row, but `oldTier` is then consumed inside the try block at 3792 for tier-downgrade enforcement. If the UPDATE succeeds but the downgrade enforcement fails (swallowed at 3801), you've got an org row claiming the new tier with stale public agents. That's exactly the silent-swallow class you're trying to retire — you just moved it one layer down."
The customer.subscription.* core UPDATE re-throw fix (#3691) was the load-bearing change for entitlement; this is the next link in the chain.
Bounded scope
Per the js-protocol-expert rule for catch-block audits:
Stop when the catch block's failure mode is non-customer-facing AND non-financial. The cut:
- Catches around DB writes that drive entitlement, revenue, or audit trail → re-throw
- Catches around Slack/email/notifications/cache invalidation → keep swallow
- Catches around `await import(...)` of optional modules → keep swallow
`demotePublicAgentsOnTierDowngrade` is the first category (drives entitlement: "agents stay public when tier doesn't allow public agents"). The fix is to re-throw, letting Stripe retry. Need to verify the function is idempotent first — a Stripe retry that re-fires the demotion should be a no-op if agents are already private.
Done state
- Verify `demotePublicAgentsOnTierDowngrade` is idempotent on retry
- Re-throw on failure
- Test: simulate failure mid-demotion, assert Stripe retry completes successfully and agents end up demoted
Refs
- Catch-block audit context: fix(billing): re-throw on core subscription UPDATE failure + relink integration tests (#3623 step 5) #3691
Activity
fix(billing): re-throw on demotePublicAgentsOnTierDowngrade failure (#…