fix: drain entire queue per flush to avoid streaming tail lag#424
Merged
Conversation
Remove the 10-item batch cap in Stream.Flush() so each cycle processes all queued items, preventing a long streaming tail when the LLM finishes faster than chunks are sent to Teams. Port of microsoft/teams.py#384 / microsoft/teams.ts#520. Co-Authored-By: Claude <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Removes the fixed 10-item cap in Stream.Flush() so each flush cycle drains the entire pending activity queue, reducing “tail lag” when generation outpaces outbound sending.
Changes:
- Remove the 10-item batch limit in
Flush()and drain_queuefully per flush - Replace the “no work done” check (
i == 0) with a queue-count-based early return guard
Comments suppressed due to low confidence (1)
Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore/AspNetCorePlugin.Stream.cs:1
startCountis computed from_queue.Count, which is not a reliable indicator of whether this flush actually dequeued items in concurrent scenarios. If_queue.Countis 0 at line 138 but items are enqueued immediately after and then dequeued in the loop,startCount == 0will still be true and the method will return early, potentially dropping/defering sends even though activities were drained and_countwas incremented. Prefer tracking whether anything was actually dequeued (e.g.,var dequeued = 0;increment inside the loop andif (dequeued == 0) return;), which matches the previousi == 0behavior and avoids reliance on_queue.Count.
// Copyright (c) Microsoft Corporation. All rights reserved.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MehakBindra
previously approved these changes
Apr 13, 2026
…am-queue-per-flush
Fixes race condition where _queue.Count snapshot could be 0 before the drain loop but items get enqueued and dequeued during the loop, causing the early return to skip sending those activities. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
MehakBindra
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stream.Flush()so each flush cycle drains the entire queueTest plan
AspNetCorePluginStreamTestspass (15/15 on both net8.0 and net10.0)🤖 Generated with Claude Code