fix: 修复订单状态机 claim 机制(HIF-25/HIF-28) #1

Open
shanshanzhong147 wants to merge 1 commits from agent/agent/36b338b4 into main
Owner

背景

修复 HIF-25 描述的三个 Bug,并增加 stuck 订单恢复机制。

变更说明

修改 1:OrderStatusClaimed 从 4 改为 6

消除与 OrderStatusFailed(4) 的值冲突。

修改 2:releaseClaim 改为返回 error

调用处检查返回值并记录日志,releaseClaim 失败时由 stuck recovery 兜底。

修改 3:claimAndGetOrder 区分 claimed 状态

claimed 订单返回包含 stuck in claimed 的可重试错误;ProcessTask 区分场景分别处理。

修改 4(关键):修复 finalizeCouponAndOrder 的 claimed→finished 转换

UpdateOrderStatus 使用 WHERE status < target 守卫,claimed(6) < finished(5) 为 false 导致订单永卡。改用直接 DB 更新 WHERE status=6 → SET status=5,再通过 model.Update 刷新缓存。

修改 5:新增 stuck 订单恢复定时任务

每 10 分钟扫描超时 claimed 订单,重置为 paid 并重新入队,不依赖 asynq 原始重试。

## 背景 修复 HIF-25 描述的三个 Bug,并增加 stuck 订单恢复机制。 ## 变更说明 ### 修改 1:OrderStatusClaimed 从 4 改为 6 消除与 OrderStatusFailed(4) 的值冲突。 ### 修改 2:releaseClaim 改为返回 error 调用处检查返回值并记录日志,releaseClaim 失败时由 stuck recovery 兜底。 ### 修改 3:claimAndGetOrder 区分 claimed 状态 claimed 订单返回包含 stuck in claimed 的可重试错误;ProcessTask 区分场景分别处理。 ### 修改 4(关键):修复 finalizeCouponAndOrder 的 claimed→finished 转换 UpdateOrderStatus 使用 WHERE status < target 守卫,claimed(6) < finished(5) 为 false 导致订单永卡。改用直接 DB 更新 WHERE status=6 → SET status=5,再通过 model.Update 刷新缓存。 ### 修改 5:新增 stuck 订单恢复定时任务 每 10 分钟扫描超时 claimed 订单,重置为 paid 并重新入队,不依赖 asynq 原始重试。
shanshanzhong147 added 1 commit 2026-05-25 02:44:14 -04:00
fix: 修复订单状态机 claim 机制的三个 Bug 并增加 stuck 订单恢复
Build docker and publish / build (20.15.1) (pull_request) Failing after 8m41s
294bdf4577
- 将 OrderStatusClaimed 从 4 改为 6,消除与 OrderStatusFailed 的值冲突
- finalizeCouponAndOrder 改用直接 DB 更新(WHERE status=6→SET status=5),
  绕过 UpdateOrderStatus 的 status<target 守卫,同时用 model.Update 刷新缓存
- releaseClaim 返回 error,调用处检查并记录日志;releaseClaim 失败由 stuck
  recovery 定时任务兜底
- claimAndGetOrder 对 status=claimed 返回可重试错误而非静默跳过;
  ProcessTask 区分 "stuck in claimed" 与 "非 paid 跳过" 两种场景
- 新增 StuckOrderRecoveryLogic:每 10 分钟扫描超时 claimed 订单,
  重置 status=paid 并重新入队 ForthwithActivateOrder,确保不依赖
  asynq 原始重试(可能已超 maxRetry)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
Some checks are pending
Build docker and publish / build (20.15.1) (pull_request) Failing after 8m41s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
The changes on this branch are already on the target branch. This will be an empty commit.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin agent/agent/36b338b4:agent/agent/36b338b4
git checkout agent/agent/36b338b4
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: HI-VPN/hi-server#1