Skip to content

fix(run): copy raw_responses when building a RunState - #4237

Merged
seratch merged 1 commit into
openai:mainfrom
adityasingh2400:fix-raw-responses-alias
Aug 6, 2026
Merged

fix(run): copy raw_responses when building a RunState#4237
seratch merged 1 commit into
openai:mainfrom
adityasingh2400:fix-raw-responses-alias

Conversation

@adityasingh2400

@adityasingh2400 adityasingh2400 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

to_state() assigns result.raw_responses straight onto the new RunState, so the state and the already-returned RunResult share one list object. Resuming that state through Runner.run() appends the next turn's ModelResponse onto that shared list, which silently grows the raw_responses of a RunResult the caller was handed earlier. The assignment one line above it in the same function copies with list(result.new_items), and the resume block in run.py copies session_items and the three guardrail result lists out of the run state the same way, so this line was the lone outlier. The fix copies the list.

This is distinct from #3924, which was closed because it changed the _model_input_items fallback branch that is unreachable for SDK-created results. This line is not branch guarded and reproduces through the plain public API. On main the new test fails with assert 2 == 1, because result1.raw_responses grows from one response to two after a second Runner.run() resumes the state. The streamed path is unaffected because run_loop.py rebinds streamed_result.raw_responses to a newly concatenated list rather than appending in place, so only the Runner.run() resume path shows the bug. make lint, make typecheck, and make tests all pass.

to_state() assigned result.raw_responses directly to the new state, so
resuming from that state appended the next turn's responses onto the list
still held by the RunResult that was already returned to the caller. The
sibling assignment one line above copies with list(result.new_items), and
the resume block in run.py copies session_items and the guardrail result
lists out of the run state the same way, so this one was the outlier.
@seratch seratch added this to the 0.20.x milestone Aug 6, 2026
@seratch
seratch enabled auto-merge (squash) August 6, 2026 00:09
@seratch
seratch merged commit 7e5b3e0 into openai:main Aug 6, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants