@@ -1797,6 +1797,61 @@ describe("ProviderRuntimeIngestion", () => {
17971797 expect ( message ?. streaming ) . toBe ( false ) ;
17981798 } ) ;
17991799
1800+ it ( "keeps async assistant messages separate from the streaming commentary item" , async ( ) => {
1801+ const harness = await createHarness ( ) ;
1802+ const base = {
1803+ provider : ProviderDriverKind . make ( "codex" ) ,
1804+ createdAt : "2026-01-01T00:00:00.000Z" ,
1805+ threadId : asThreadId ( "thread-1" ) ,
1806+ turnId : asTurnId ( "turn-async-message" ) ,
1807+ } ;
1808+ const completeAssistant = ( eventId : string , itemId : string , detail : string ) =>
1809+ ( {
1810+ ...base ,
1811+ type : "item.completed" ,
1812+ eventId : asEventId ( eventId ) ,
1813+ itemId : asItemId ( itemId ) ,
1814+ payload : { itemType : "assistant_message" , status : "completed" , detail } ,
1815+ } ) as const ;
1816+ const commentaryDelta = ( eventId : string , delta : string ) =>
1817+ ( {
1818+ ...base ,
1819+ type : "content.delta" ,
1820+ eventId : asEventId ( eventId ) ,
1821+ itemId : asItemId ( "commentary" ) ,
1822+ payload : { streamKind : "assistant_text" , delta } ,
1823+ } ) as const ;
1824+
1825+ await harness . emitAndDrain ( [
1826+ commentaryDelta ( "evt-commentary-1" , "Working on it." ) ,
1827+ completeAssistant ( "evt-async-1" , "async-message-1" , "Still investigating." ) ,
1828+ completeAssistant ( "evt-async-2" , "async-message-2" , "Found the cause." ) ,
1829+ commentaryDelta ( "evt-commentary-2" , " Applying the fix." ) ,
1830+ completeAssistant (
1831+ "evt-commentary-completed" ,
1832+ "commentary" ,
1833+ "Working on it. Applying the fix." ,
1834+ ) ,
1835+ ] ) ;
1836+
1837+ const thread = ( await harness . readModel ( ) ) . threads . find (
1838+ ( entry ) => entry . id === asThreadId ( "thread-1" ) ,
1839+ ) ;
1840+ const assistantMessages = ( thread ?. messages ?? [ ] ) . filter (
1841+ ( message ) => message . role === "assistant" ,
1842+ ) ;
1843+ expect (
1844+ assistantMessages . map ( ( message ) => ( { text : message . text , streaming : message . streaming } ) ) ,
1845+ ) . toEqual (
1846+ expect . arrayContaining ( [
1847+ { text : "Working on it. Applying the fix." , streaming : false } ,
1848+ { text : "Still investigating." , streaming : false } ,
1849+ { text : "Found the cause." , streaming : false } ,
1850+ ] ) ,
1851+ ) ;
1852+ expect ( assistantMessages ) . toHaveLength ( 3 ) ;
1853+ } ) ;
1854+
18001855 it ( "preserves completed tool metadata on projected tool activities" , async ( ) => {
18011856 const harness = await createHarness ( ) ;
18021857 const now = "2026-01-01T00:00:00.000Z" ;
0 commit comments