fix: close Claude stream when final usage is estimated#4943
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdds a nil-usage guard in StreamResponseOpenAI2Claude's done-chunk path to avoid emitting a final message_delta when no usage exists, and adds a unit test that verifies chunk ordering, stop-reason mapping, usage propagation, and Claude conversion completion state. ChangesStream Response Completion Handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
29d2466 to
acb5574
Compare
📝 变更描述 / Description
修复 OpenAI-compatible stream 转 Anthropic
/v1/messages时的结束事件丢失问题。此前当上游最后一个 chunk 只有
finish_reason: "stop"、没有usage时,转换器会提前返回等待 usage-only chunk。对于已经在最终处理阶段写入本地估算 usage 的请求,这会跳过content_block_stop、message_delta和message_stop,导致 Claude Code 等客户端一直等待流结束。本次改动只在当前 chunk 和
ClaudeConvertInfo.Usage都没有 usage 时继续等待;如果已有估算 usage,则正常关闭当前 content block 并输出 Anthropic 结束事件。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit
Bug Fixes
Tests