Repository navigation
Python: Capture code interpreter outputs on output_item.done - #9744
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits intoOct 27, 2026
Conversation
response.output_item.done handles every other hosted-tool item type by capturing its final, complete state there - several branches note explicitly that the completed item is the only place their full data is populated - but code_interpreter_call had no branch there at all. The only other place outputs (logs/images) are read from is response.output_item.added, which fires before the call has run, so a streamed code_interpreter_tool_result.outputs was always empty regardless of what the sandbox produced. Added the missing branch, tagging the done item's code and outputs with merge_mode="replace" like code_interpreter_call_code.done's code already is, since a normal stream sends both for the same call and the merge needs to recognize the second one as a repeat of the authoritative value rather than append onto the first. Fixes microsoft#9743
Sadok Barbouche (cr-sbarbouche)
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 27, 2026 06:45
Sadok Barbouche (cr-sbarbouche)
temporarily deployed
to
github-app-auth
October 27, 2026 06:45 — with
GitHub Actions
Inactive
Sadok Barbouche (cr-sbarbouche)
temporarily deployed
to
github-app-auth
October 27, 2026 06:45 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The generated-image behavior addressed by this fix still needs completed-item regression coverage under the repository's testing standards.
1 open issue
What changed in this PR
This PR addresses #9743 by capturing completed code interpreter outputs in the Python OpenAI client's streaming parser.
Changes:
- Parse logs, images, and final code from
response.output_item.done. - Use replacement merging for completed calls and results to avoid duplicating final code.
- Add regression tests for streamed log capture and code deduplication.
| File | Description |
|---|---|
python/packages/openai/tests/openai/test_openai_chat_client.py |
Adds completed-item and streaming-sequence regression tests. |
python/packages/openai/agent_framework_openai/_chat_client.py |
Captures final code interpreter outputs and code during streaming. |
Review effort: Balanced
The completed-item test only exercised the logs branch of the new code, leaving the image branch (also added in this PR) unverified.
Sadok Barbouche (cr-sbarbouche)
temporarily deployed
to
github-app-auth
October 27, 2026 07:04 — with
GitHub Actions
Inactive
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Oct 27, 2026
This branch was previously 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
response.output_item.doneis where every other hosted-tool item type (shell_call,computer_call,image_generation_call,mcp_call,web_search_call/file_search_call,custom_tool_call,tool_search_call,function_call_output) gets its final, complete state captured during streaming - a couple of the existing branches even say so explicitly in their comments.code_interpreter_callis missing from that dispatch entirely. The only other place a code interpreter call'soutputs(logs, generated images) are read from isresponse.output_item.added, which fires before the call has run, so a streamedcode_interpreter_tool_result.outputswas always empty no matter what the sandbox actually produced. See #9743 for a runnable repro against the real client.Description & Review Guide
code_interpreter_callbranch to theresponse.output_item.donedispatch inOpenAIChatClient, mirroring the existing non-streaming parser's andresponse.output_item.added's handling of the same item shape (parseoutputsintocode_interpreter_tool_result, parsecodeintocode_interpreter_tool_call). Both are taggedmerge_mode="replace", matching howcode_interpreter_call_code.donealready tags the code, since a normal stream can send both events for the same call and the merge layer needs to recognize the second one as a repeat of the authoritative final value rather than append onto the first.get_response()call already does. No change for callers who never inspectcode_interpreter_tool_result.outputs.replaceis the right mode foroutputsspecifically. Outputs are never streamed incrementally (no delta event for them), so the done item's list is always the complete, authoritative set; I treated it the same as the already-done code rather thanappend, but wanted to flag the choice explicitly.Related Issue
Fixes #9743
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.