feat: Add immediate graph deprovisioning with subscription cancellation#657
Conversation
- Introduced `CancelSubscriptionRequest` model to handle subscription cancellation requests. - Updated subscription cancellation logic to support immediate cancellation with confirmation. - Enhanced logging for subscription cancellation events. - Added handling for immediate cancellation of graph subscriptions, redirecting to the delete-graph operation. - Implemented new `BillingAccountCredit` model to track credits issued to organizations. - Updated billing subscription model to include `cancellation_type` for tracking cancellation intent. - Added tests for subscription cancellation scenarios, including immediate and period-end cancellations. - Created tests for the delete-graph operation, ensuring proper authorization and subscription checks.
…tions and enhance delete-graph operation documentation
|
@claude please review this PR |
|
Claude finished @jfrench9's task in 2m 54s —— View job PR Review: feat: Add immediate graph deprovisioning with subscription cancellation
Overall this is well-structured work — the two-mode design ( Bugs1. Wrong SecurityAuditLogger.log_security_event(
event_type=SecurityEventType.AUTH_TOKEN_INVALID, # ← wrong type
...
"action": "stripe_cancel_failed_during_delete_graph",
2. else:
self.ends_at = self.current_period_end # None if never activatedA subscription in
Suggested fix: add an explicit guard in if not immediate:
if self.current_period_end is None:
raise ValueError(
f"Cannot defer cancellation for subscription {self.id}: "
"current_period_end is not set (subscription may not have been activated)."
)
self.ends_at = self.current_period_end…and/or add a pre-flight check in Design Notes3. Identical function defined at 4. Both 5. Body parameter inconsistency in body: CancelSubscriptionRequest = ..., # graphs/subscriptions.py
body: CancelSubscriptionRequest = Body(default_factory=CancelSubscriptionRequest), # billing/subscriptions.pyThe 6. import logging
logger = logging.getLogger(__name__) # ← not the project's get_loggerEvery other router in the codebase uses Test CoverageThe new test suite in
Summary
The two bugs (#1 and #2) should be fixed before merging; the rest are improvements that can be tracked separately. |
…isplay name resolution
|
@claude have we addressed all issues worth fixing? |
|
Claude finished @jfrench9's task in 1m 28s —— View job Review issue status — all bugs fixed, one design note outstandingHere's the current state of each item from the previous review: Bug #1 — Wrong
Bug #2 — Two-layer fix landed:
Nit #5 — Body parameter inconsistency ✅ Fixed
Nit #6 —
Design #3 — Logic is centralized in Design #4 —
Summary
All blocking items are resolved. The remaining design note (#4) is not a blocker — a short comment in the billing router would close it, but it can also be tracked separately. This is ready to merge. |
Summary
Implements immediate graph deprovisioning by adding subscription cancellation logic that triggers resource cleanup when a graph is deleted. This replaces or augments the previous end-of-period cancellation behavior with an immediate cancellation flow, ensuring that billing and infrastructure are promptly reconciled when users delete a graph.
Key Accomplishments
Billing & Subscription Cancellation
CancelSubscriptionRequestAPI model to formally represent cancellation requestsrouters/graphs/subscriptions.py) to manage the relationship between graph lifecycle and subscription stateGraph Delete Operation
delete-graphoperation inrouters/graphs/operations.pywith comprehensive logic that coordinates subscription cancellation as part of graph deletionmodels/api/graphs/operations.pyInfrastructure & Lifecycle Sensors
Observability
Database Migration
ac32cd15e221_immediate_cancelto support the new immediate cancellation fields on the subscription modelBreaking Changes
Testing
tests/routers/graphs/test_delete_graph_op.py— comprehensive coverage of the delete-graph operation including edge cases around subscription statetests/routers/billing/test_subscriptions.py(+339 lines) andtests/routers/graphs/test_subscriptions_router.py(+261 lines) significantly expanded to cover new cancellation flowstests/dagster/test_graph_lifecycle.pyfor the updated lifecycle sensor behaviortests/models/core/billing/test_subscription.pyfor new subscription model fieldsInfrastructure Considerations
🤖 Generated with Claude Code
Branch Info:
feature/graph-immediate-deprovisionmainCo-Authored-By: Claude noreply@anthropic.com