Skip to content

fix: drain entire queue per flush to avoid streaming tail lag#384

Merged
heyitsaamir merged 1 commit intomainfrom
fix/drain-entire-queue-per-flush
Apr 13, 2026
Merged

fix: drain entire queue per flush to avoid streaming tail lag#384
heyitsaamir merged 1 commit intomainfrom
fix/drain-entire-queue-per-flush

Conversation

@heyitsaamir
Copy link
Copy Markdown
Collaborator

Summary

  • Removes the 10-item batch cap in HttpStream._flush() so each flush cycle drains the entire queue
  • Prevents a long streaming tail when the LLM finishes generating faster than chunks are sent to Teams
  • Port of microsoft/teams.ts#520

Test plan

  • Existing test_http_stream.py tests pass (11/11)
  • Updated test_stream_multiple_emits_with_timer to verify the first flush drains all 12 messages with no second flush scheduled
  • Pre-commit hooks (ruff, pyright) pass

🤖 Generated with Claude Code

Remove the 10-item batch cap in HttpStream 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.ts#520.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 13, 2026 17:15
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates HttpStream._flush() to drain the entire queued backlog in one flush cycle, eliminating the previous 10-item cap and reducing end-of-stream “tail lag” when generation outpaces outbound chunk sending.

Changes:

  • Remove the 10-item per-flush batch limit so _flush() drains the whole queue in one pass.
  • Update the _flush() flow documentation and adjust logic to detect “nothing to flush” based on initial queue length.
  • Update the timer-based streaming test to assert a single flush drains all messages and no follow-up flush is scheduled.

Reviewed changes

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

File Description
packages/apps/src/microsoft_teams/apps/http_stream.py Removes per-flush batching and updates flush-loop logic/docs to drain the full queue.
packages/apps/tests/test_http_stream.py Updates the timer-based test to validate the new “drain all in first flush” behavior.

Comment thread packages/apps/src/microsoft_teams/apps/http_stream.py
Comment thread packages/apps/tests/test_http_stream.py
heyitsaamir added a commit to microsoft/teams.net that referenced this pull request Apr 13, 2026
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 <noreply@anthropic.com>
@heyitsaamir heyitsaamir merged commit 11e9cda into main Apr 13, 2026
9 checks passed
@heyitsaamir heyitsaamir deleted the fix/drain-entire-queue-per-flush branch April 13, 2026 17:27
@heyitsaamir heyitsaamir mentioned this pull request Apr 16, 2026
2 tasks
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.

3 participants