fix(streaming): reconcile completed Responses output items - #3615
fix(streaming): reconcile completed Responses output items#3615by-openai wants to merge 1 commit into
Conversation
ting-hong-shieh
left a comment
There was a problem hiding this comment.
Validated at 9dad2ad8 against base d9029e3a.
I ran the same synthetic response.created → response.output_item.added → response.output_item.done sequence for reasoning, message, and function-call items. The canonical snapshot hashes changed as follows:
| Item | Base snapshot | Done item / head snapshot |
|---|---|---|
| Reasoning | aa8c8dd24e79 |
b897c980880a |
| Message | 6a64d2e6f63e |
1c0e1e631e2a |
| Function call | 68c4bd453415 |
b0fc42c0be19 |
On the base, all three snapshots still held their provisional values after the done event. On this head, each snapshot matched the authoritative done item exactly. The completed message remained a ParsedResponseOutputMessage with ParsedResponseOutputText content, and the function call remained a ParsedResponseFunctionToolCall.
Validation on the exact head:
pytest -q -n 0 tests/lib— 259 passed- focused Responses file — 10 passed
- Ruff lint and format checks — passed
- Pyright — 0 errors; Mypy — passed
- compilation and
git diff --check— passed
The three public workflow runs are also green. The snapshot used constructed local events only; it made no API request and used no credentials.
Changes being requested
Update
ResponseStreamStateto replace provisional output items fromresponse.output_item.addedwith the authoritative item received inresponse.output_item.done.A reasoning item's initial
encrypted_content, summary, and status can differ from its completed values. Ignoring the done event leaves the streaming snapshot with incomplete encrypted reasoning that cannot safely be replayed. Completed assistant messages and function calls likewise retain stale content, arguments, and status.The reconciliation preserves
ParsedResponseOutputMessageandParsedResponseFunctionToolCallwrappers and applies to both synchronous and asynchronous Responses streams through their shared state.Regression tests cover:
Validation:
pytest tests/lib— 259 passed.ruff checkandruff format --checkon both changed files.pyrighton both changed files.mypyon the changed streaming implementation.Additional context & links
src/openai/lib/, whichCONTRIBUTING.mdidentifies as excluded from SDK code generation.