Repository navigation
fix(responses): preserve reported usage and observed-output settlement - #590
Merged
Merged
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ 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. |
9 tasks done
…ality-responses-fallback-20261003
11 tasks done
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.
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.
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
上游参考 / 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
验证 / Verification
最终 immutable head
4c758b6eb6edf1aaf59902fa2910d0800b1f41ff,正常 merge 旧03325ce与已合入 #584 的 mained4eb574,未 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 未命中路径,不计作独立浏览器验收。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 均显式执行并通过。-D warnings通过。普通 lib 938 passed/5 ignored,observability 13、readonly routes 2、WebSocket 35 通过;普通测试中 ignored 的 5 项没有被算作已执行。截图或日志 / Screenshots or logs
docs/responses-missing-usage.md记录 provider usage 权威性、估算下限、失败与成功 snapshot、已确认部分输出政策及各运行时验证边界。真实结算回归直接比较钱包、Token、消费日志、usage、success slot 和上游调用次数。提交检查 / Checklist