Skip to content

fix: prevent duplicate suno task refunds via cas status update#6074

Open
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/b5241e091
Open

fix: prevent duplicate suno task refunds via cas status update#6074
feitianbubu wants to merge 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/b5241e091

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📝 变更描述 / Description

Suno 轮询里失败退款原来是直接调 RefundTaskQuota,没有并发保护。重叠轮询、超时 sweep、多实例同时命中有机率触发重复退款。

改法:同步视频任务的 CAS保护

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

触发一次suno 生成失败任务, 只退款一次
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved task status updates to prevent conflicting processes from overwriting results.
    • Ensured failed tasks are completed consistently and quota refunds occur only when appropriate.
    • Added clearer handling and logging when task updates fail or are already handled elsewhere.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Suno task update flow

Layer / File(s) Summary
Result application and CAS-protected refund
service/task_polling.go
Suno task results now derive failure state, update task timing and status fields, persist through UpdateWithStatus, and refund quota only after a winning failure transition.

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

Sequence Diagram(s)

sequenceDiagram
  participant SunoTaskResult
  participant updateSunoTasks
  participant TaskPersistence
  participant RefundTaskQuota
  SunoTaskResult->>updateSunoTasks: provide status and fail reason
  updateSunoTasks->>TaskPersistence: UpdateWithStatus(prevStatus)
  TaskPersistence-->>updateSunoTasks: CAS result
  updateSunoTasks->>RefundTaskQuota: refund non-zero quota after winning failure transition
Loading

Poem

A rabbit watched the task stream flow,
With CAS guarding status below.
If failure won the race just right,
Quota hopped back out of sight.
“No double refunds!” the bunny sings.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preventing duplicate Suno task refunds with CAS-based status updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant