Skip to content

fix(customer): reject delete while a subscription has not ended - #5515

Merged
tothandras merged 1 commit into
mainfrom
claude/customer-delete-subscription-check-6a857c
Nov 13, 2026
Merged

tothandras merged 1 commit into
mainfrom
claude/customer-delete-subscription-check-6a857c

Conversation

@tothandras

@tothandras tothandras commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Customer deletion only rejected subscriptions that were active at that moment. A scheduled subscription survived the delete and later started for a deleted customer.

Both delete checks now reject any subscription that is not deleted and has no end or an end in the future:

  • The check inside the DeleteCustomer transaction uses a new adapter query, ListNotEndedSubscriptionIDs. activeSubscriptionFilter is unchanged, because customer expansions and the plan-key filter use it.
  • The subscription validator's ValidateDeleteCustomer lists subscriptions active from now onward instead of active at now.

API-visible change: deleting a customer that has a scheduled subscription now fails. Both error messages now say "active or scheduled subscriptions". The error code deleting_customer_with_active_subscriptions is unchanged.

Notes for reviewer

  • Not included: billing sync cleanup for customers that were already deleted before their subscription started. That follows separately.
  • A subscription created concurrently with the delete can still slip through. Create checks the customer before its own transaction, and the delete takes no subscription lock.
  • Tests: an adapter test for the query, a service test without request validators (the in-transaction check), and a full-stack test with the validator registered. I ran the customer, subscription, entitlement, subject, server, billing and subscription-sync suites locally against a throwaway Postgres 14 container, and golangci-lint on the changed packages.
  • No package README describes the delete rule, so none changed.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge within its stated scope.

Summary

Customer deletion now rejects active or scheduled subscriptions until they end or are deleted.

  • Customer deletion stops when a subscription is active or scheduled.

Acknowledged scope exclusions from tothandras: subscription creation racing with customer deletion remains deferred because creation checks the customer before its transaction and deletion takes no subscription lock. Billing cleanup for customers deleted before their subscriptions started will follow separately.

Reviews (1) · Last reviewed commit: "fix(customer): reject delete while a sub..." · Reviewed by Greptile

Summary by CodeRabbit

  • Behavior Changes
    • Customer deletion is now blocked while the customer has active or scheduled subscriptions. Cancel or delete those subscriptions before deleting the customer.
    • Deletion is allowed once no active or scheduled subscriptions remain.

Customer deletion only rejected subscriptions active now, so a scheduled
subscription survived the delete and later started for a deleted customer.

Both delete checks now cover every subscription that is not deleted and has
no end or an end in the future.
@tothandras
tothandras requested a review from a team as a code owner November 13, 2026 15:23
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Customer deletion checks now reject customers with active or scheduled subscriptions. The customer adapter lists subscriptions that have not ended, and the customer service and validator use subscription checks to block deletion.

Changes: Scheduled Subscription Deletion

Layer / File(s) Summary
List subscriptions that have not ended
openmeter/customer/adapter.go, openmeter/customer/adapter/customer.go, openmeter/customer/adapter/customer_test.go
The customer adapter adds a query for subscription IDs that have not ended or been deleted. Tests cover active, scheduled, past-ended, soft-deleted, and other-customer subscriptions.
Block deletion in the customer service
openmeter/customer/service/customer.go, openmeter/customer/errors.go, openmeter/subscription/service/customerdelete_test.go
DeleteCustomer rejects deletion when the query returns subscription IDs. Its error message includes scheduled subscriptions. A service test checks rejection before a scheduled subscription starts and successful deletion after the subscription is removed.
Validate deletion across customer endpoints
openmeter/subscription/validators/customer/validator.go, test/customer/customer.go, test/customer/customer_test.go
The validator checks subscriptions active from the current time onward. Customer tests verify that scheduled subscriptions block deletion until removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant DeleteCustomer
  participant CustomerAdapter
  participant SubscriptionQuery
  Caller->>DeleteCustomer: Request customer deletion
  DeleteCustomer->>CustomerAdapter: ListNotEndedSubscriptionIDs
  CustomerAdapter->>SubscriptionQuery: Query by customer and subscription dates
  SubscriptionQuery-->>CustomerAdapter: Matching subscription IDs
  CustomerAdapter-->>DeleteCustomer: Subscription IDs
  DeleteCustomer-->>Caller: Precondition failure if IDs exist
Loading

Suggested reviewers: turip, chrisgacsal, galexihu

Merge Risk: Minimal · up to b9ac1

Deleting a customer with a scheduled subscription now fails with a clear error, and tests cover both rejection and recovery. Add a release-note label to satisfy the label check before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: customer deletion is now rejected while a subscription has not ended, which matches the summary and objectives (scheduled and active subscriptions block deletion via L…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: customer deletion is now rejected while a subscription has not ended, which matches the summary and objectives (scheduled and active subscriptions block deletion via ListNotEndedSubscriptionIDs and ValidateDeleteCustomer). It uses the fix(customer) convention and is specific enough for a teammate scanning history.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6964dbe and b9ac1d2.

Files selected for processing: 9

  • openmeter/customer/adapter.go
  • openmeter/customer/adapter/customer.go
  • openmeter/customer/adapter/customer_test.go
  • openmeter/customer/errors.go
  • openmeter/customer/service/customer.go
  • openmeter/subscription/service/customerdelete_test.go
  • openmeter/subscription/validators/customer/validator.go
  • test/customer/customer.go
  • test/customer/customer_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@tothandras tothandras added the release-note/bug-fix Release note: Bug Fixes label Nov 13, 2026
@tothandras
tothandras merged commit 083608f into main Nov 13, 2026
34 of 35 checks passed
@tothandras
tothandras deleted the claude/customer-delete-subscription-check-6a857c branch November 13, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants