Skip to content

Conversation

@MehakBindra
Copy link
Collaborator

@MehakBindra MehakBindra commented Oct 22, 2025

Issue : microsoft/teams.ts#374

Main change::

  • In emit, instead of cancelling and scheduling a new timeout,
    • flush immediately if no timeout pending,
    • else push to queue and wait.
  • Set retry to 500 ms to avoid API quota exceeded errors

EDIT

  • Changed the behavior of lock: Instead of blocking, it now tries to acquire the lock and immediately returns if another flush is running.
  • WaitForIdAndQueueAsync : On close, donot wait forever for id to be set or queue to be empty. Leads to hanging
streaming_dotnet_fix.mp4

Devtools: Streaming always starts before the full response is received (check with logs, see attached video with the green coloured log).
Teams: Even though the first chunk is emitted immediately, (sometimes) by the time the stream starts on Teams, the full response is ready. In the third msg ?, we can see the stream starts a slightly before the full response is logged.

stream.Emit("Eleventh message");
stream.Emit("Twelfth message");

await Task.Delay(70); // Wait for initial flush
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as my python feedback, instead of using a delay you should test this via a stubbed HttpClient so you can programmatically throw different status codes to test the streamer.

Copy link
Collaborator Author

@MehakBindra MehakBindra Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing unit tests for AspNetCorePlugin.Stream will depend on FakeTimeProvider and required internal timing hooks (LastFlushTask) to be deterministic. Maintaining these tests would require changes to production code that are not justified by their limited value and the complexity introduced.

Copilot AI review requested due to automatic review settings January 4, 2026 09:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a streaming timeout issue where the timeout was being reset on each chunk emission, preventing timely flushing of streaming data. The fix changes the behavior to flush immediately when no timeout is pending, rather than continuously resetting a timer.

Key changes:

  • Modified Emit methods to trigger immediate flush when no timeout is pending, instead of resetting timer on each emit
  • Changed lock behavior from blocking to non-blocking using WaitAsync(0) to avoid multiple concurrent flushes
  • Added timeout handling in Close() method with new WaitForIdAndQueueAsync() helper to prevent indefinite waiting
  • Increased global retry delay from 200ms to 500ms to avoid API quota issues
  • Removed all existing streaming tests

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 13 comments.

File Description
Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore/AspNetCorePlugin.Stream.cs Core streaming implementation changes: modified emit logic to not reset timeout, added timeout handling in Close(), changed to non-blocking lock acquisition, and added comprehensive documentation
Libraries/Microsoft.Teams.Common/Extensions/TaskExtensions.cs Increased default retry delay from 200ms to 500ms globally to prevent API quota exceeded errors
Tests/Microsoft.Teams.Plugins.AspNetCore.Tests/AspNetCorePluginStreamTests.cs Removed all streaming tests (4 test methods covering flush timing, timer resets, timeout handling, and typing activities)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…etCore/AspNetCorePlugin.Stream.cs

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings January 5, 2026 02:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings January 5, 2026 02:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants