Repository navigation
Conversation
DELETE /v1/users/delete-account revoked Firebase auth and wiped Firestore but never canceled the user's Stripe subscription, so a paying user kept getting billed after deletion with no way to log back in and cancel (BasedHardware#6750). Cancel the subscription (best-effort, via the existing cancel_subscription helper) before the wipe, while the user doc is still readable. A Stripe error is logged but never blocks deletion. Adds regression tests. Fixes BasedHardware#6750
Greptile SummaryThis PR fixes a billing gap where deleting an account through
Confidence Score: 4/5The core fix is correct and the best-effort pattern is well-structured; the main risks are a misleading log message and the cancel_at_period_end=True choice leaving subscriptions technically active on Stripe until the period ends. The fix addresses a real billing gap and is correctly ordered (cancel before Firebase revoke, before Firestore wipe). The outer except block log message misattributes Firestore read failures as Stripe failures, which could mislead operators during incidents. The cancel_at_period_end=True semantic means the Stripe subscription remains status=active until the billing period ends — anything reading Stripe subscription status directly will still see it as active after account deletion. The test global _StubFinder is safe for the test.sh invocation pattern but would contaminate other tests in a combined pytest run. The cancel_at_period_end=True behavior in backend/routers/users.py deserves a second look if downstream systems (webhooks, entitlement checks) read Stripe subscription status directly rather than relying on Firebase auth being revoked. Important Files Changed
Reviews (1): Last reviewed commit: "fix(backend): cancel active Stripe subsc..." | Re-trigger Greptile |
- delete_account: the except only fires on the subscription lookup (cancel_subscription swallows its own errors), so reword the log to 'subscription lookup failed' and add a note. - test: install the meta-path stub finder only around the routers.users import, then remove it and pop the stub modules it created, so it can't affect other tests in a full-suite run.
Fixes #6750
Summary
DELETE /v1/users/delete-accountrevokes Firebase auth and wipes Firestore but never cancels the user's Stripe subscription. A paying user who deletes their account keeps getting billed, and since their auth and data are gone they can't log back in to self-serve the cancellation. This cancels the active subscription (best-effort) before the wipe.Root cause
delete_account(backend/routers/users.py) does: store feedback ->auth.delete_account(uid)(Firebase revoke) -> background Firestore wipe (_background_wipe_user_data->delete_user_data). None of those touch Stripe, so the subscription stays active. The delete-account redesign (#6669) explicitly deferred Pinecone/GCS but didn't mention Stripe, so this reads as an unintentional gap.Fix
Insert a best-effort cancel right after the feedback step and before the Firebase revoke, so the user doc (and
subscription.stripe_subscription_id) is still readable:It uses the existing
utils/stripe.pycancel_subscriptionhelper (cancel_at_period_end=True), which is idempotent and already error-tolerant. The try/except guarantees a Stripe outage can never strand an account half-deleted; aNonereturn or exception is logged so support can clean up manually.Behavior change
Testing
New
backend/tests/unit/test_delete_account_stripe_cancel.py(registered inbackend/test.sh):cancel_subscriptioncalled with the subscription id, deletion still proceedsstripe_subscription_id is None) -> Stripe not called{'status': 'ok'}Verified the paid-user test fails against current
main(no cancel happens) and passes with this change.Scope and possible follow-ups (kept out to keep this minimal)
cancel_at_period_end=Truehelper for consistency. If the intent is "deleted account means no active paid service," an immediate-cancel variant could be added.get_user_subscriptionwrites a default subscription doc if none exists. It's harmless here since the doc is wiped moments later, but a non-mutating read would be slightly cleaner.