Skip to content

Python: Fix OpenAI Responses streaming to propagate created_at from final response.completed event#5382

Merged
moonbox3 merged 2 commits intomicrosoft:mainfrom
moonbox3:agent/fix-5347-1
Apr 22, 2026
Merged

Python: Fix OpenAI Responses streaming to propagate created_at from final response.completed event#5382
moonbox3 merged 2 commits intomicrosoft:mainfrom
moonbox3:agent/fix-5347-1

Conversation

@moonbox3
Copy link
Copy Markdown
Contributor

Motivation and Context

When using OpenAIChatClient with stream=True, the final streamed response had created_at=None even though the raw response.completed event contains a valid timestamp. This caused noisy warnings in durabletask persistence and incorrect metadata on streamed responses.

Fixes #5347

Description

The root cause was that _parse_chunk_from_openai extracted response_id, conversation_id, and model from the response.completed event but never read created_at. The fix adds extraction of event.response.created_at (a Unix timestamp), formats it as an ISO 8601 UTC string, and passes it through to the returned ChatResponseUpdate. A dedicated unit test verifies the timestamp is correctly propagated and formatted.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Note: PR autogenerated by moonbox3's agent

microsoft#5347)

The streaming path in _parse_chunk_from_openai did not extract created_at
from the response.completed event, unlike the non-streaming path in
_parse_responses_response. This caused durabletask persistence warnings
when created_at was None.

Extract created_at in the response.completed case and pass it to the
returned ChatResponseUpdate.

Also fix pre-existing pyright errors for optional orjson import in sample
files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 03:49
@moonbox3 moonbox3 self-assigned this Apr 21, 2026
Copy link
Copy Markdown
Contributor Author

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 92% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by moonbox3's agents

@moonbox3
Copy link
Copy Markdown
Contributor Author

moonbox3 commented Apr 21, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/openai/agent_framework_openai
   _chat_client.py91612186%522–525, 529–530, 536–537, 572–578, 599, 607, 630, 748, 847, 906, 908, 910, 912, 978, 992, 1072, 1082, 1087, 1130, 1246, 1427, 1432, 1436–1438, 1442–1443, 1509, 1538, 1544, 1554, 1560, 1565, 1571, 1576–1577, 1596, 1686, 1708–1709, 1724–1725, 1743–1744, 1787, 1953, 1991–1992, 2008, 2010, 2090–2098, 2128, 2238, 2273, 2288, 2308–2318, 2331, 2342–2346, 2360, 2374–2385, 2394, 2426–2429, 2439–2440, 2451–2453, 2467–2469, 2479–2480, 2486, 2501
TOTAL28468330488% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5688 30 💤 0 ❌ 0 🔥 1m 30s ⏱️

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

Fixes OpenAI Responses streaming so the final response.completed event propagates created_at into the final ChatResponse/AgentResponse, addressing missing timestamps that caused durabletask persistence warnings and incorrect response metadata.

Changes:

  • Extract event.response.created_at in _parse_chunk_from_openai() for response.completed events and set it on ChatResponseUpdate.
  • Add a unit test asserting created_at is propagated and formatted as ISO-8601 UTC (...Z) for streaming completion.
  • Adjust optional orjson imports in conversation samples with a type-ignore annotation.

Reviewed changes

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

File Description
python/packages/openai/agent_framework_openai/_chat_client.py Propagates created_at from response.completed streaming events into ChatResponseUpdate.
python/packages/openai/tests/openai/test_openai_chat_client.py Adds/updates tests to validate streamed created_at propagation and formatting.
python/samples/02-agents/conversations/file_history_provider.py Updates optional orjson import with a type-ignore comment.
python/samples/02-agents/conversations/file_history_provider_conversation_persistence.py Updates optional orjson import with a type-ignore comment.

Comment thread python/samples/02-agents/conversations/file_history_provider.py Outdated
…ft#5347)

Replace `# type: ignore[import-not-found]` with
`# pyright: ignore[reportMissingImports]` on optional orjson imports
in conversation sample files, matching the repo's Pyright strict
configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 94% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by moonbox3's agents

@moonbox3 moonbox3 enabled auto-merge April 21, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: OpenAI Responses streaming final response loses created_at, causing durabletask persistence warning

4 participants