Skip to content

fix(billing): 原子提交任务差额结算并补充隔离回归(Draft) - #774

Closed
LIghtJUNction wants to merge 1 commit into
wip/rust-core-go-extensionsfrom
fix/funds-task-settlement-atomic-20261011
Closed

LIghtJUNction wants to merge 1 commit into
wip/rust-core-go-extensionsfrom
fix/funds-task-settlement-atomic-20261011

Conversation

@LIghtJUNction

@LIghtJUNction LIghtJUNction commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

开发主线交接(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

  • LMM API 独有变更 / LMM API-specific change

关联 Issue / Related issue

关联 #703;本轮整体审查还涉及 #748、#753、#754。本 PR 不宣称解决全部资金问题,不自动关闭这些工作项。

变更类型 / Type of change

  • Bug 修复 / Bug fix
  • 部署、CI 或构建 / Deployment, CI, or build(仅限定范围的测试检查,不发布、不部署)

验证 / Verification

已在本地实际执行:

gofmt(仅本 PR 的 Go 文件):完成。
Go parser.ParseFile + parser.AllErrors:3 个 Go 文件通过语法解析,退出码 0。
YAML 解析和 bash -n:通过。

以上不等于类型检查或 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。

场景 钱包余额 Token 剩余 最终任务 quota 用户/渠道已用 订阅已用
钱包最终消费 150,重复结果无第二次扣费 850 850 150 150 不适用
钱包最终消费 75,退还差额 25 925 925 75 75 不适用
任一写入失败,事务回滚 900 900 100 100 不适用
订阅最终消费 150 1000 850 150 150 150
订阅最终消费 75 1000 925 75 75 75
订阅写入失败,事务回滚 1000 900 100 100 100

未覆盖与合并门槛

保持 Draft,禁止仅凭语法检查或单组测试合并。仍需验证 PostgreSQL 独立连接/进程并发、完整任务完成流程与失败后恢复、跨订阅重置周期、缓存并发、全量 Go 测试与 vet。本 PR 不改变原有 actualQuota=0 的处理,也未修复历史价格快照缺失、未知流式用量、充值回调/退款和优惠券生命周期。

截图或日志 / Screenshots or logs

无 UI 变更。测试输出为合成金额;不包含真实账号或支付数据。

提交检查 / Checklist

  • 已检索相关工作并说明与 fix(billing): audit 1x base-cost accounting and remove inconsistent conversions #703 的拆分关系。
  • 仅包含任务结算及其限定范围验证;没有混入原 PR 的其他改动。
  • 新增回归测试;明确区分已执行检查和未执行验证。
  • 已完成全部资金一致性与生产升级验收。
  • 不包含真实凭据、生产数据;没有移动真实资金、合并或部署。

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.
@LIghtJUNction
LIghtJUNction marked this pull request as ready for review October 11, 2026 12:26
Copilot AI balanced review requested due to automatic review settings October 11, 2026 12:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-11T12:40:27.792163Z 70c0ea2 Draft marked ready

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ 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.

Comment on lines +48 to +50
return result.Error
}
if result.RowsAffected != 1 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

P1 Badge 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 👍 / 👎.

@LIghtJUNction

Copy link
Copy Markdown
Member Author

根据开发主线交接策略,旧单体 main / traditional 已冻结,相关财务/计费/测试/工具逻辑已由 wip/rust-core-go-extensions 对应微服务组件承接。关闭旧单体历史 PR,避免堆积。

@LIghtJUNction
LIghtJUNction deleted the fix/funds-task-settlement-atomic-20261011 branch November 5, 2026 07:31
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.

2 participants