Fix: Ensure message_start and message_stop events are paired in SDK streaming#2448
Fix: Ensure message_start and message_stop events are paired in SDK streaming#2448
Conversation
📋 Review SummaryThis PR fixes a critical issue where 🔍 General Feedback
🎯 Specific Feedback🔴 Critical
🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
…tream events Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
4a077fd to
79083ff
Compare
TLDR
Fixes
StreamJsonOutputAdapterto ensuremessage_stopevents are always emitted when a message is finalized, ensuringmessage_startandmessage_stopevents are properly paired in SDK streaming mode. Added comprehensive E2E tests to validate the pairing behavior.Dive Deeper
The
StreamJsonOutputAdapterwas emittingmessage_startevents but not consistently emittingmessage_stopevents when messages were finalized. This caused issues for SDK consumers who rely on these paired events to track message boundaries in streaming mode.Changes made:
finalizeAssistantMessage()to call a newfinalizeAssistantMessageInternal()method that properly handles both main agent and subagent messagesmessage_stopevent whenstate.messageStartedis true,includePartialMessagesis enabled, and the message is for the main agent (parentToolUseId === null)The fix ensures that every
message_startevent has a correspondingmessage_stopevent with the samemessage_id, allowing SDK consumers to properly track message boundaries.Reviewer Test Plan
Run the new E2E tests:
npm run test:e2e -- --testNamePattern="Message Start/Stop Event Pairing"Manual validation with SDK streaming:
Verify that
message_startandmessage_stopevents are paired with the samemessage_id.Testing Matrix
Linked issues / bugs