Repository navigation
refactor: unify subscription reservations and wallet quota accounting - #3
Merged
Merged
Conversation
This was referenced Oct 16, 2026
6 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
此 Draft PR 由 Codex 辅助审查、实现和验证,尚待维护者人工复核;人工确认项保持未勾选。
📝 变更描述 / Description
统一绑定 Key 与历史订阅的预扣校验和记账,保留请求归属、模型范围、到期、每日限额和额度保护;计费会话拒绝负实际额度及退款后的迟到结算。支付回调、人工补单与历史完成入口共用 TopUp.WalletQuota,按各支付商既有 Amount/Money 单位换算。
真实 PostgreSQL 16 验收发现并修复两处问题:预扣重放与退款持锁顺序相反导致 SQLSTATE 40P01;初始化的 GORM 锁定语句跨模型复用导致查询条件和表名污染。现在统一按“订阅池 → 预扣记录”加锁,并隔离重放查询作用域。新增确定性并发回归、签名支付 HTTP 回调与人工补单并发测试,CI 使用独立 PostgreSQL 16 容器和 race detector。
前端新增按文件隔离的 Bun 测试入口,消除 node:test 注册与 DOM 模块状态跨文件干扰。CI 在同一 runner、同一 Bun 1.3.14 对比 base/head 原始与隔离运行结果,上传全部日志,完整保留原断言和失败退出码。
没有修改 Schema、套餐/流量包合同、价格、额度系数、商品可见性、Key 绑定、渠道/模型限制、fallback 或支付验签规则。详细代码证据、初轮架构审查与续轮验收见报告第 8 节。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
最终代码:
dae9a04a231e3e96f9f0d2cdb93ee53d6228ee59;对比 main:42b8280358241580076ce7fe00350fbd5890098e。验收结论:暂不建议人工合并,保持 Draft。 PostgreSQL 死锁及查询污染已修复;当前明确未解除的 CI 阻塞是
api-key-group-cell.test.tsx的三个 Auto 标记视觉断言。main 同样失败,现有组件注释了 AutoGroupBadge;需要独立确认 UI 行为与测试契约。本 PR 没有恢复 UI、弱化断言或因基线失败豁免检查。已确认的既有资金风险: 异步订阅退款三次最终失败后,Key 可恢复但池仍占用额度;会话已标记 refunded,后续调用不再重试。没有持久化补偿队列或可靠自动对账;七天清理还可能删除 consumed 凭据,且成功结算与退款失败记录无法凭状态区分。故障注入与已知请求号显式幂等恢复测试已通过,只证明缺口和低层恢复能力。持久化终态/账务操作、outbox 重试、人工异常队列及完成后清理的方案已写入报告,本轮不扩大实现范围。
MySQL 实例、生产快照迁移、真实浏览器 E2E、真实支付和进程崩溃后的恢复未验证;没有宣称资金补偿闭环已完成。隔离 PostgreSQL 已关闭。无生产写入、合并或部署。