Skip to content

fix(responses): preserve reported usage and observed-output settlement - #590

Merged
LIghtJUNction merged 15 commits into
mainfrom
codex/quality-responses-fallback-20261003
Oct 3, 2026
Merged

LIghtJUNction merged 15 commits into
mainfrom
codex/quality-responses-fallback-20261003

Conversation

@LIghtJUNction

@LIghtJUNction LIghtJUNction commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

LMM API Pull Request

变更说明 / Summary

原生 Responses 未返回 usage 时,拒绝文字和只出现在成功 terminal snapshot 的文字、function arguments、reasoning 可能漏计;上游显式报告零 usage 时,原有历史/预扣 fallback 又可能错误收费。本次区分已接受的 provider report 与本地估算:任何已接受的零或正 report 优先;没有 report 时只沿用可观察输出的估算下限。

维护者已于 2026-10-03 明确选择保留既有部分输出计费规则:实际输出后收到失败、但没有 provider usage,继续按输出估算;空失败保持零。成功 terminal snapshot 仅在尚未收集 delta 时补充,避免重复计数;失败/带 error 的 snapshot 不新增推测输出。flat error 立即终止,忽略其后的 completion,并避免追加第二个错误事件。

Go 原生 HTTP 与 WebSocket、Rust 原生 HTTP 结算覆盖此规则。WebSocket 保留独立的下游成功交付判定与成功次数预留;新 attempt 清除 usage evidence,防止上一轮 detail/计费状态污染。显式零只覆盖 token 结算,已有独立工具/图片计价规则继续适用。转换路由的既有显式上游失败退款规则不在此范围。

与上游的关系 / Upstream relationship

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

上游参考 / Upstream reference: QuantumNous/new-api@55a6cd2 (PR #7427)。按本仓库实际 settlement 契约及维护者确认的部分输出政策实现,未直接移植 started-but-empty prompt 收费。

关联 Issue / Related issue

Closes #373

依赖 #584、#591 已合入。最终 head 正常 merge 模型诊断、main 与 WS 失败预留释放修复;父 PR 合并后 diff 仅保留本 Responses usage scope,父 PR 与此 head CI/服务器验收均已通过。此 PR 使用仓库允许的普通合并保留提交关系,避免依赖 PR #592 的文档索引冲突;源范围保持不变。

变更类型 / Type of change

  • Bug 修复 / Bug fix
  • 文档或仓库维护 / Documentation or maintenance

验证 / Verification

最终 immutable head 4c758b6eb6edf1aaf59902fa2910d0800b1f41ff,正常 merge 旧 03325ce 与已合入 #584 的 main ed4eb574,未 rebase/force。相对旧 head 仅加入 main #589 的六个 CCSwitch 文件,逐 blob 与 main 相同;Responses、模型诊断、Rust/PG fixture、36 项精确门槛与文档原样。六个相关 Go 包 race/vet 和 Rust 脚本静态契约再次通过,未运行 Cargo。旧 head 的 CI 与 完整服务器资格 已通过,真实 PG 36 项实际通过且 0 ignored;此新 head 的 CI、完整服务器资格、Billing safety 和 CodeQL 均已通过;24 checks 中 21 success、3 条件跳过,无失败或待执行项。Console page review 未命中路径,不计作独立浏览器验收。

  • Go 原生 HTTP/gzip settlement matrix 与新增 refusal、terminal 输出、reported zero、snapshot dedupe、nested/flat error 回归通过;controller、OpenAI、relay common、service regular/race 与相关 vet 通过。
  • WebSocket 58 个真实 upstream/downstream + SQL cases 通过:所有五类 delta、accepted zero/positive report、lifecycle placeholder、failed/incomplete partial、nested error、replay、新 attempt、本地 prompt 上限及独立 success-slot 结算。
  • 整合源 9a672eba54d342226d28b3cae70b7a0c66986eec 使用独立 PostgreSQL 18.6/Valkey 9.1.2:真实 HTTP settlement 36 项全部实际执行、0 ignored;新增 billing(responses): reconcile interrupted-stream missing-usage policy with new-api #7427 #373 matrix 含 10 个子案例。资金 Go oracle 28 vectors 与 price lifecycle 32 vectors重新生成;资金规则 1 项和分页 4 项 ignored integration 均显式执行并通过。
  • Rust fmt、全 workspace/all-target/all-feature Clippy -D warnings 通过。普通 lib 938 passed/5 ignored,observability 13、readonly routes 2、WebSocket 35 通过;普通测试中 ignored 的 5 项没有被算作已执行。
  • 真实 integration runner 强制精确 inventory/命名守卫,静态契约 8+3 回归通过。PR CI/服务器验收仍以最终 immutable head 为准;没有部署或真实上游凭据验收。

截图或日志 / Screenshots or logs

docs/responses-missing-usage.md 记录 provider usage 权威性、估算下限、失败与成功 snapshot、已确认部分输出政策及各运行时验证边界。真实结算回归直接比较钱包、Token、消费日志、usage、success slot 和上游调用次数。

提交检查 / Checklist

  • 我已搜索本仓库的 Issues 和 PRs,确认没有重复工作。
  • 此 PR 只包含与当前目标相关的改动,未混入格式化或其他无关变更。
  • 我已说明该变更对当前产品流程或兼容行为的影响,并保留必要的来源、版权和许可证信息。
  • 我已检查兼容性;如有破坏性变化,已在说明中明确列出迁移方式。
  • 我已补充或更新相关测试,并在上方记录实际验证结果;如未测试,已说明原因。
  • 我已更新受影响的文档、示例配置和多语言文案(如适用)。
  • 代码、日志、截图和提交记录中不包含 API Key、Cookie、Token、密码、DSN 或其他敏感信息。

Observe provider-declared models before conversion, retain useful three-name metadata with a sticky derived mismatch, and share a bounded compatibility contract across Go, Rust, and the usage-log UI. Keep existing response and billing behavior, including native Claude model handling. Refs #378.
Bind the settlement integration gate to all 35 source and compiled tests, including both response model diagnostics regressions. Keep exact test names and execution-count guards, and verify that dropping the new regressions fails before execution. Refs #378.
Retain WebSocket capability, authorization and reader isolation alongside provider model observations. Preserve both translation sets and provide a scoped WebSocket copy generator with exact-key regression coverage. Keep all documentation index links and the 35-test settlement gate.
Copilot AI balanced review requested due to automatic review settings October 3, 2026 13:31

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 3, 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-03T13:57:03.958896Z d501fd2 PR opened
ℹ️ 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.

Preserve the confirmed partial-output billing policy, reported terminal zero usage, WebSocket/image settlement boundaries, and all 36 exact settlement gate tests. Retain main CC Switch model scoping and documentation indexes.
@LIghtJUNction
LIghtJUNction merged commit a0d213e into main Oct 3, 2026
24 checks passed
@LIghtJUNction
LIghtJUNction deleted the codex/quality-responses-fallback-20261003 branch October 11, 2026 10:12
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.

billing(responses): reconcile interrupted-stream missing-usage policy with new-api #7427

2 participants