fix(aws): record cancellations and sync partial usage - #6628
Open
ifoxgege wants to merge 1 commit into
Open
Conversation
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
📝 变更描述 / Description
这是 #6589 的后续修复,补齐 AWS Bedrock 流取消后的日志和部分 usage 结算:
RelayInfo.StreamStatus,区分client_gone、timeout、done和eof,从而与公共StreamScannerHandler的日志行为一致。message_delta时,会根据已累计文本更新部分CompletionTokens,并重新构建BillingUsage,避免继续采用message_start中常见的output_tokens=1。BuildMessageDeltaPatchUsage会在上游缺失输出 usage 时,从已归一化的语义 usage 补齐OutputTokens;输入与 cache 字段仍保持独立语义。实际复现中,Claude 原生流在客户端收到约 50 KB 后断开,旧逻辑仍以
output_tokens=1结算;该修改确保部分输出计数同步到最终计费 usage,同时保留 Bedrock 上游取消。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
client_gone与取消后 staleBillingUsage的重复修改。📸 运行证明 / Proof of Work
新增断言确保:
StreamStatus.EndReason == client_gone;BillingUsage.ClaudeUsage.OutputTokens与本地累计的CompletionTokens一致且大于 1;