Python: Fix OpenAI Responses streaming to propagate created_at from final response.completed event#5382
Conversation
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>
moonbox3
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 92% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by moonbox3's agents
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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_atin_parse_chunk_from_openai()forresponse.completedevents and set it onChatResponseUpdate. - Add a unit test asserting
created_atis propagated and formatted as ISO-8601 UTC (...Z) for streaming completion. - Adjust optional
orjsonimports 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. |
…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>
moonbox3
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 94% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by moonbox3's agents
Motivation and Context
When using
OpenAIChatClientwithstream=True, the final streamed response hadcreated_at=Noneeven though the rawresponse.completedevent 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_openaiextractedresponse_id,conversation_id, andmodelfrom theresponse.completedevent but never readcreated_at. The fix adds extraction ofevent.response.created_at(a Unix timestamp), formats it as an ISO 8601 UTC string, and passes it through to the returnedChatResponseUpdate. A dedicated unit test verifies the timestamp is correctly propagated and formatted.Contribution Checklist