{"record":{"id":"4b13fbc41a251075","repo":"Significant-Gravitas/AutoGPT","slug":"unable-to-cancel-your-subscription-right-now-plea","errorCode":null,"errorMessage":"Unable to cancel your subscription right now. Please try again or contact support.","messagePattern":"Unable to cancel your subscription right now\\. Please try again or contact support\\.","errorType":"http","errorClass":"HTTPException","httpStatus":502,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/v1.py","lineNumber":1152,"sourceCode":"\n    target_price_id = await get_subscription_price_id(tier, request.billing_cycle)\n\n    # Cancel: target NO_TIER. Schedule Stripe cancellation at period end;\n    # cancel_at_period_end=True lets the webhook flip the DB tier. No active\n    # sub (admin-granted or never-paid) or payment disabled → DB flip.\n    # NO_TIER is never priceable, so this branch always fires for cancel\n    # requests regardless of LD config.\n    if tier == SubscriptionTier.NO_TIER:\n        if payment_enabled:\n            try:\n                had_subscription = await cancel_stripe_subscription(user_id)\n            except stripe.StripeError as e:\n                logger.exception(\n                    \"Stripe error cancelling subscription for user %s: %s\",\n                    user_id,\n                    e,\n                )\n                raise HTTPException(\n                    status_code=502,\n                    detail=(\n                        \"Unable to cancel your subscription right now. \"\n                        \"Please try again or contact support.\"\n                    ),\n                )\n            if not had_subscription:\n                # No Stripe subscription drove this change (admin-granted or\n                # never-paid).\n                await set_subscription_tier(user_id, tier)\n            return await get_subscription_status(user_id)\n        await set_subscription_tier(user_id, tier)\n        return await get_subscription_status(user_id)\n\n    if not payment_enabled:\n        raise HTTPException(\n            status_code=422,\n            detail=f\"Subscription not available for tier {tier.value}\",","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/v1.py#L1134-L1170","documentation":"HTTP 502 from POST /credits/subscription when cancelling (target tier NO_TIER) fails because cancel_stripe_subscription raised a stripe.StripeError. Payment must be enabled for the user; the cancel path calls Stripe to cancel the active subscription and a Stripe-side failure is mapped to 502 with the exception logged.","triggerScenarios":"POST /credits/subscription with tier=BASIC (NO_TIER) while the user has an active paid Stripe subscription, and the Stripe cancel call errors.","commonSituations":"Stripe outage or timeout; subscription already cancelled in the Stripe dashboard causing a not-found error; wrong/stale Stripe API key; restricted-mode key missing the subscriptions:write permission.","solutions":["Retry after a short delay; check status.stripe.com if errors repeat","Verify the Stripe API key has write access to subscriptions (not a read-only key)","Inspect the backend log line 'Stripe error cancelling subscription' for the exact Stripe error code","If the subscription was already cancelled in Stripe, sync the user's tier via set_subscription_tier / admin tooling"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await api.cancelSubscription(); }\ncatch (e) { if (e.status === 502) { await backoffRetry(); } else throw e; }","preventionTips":["Retry cancellations with backoff once","Keep Stripe API keys valid and write-capable","Monitor status.stripe.com during incidents"],"tags":["stripe","subscription","cancellation","http-502"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}