Skip to content

Fix task polling result URLs and reset locking - #5975

Closed
iranyxiao-lab wants to merge 1 commit into
QuantumNous:mainfrom
iranyxiao-lab:codex/fix-task-polling-subscription-reset
Closed

iranyxiao-lab wants to merge 1 commit into
QuantumNous:mainfrom
iranyxiao-lab:codex/fix-task-polling-subscription-reset

Conversation

@iranyxiao-lab

@iranyxiao-lab iranyxiao-lab commented Jul 7, 2026 •

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 本描述已按本次变更人工整理为简洁摘要,没有直接粘贴未经整理的 AI 输出。
  • AI 辅助声明:本 PR 的代码与说明由 Codex 辅助生成,提交者 git 身份不是仓库近期核心作者。

📝 变更描述 / Description

修复两个异步任务和订阅重置相关问题:

  1. 任务轮询解析 New API 响应时改用 dto.TaskResponse[dto.TaskDto],读取顶层 result_url 并保存到任务私有结果 URL。这样 New API 作为上游异步任务服务时,成功任务不会因为按 model.Task 解析而丢失结果地址。
  2. 管理员重置用户订阅/套餐订阅时改用现有 lockForUpdate(tx) helper。GORM v2 会忽略旧的 Set("gorm:query_option", "FOR UPDATE"),该 helper 能在支持的数据库上生成行锁,并在 SQLite 下保持兼容。

补充了一个回归测试,覆盖 New API TaskDto.result_url 轮询结果保存流程。

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。已注意到 fix video task successful upstream result parsing #5805/fix(task): support xAI grok-imagine-video task polling #5927 与任务轮询相关,但它们没有覆盖顶层 TaskDto.result_url 解析,也没有覆盖订阅重置行锁问题。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

通过:

go test ./service -run "TestUpdateVideoTasksPreservesNewAPITaskDtoResultURL|TestUpdateVideoTasks"
go test ./model -run "TestAdminReset|TestLockForUpdate|TestSubscription"

补充验证:

go test ./model ./service

结果:./model 通过;./service 中现有的 channel affinity usage cache 用例失败,失败项为 TestObserveChannelAffinityUsageCacheByRelayFormat_MixedMode 和 TestObserveChannelAffinityUsageCacheByRelayFormat_UnsupportedModeKeepsEmpty。这两个失败与本 PR 修改的任务轮询和订阅重置代码无关。

Summary by CodeRabbit

  • Bug Fixes
    • Improved subscription reset handling for admins by making record locking more reliable.
    • Fixed task polling so video task results now preserve the correct result URL from the newer response format, with a fallback when the URL is missing.
    • Added coverage for the updated task polling behavior to help prevent regressions.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5cbeca04-8c00-4573-a556-6df9fa0484fa

📥 Commits

Reviewing files that changed from the base of the PR and between becc18e and 05b5ff1.

📒 Files selected for processing (3)
  • model/subscription.go
  • service/task_polling.go
  • service/task_polling_test.go

Walkthrough

This PR fixes two issues: subscription reset transactions now use a lockForUpdate helper instead of an ineffective GORM v1-style query option for row locking, and video task polling parses new-format API responses as dto.TaskDto to correctly preserve result_url, with a fallback to FailReason when empty. Tests are updated accordingly.

Changes

Subscription Reset Locking

Layer / File(s) Summary
Replace ineffective query-option locking
model/subscription.go
adminResetUserSubscriptionsByPlanTx and adminResetPlanSubscriptionsTx now use lockForUpdate(tx) instead of tx.Set("gorm:query_option", "FOR UPDATE") for active subscription queries.

Video Task Result URL Parsing

Layer / File(s) Summary
Parse TaskDto response and preserve result URL
service/task_polling.go
updateVideoSingleTask parses new-format responses as dto.TaskResponse[dto.TaskDto], maps ResultURL (trimmed) to taskResult.Url, and falls back to trimmed FailReason when a Success status has an empty ResultURL.
Test adaptor support and new coverage
service/task_polling_test.go
taskPollingFetchAdaptor gains a responseBody map so FetchTask can return custom per-task payloads; a new test verifies UpdateVideoTasks preserves ResultURL from a dto.TaskDto-based response.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Poller as UpdateVideoTasks
    participant Adaptor as TaskAdaptor
    participant Parser as updateVideoSingleTask
    participant DB as Task Storage

    Poller->>Adaptor: FetchTask(taskID)
    Adaptor-->>Poller: HTTP response (TaskDto payload)
    Poller->>Parser: parse response body
    Parser->>Parser: unmarshal as dto.TaskResponse[dto.TaskDto]
    alt Success and ResultURL present
        Parser->>Parser: set taskResult.Url = trimmed ResultURL
    else Success and ResultURL empty
        Parser->>Parser: set taskResult.Url = trimmed FailReason
    end
    Parser->>DB: save task with PrivateData.ResultURL
Loading

Estimated code review effort: 2 (Simple) | ~12 minutes

Poem

A lock that slipped through GORM's old net,
now holds the row tight, no regret. 🔒
The task's true URL, once lost in the fray,
hops home safe through the trimmed FailReason way. 🐇
Two bugs squashed, my whiskers twitch with glee!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the two main changes: task polling result URLs and subscription reset locking.
Linked Issues check ✅ Passed The changes address both linked requirements by preserving New API result_url values and replacing the ineffective GORM query option with row locking.
Out of Scope Changes check ✅ Passed The modified code stays within the linked objectives and includes only the polling and locking fixes plus a regression test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@iranyxiao-lab

Copy link
Copy Markdown
Author

Superseded by #5976, which uses a non-codex branch name as requested.

@iranyxiao-lab
iranyxiao-lab deleted the codex/fix-task-polling-subscription-reset branch July 7, 2026 07:53
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.

任务轮询丢失 result_url 且订阅重置行锁未生效

1 participant