Repository navigation
fix(billing): 原子提交任务差额结算并补充隔离回归(Draft) - #774
LIghtJUNction wants to merge 1 commit into
Conversation
Keep wallet/subscription, token, usage counters and task quota in one transaction. Add isolated synthetic regression fixtures and a scoped network-isolated test check. Do not change price selection, rounding, top-up conversion or discount policy.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 70c0ea2241
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| return result.Error | ||
| } | ||
| if result.RowsAffected != 1 { |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Match the subscription billing lock order
When a subscription-backed async task with a positive final adjustment completes while the same API-token user starts another subscription-billed request, this transaction locks subscription→token→user, while pre-consume locks user→subscription→token. PostgreSQL/MySQL can deadlock; if settlement is aborted, RecalculateTaskQuota only logs the error after SUCCESS was stored, and terminal tasks are never polled again. A user can repeatedly overlap requests to leave final deltas uncharged. Lock the user before the subscription and durably retry failed settlements.
Useful? React with 👍 / 👎.
|
根据开发主线交接策略,旧单体 main / traditional 已冻结,相关财务/计费/测试/工具逻辑已由 wip/rust-core-go-extensions 对应微服务组件承接。关闭旧单体历史 PR,避免堆积。 |
开发主线交接(2026-10-12)
开发默认主线现为
wip/rust-core-go-extensions;旧单体main与traditional冻结于3948a0a1ee1cefdd016a7aa45a11851545bb4b85。分支交接不是发布、部署或验收通过。原问题、源码基线、测试与未完成项保留;旧单体路径仅作历史证据,后续先在微服务源码重新确认并按职责移植,不回灌旧数据库/权限/资金实现。主线/S11 跟踪:#895。Extore 商品同步:#894,未验收,禁止部署,尤其禁止合并/推送 Extore
main。本 PR 原目标为旧单体
main,现转向微服务主线。只修改审查目标,尚未完成移植或验收,不可直接合并;须解决跨架构差异/冲突并完成本地验证,保留其他任务的改动。变更说明 / Summary
资金一致性审查的第一个独立根因修复。基线
e1d04c82dbfcd6111cf7e94713fd079084414299,初始提交70c0ea2241851831e23386ab9228ea3f252687e3。现有任务差额结算分别更新资金来源、Token、任务 quota 和统计值;这些更新不能作为一个整体回滚。本 PR 将它们放入同一个数据库事务,并使用任务持久化 quota 检查重复结果与过时结果。退款中的任务不能再次进入差额结算。缓存只在提交后失效,缓存错误不导致再次移动资金。
保留现有价格选择、最终取整、充值渠道比例、合法优惠和订阅额度检查。不纳入 #703 的全局向上取整,不纳入 #754 的固定比例 1。
与上游的关系 / Upstream relationship
关联 Issue / Related issue
关联 #703;本轮整体审查还涉及 #748、#753、#754。本 PR 不宣称解决全部资金问题,不自动关闭这些工作项。
变更类型 / Type of change
验证 / Verification
已在本地实际执行:
以上不等于类型检查或 Go/数据库回归通过。本机只有 Go 1.23.2,项目要求 1.25.1,且 github.com/proxy.golang.org DNS 不可用;不能声称本机已执行完整 go test 或 go vet。
新增限定路径的检查:先编译 service 回归及 paymentpricing 测试二进制,再在独立网络命名空间、空环境、新临时目录中执行。service 仅运行
^TestTaskQuotaSettlement,使用全新临时 SQLite 和合成账号;支付单位测试使用现有非 1 比例用例。没有部署凭据、生产 DSN 或支付网络访问。检查记录源码 SHA、日志和退出码。工作流提交不等于已运行;必须以实际运行结果为准。新增回归:差额补扣与退还、独立旧对象重复结算、8 个并发调用、任务/Token/渠道写入失败后的全量回滚与重试、冲突目标、已预约退款状态。
对账表 / Reconciliation
下表是回归断言的预期值,尚不是运行通过的对账结果。初始总额度 1000,任务已扣 100。
未覆盖与合并门槛
保持 Draft,禁止仅凭语法检查或单组测试合并。仍需验证 PostgreSQL 独立连接/进程并发、完整任务完成流程与失败后恢复、跨订阅重置周期、缓存并发、全量 Go 测试与 vet。本 PR 不改变原有 actualQuota=0 的处理,也未修复历史价格快照缺失、未知流式用量、充值回调/退款和优惠券生命周期。
截图或日志 / Screenshots or logs
无 UI 变更。测试输出为合成金额;不包含真实账号或支付数据。
提交检查 / Checklist