---
type: email
from: Zach Birenbaum <notifications@github.com>
subject: Re: [openai/openai-agents-python] Fix streaming trace end before

 guardrails complete (PR #1921)
received: 2026-03-06 08:10:11
date_header: Mon, 20 Oct 2025 15:56:29 -0700
priority: normal
status: awaiting_approval
uid: 33122
---

## Email Content

**From:** Zach Birenbaum <notifications@github.com>
**Subject:** Re: [openai/openai-agents-python] Fix streaming trace end before

 guardrails complete (PR #1921)
**Date:** Mon, 20 Oct 2025 15:56:29 -0700

### Body (preview)

@zbirenbaum commented on this pull request.







> @@ -1138,6 +1138,12 @@ async def _start_streaming(

 

             streamed_result.is_complete = True

         finally:

+            if streamed_result._input_guardrails_task:

+                try:

+                    streamed_result.input_guardrail_results = await streamed_result._input_guardrails_task

+                except Exception:

+                    # Exceptions will be checked in the stream_events loop

+                    output_guardrail_results = []



I managed to confirm the branch in its current state addresses the inconsistency in trace completion and the trace structure/code behavior is consistent in the following scenarios:

1. Input guardrail completes first (prior to changes - happy path)

2. Input guardrail completes first (after changes - happy path)

3. Input guardrail completes after main request  (after changes - scenario PR intends to fix)



I also added some unit tests for various delay scenarios and exception behavior:

- On main: `test_parent_span_and_trace_finish_after_slow_input_guardrail` is the only test that fails

- On this branch: `test_parent_span_and_trace_finish_after_slow_input_guardrail` passes



I think this should be good to go.



-- 

Reply to this email directly or view it on GitHub:

https://github.com/openai/openai-agents-python/pull/1921#discussion_r2446308583

You are receiving this because you are subscribed to this thread.



Message ID: <openai/openai-agents-python/pull/1921/review/3358166982@github.com>

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
