fix: 修复 v2 流式事件中 THINKING_BLOCK_END / MODEL_CALL_END / AGENT_END 的收尾顺序#1639
fix: 修复 v2 流式事件中 THINKING_BLOCK_END / MODEL_CALL_END / AGENT_END 的收尾顺序#1639guslegend0510 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…cope-ai#1639) Add a top-level `usage` field to Msg for direct token usage access, matching Python's `Msg.usage: Usage | None`. The field is serialized to JSON and deserialized via Jackson. - Add ChatUsage usage field to Msg with getter, builder method, and JSON serialization support - Update getChatUsage() to prefer the direct field over metadata lookup - Add @JsonCreator to ChatUsage for proper deserialization - Populate usage in ReasoningContext.buildFinalMessage() - Add MsgUsageSerializationTest with 5 round-trip and fallback tests
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR fixes the ordering issue of THINKING_BLOCK_END, MODEL_CALL_END, and AGENT_END events in v2 streaming. The core problem was that ThinkingBlockEndEvent was only emitted in the stream's finalization phase (endEvents), causing it to appear after subsequent block events (e.g., TextBlockStartEvent) instead of immediately when the model transitions away from thinking. The fix introduces a thinkingEnded guard flag and an emitThinkingBlockEndIfNeeded() helper that closes the thinking block eagerly — both when a non-thinking block arrives mid-stream and at stream finalization. The same pattern is applied symmetrically to the summary stream. A targeted test validates the corrected event ordering.
|
还是有问题 事件还是乱序的 工具调用 还是乱序的 主要问题是代码 最后兜底导致的乱序,应该在前面的代码中void emitBlockEvents 中处理掉,总体逻辑是 遇到一个block 就因该强制发送非同类事件的结束event |
ca652e5 to
ed25fea
Compare
|
@LearningGp 麻烦看一下,谢谢您 |
|
Thanks for the contribution! This issue has been fixed by #1829 (ModelCallBlockLifecycle refactor). |
关联 Issue
变更内容
THINKING_BLOCK_END、MODEL_CALL_END、AGENT_END顺序延后的问题。ThinkingBlock时立即结束 thinking block,确保THINKING_BLOCK_END早于正文流开始。验证
THINKING_BLOCK_END -> TEXT_BLOCK_START的顺序约束。