fix: keep subscription pre-consume refund atomic (#5556) - #6089
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughSubscription refunds now reverse quota usage through the same database transaction that updates the pre-consume record. A shared helper handles locking and validation, while integration tests verify idempotent reversal and refunded record state. ChangesSubscription refund consistency
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant BillingSession
participant RefundSubscriptionPreConsume
participant UserSubscription
participant SubscriptionPreConsumeRecord
BillingSession->>RefundSubscriptionPreConsume: refund request
RefundSubscriptionPreConsume->>UserSubscription: lock and decrement AmountUsed
RefundSubscriptionPreConsume->>SubscriptionPreConsumeRecord: mark record refunded
RefundSubscriptionPreConsume-->>BillingSession: commit transaction
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@Calcium-Ion @t0ng7u 麻烦有空时 review 一下这个 PR。 范围:仅 #5556 — 订阅预扣退款在同一事务内回退 |
1a48572 to
26ed8ca
Compare
|
Rebased onto latest Same conflict surface as #6090: Local verification:
|
Important
📝 变更描述 / Description
将订阅预扣退款改为在同一数据库事务内回退 user_subscriptions.amount_used,并标记 subscription_pre_consume_records 为 refunded。原先在事务中调用 PostConsumeUserSubscriptionDelta 会新开事务,可能出现额度已退回但记录状态未更新,导致重试重复退款。
This PR was AI-assisted and manually reviewed before submission.
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit
Bug Fixes
Tests