When multiple upgraded subscriptions expire in the same sweep, expire the due subscriptions first and resolve the downgrade target from the full due set instead of only the latest expired row.
This keeps users from remaining on an intermediate paid group after a chained upgrade sequence expires. Explicit downgrade_group still takes precedence, and active upgraded subscriptions keep the current group unchanged.
Reviewed after GHSA-hmwm-3f9g-x2v5, reported by adrgs and found by aisafe.io. We do not accept the advisory as a security vulnerability as submitted, but the report identified a subscription expiry business logic bug worth fixing.
Refs: GHSA-hmwm-3f9g-x2v5