Repository navigation
Python: fix(core): warn when a streamed run registers result gates without buffering - #9029
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits intoOct 7, 2026
Conversation
…thout buffering A result gate runs at stream finalization, so with stream_buffer_updates left at its default the consumer has already received every update by the time the gate raises: the guard fails open, silently, and the exception afterwards documents a block that never happened. microsoft#8954 has the full analysis and an offline repro. Log a warning from both middleware pipelines when result gates are registered on a streamed run with buffering off, and note on with_result_gate() that buffer_updates() is what makes gates block delivery. Strictly additive: delivery semantics are unchanged. Flipping buffering on when a gate is registered, or adding a per-gate opt-in, changes latency semantics and is a vNext call for maintainers.
Yufeng He (he-yufeng)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 3, 2026 17:57
Yufeng He (he-yufeng)
deployed
to
github-app-auth
October 3, 2026 17:57 — with
GitHub Actions
Active
Yufeng He (he-yufeng)
deployed
to
github-app-auth
October 3, 2026 17:58 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Warning detection does not reflect gates and buffering configured directly on the final ResponseStream.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds warnings for unbuffered streamed result gates in Python core middleware.
Changes:
- Warns for unbuffered context-level result gates.
- Documents buffering requirements.
- Adds agent and chat middleware tests.
| File | Description |
|---|---|
python/packages/core/agent_framework/_middleware.py |
Adds gate warning logic to both pipelines. |
python/packages/core/agent_framework/_types.py |
Clarifies with_result_gate() buffering behavior. |
python/packages/core/tests/core/test_middleware_with_agent.py |
Tests agent-path warnings. |
python/packages/core/tests/core/test_middleware_with_chat.py |
Tests chat-path warnings. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
…al stream The warning compared the middleware context's gate lists and buffer option before they were mounted, so a middleware that called with_result_gate() or buffer_updates() on the final ResponseStream itself was invisible to it: direct gates went unwarned, direct buffering still warned. Read the mounted stream state instead and run the check after the mount block in both pipelines.
Yufeng He (he-yufeng)
deployed
to
github-app-auth
October 4, 2026 04:06 — with
GitHub Actions
Active
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Oct 6, 2026
This branch was successfully deployed
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.

Motivation & Context
#8954 shows that an output guard written the natural way fails open on streamed runs: a result gate runs at stream finalization, so with
stream_buffer_updatesleft at its defaultFalseevery update has already reached the consumer by the time the gate raises. Switching a guarded endpoint fromrun()torun(stream=True)silently removes the protection, and the exception raised afterwards makes logs look like the answer was blocked.Description & Review Guide
with_result_gate()docstring notes thatbuffer_updates()is what makes gates block delivery. Strictly additive: delivery semantics are unchanged.Related Issue
Fixes #8954
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.