Bug Description
I've found two bugs in HttpStream (packages/apps/src/http/http-stream.ts):
found in @microsoft/teams.apps version 2.0.5
Bug 1: streamType always remains informative in final message
close() builds the final activity with .addStreamFinal().withChannelData(this.channelData). Since addStreamFinal() sets streamType: 'final' but withChannelData() merges this.channelData afterwards (which contains streamType: 'informative' accumulated from typing updates), the final message's streamType gets overwritten. Teams never receives the correct final stream state.
Reproduction:
stream.update('Thinking...')
stream.emit('Response text')
await stream.close()
// Final message has streamType: 'informative' instead of 'final'
Bug 2: Race condition in close() - final message sent before flush completes
The while loop in close() checks queue.length and this.id but not this._flushing. If flush() has drained the queue but is still awaiting pushStreamChunk() network calls, close() proceeds immediately and sends the final message. This causes the final message to arrive before intermediate stream chunks.
Reproduction:
stream.emit('chunk 1')
stream.emit('chunk 2')
stream.close()
// close() may send final message before chunk 2 finishes sending
Proposed fixes
- Bug 1: Swap method order in close() so .withChannelData() runs before .addStreamFinal()
- Bug 2: Add
|| this._flushing to the while condition in close()
I have a working fix with unit tests ready to submit as a PR once approved.
Bug Description
I've found two bugs in
HttpStream(packages/apps/src/http/http-stream.ts):found in @microsoft/teams.apps version 2.0.5
Bug 1:
streamTypealways remainsinformativein final messageclose()builds the final activity with.addStreamFinal().withChannelData(this.channelData). SinceaddStreamFinal()setsstreamType: 'final'butwithChannelData()mergesthis.channelDataafterwards (which containsstreamType: 'informative'accumulated from typing updates), the final message'sstreamTypegets overwritten. Teams never receives the correct final stream state.Reproduction:
Bug 2: Race condition in close() - final message sent before flush completes
The while loop in close() checks queue.length and this.id but not this._flushing. If flush() has drained the queue but is still awaiting pushStreamChunk() network calls, close() proceeds immediately and sends the final message. This causes the final message to arrive before intermediate stream chunks.
Reproduction:
Proposed fixes
|| this._flushingto the while condition in close()I have a working fix with unit tests ready to submit as a PR once approved.