Skip to content

fix(openai): preserve streamed encrypted reasoning - #39635

Merged
ccurme (ccurme) merged 6 commits into
masterfrom
fix/openai-stream-encrypted-reasoning
Aug 14, 2026
Merged

fix(openai): preserve streamed encrypted reasoning#39635
ccurme (ccurme) merged 6 commits into
masterfrom
fix/openai-stream-encrypted-reasoning

Conversation

@johannes117

@johannes117 Johannes du Plessis (johannes117) commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

ChatOpenAI preserves encrypted reasoning from streamed Responses API calls for stateless replay.


OpenAI emits an empty placeholder on response.output_item.added and the final encrypted payload on response.output_item.done. ChatOpenAI now merges the completed payload into streamed output and skips empty payloads during stateless replay.

Made by Open SWE

@github-actions github-actions Bot added fix For PRs that implement a fix integration PR made that is related to a provider partner package integration internal openai `langchain-openai` package issues & PRs size: XS < 50 LOC labels Aug 13, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

@wiggzz

Copy link
Copy Markdown

Review note from the Codex triage assistant: the converter approach looks correct, including same-index aggregation for both output versions and filtering empty encrypted payloads from stateless replay. The current VCR failures appear to be cassette misses caused by the corrected request shape, not product failures: test_mcp_builtin_zdr and both test_mcp_builtin_zdr_v1 cases fall through to network and raise APIConnectionError. Re-recording/updating libs/partners/openai/tests/cassettes/test_mcp_builtin_zdr.yaml.gz should make CI green. One optional coverage improvement would be a single explicit streamed-output -> store=False replay regression, though the existing stream reconstruction plus replay tests already cover the behavior substantively.

@wiggzz

Copy link
Copy Markdown

FWIW this is impacting us pretty hard - we started getting 404s from OpenAI earlier because LangChain was not preserving the encrypted reasoning content. We're working around it but look forward to pulling in this patch when it's released.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
Address review feedback on the streamed encrypted reasoning fix:

- Only match the reasoning `response.output_item.done` branch when the item
  actually carries encrypted content. Previously the branch matched every
  reasoning item and fell through to build a chunk with empty content, adding a
  spurious `on_llm_new_token` callback to every reasoning stream.
- Restore the non-empty `encrypted_content` on the streamed `output_item.added`
  fixture so the deduplicating `pop()` is actually pinned; without it the line
  could be deleted with the suite still green.
- Cover the stateless (`store=False`) replay of a streamed message end to end,
  and re-add the reasoning block shape with no `encrypted_content` key at all.
@github-actions github-actions Bot added size: S 50-199 LOC and removed size: XS < 50 LOC labels Aug 14, 2026
@jhhayashi

Copy link
Copy Markdown

thanks for the quick patch, we also got hit by this today

dropping the reasoning item can leave its function_call replaying an fc_ id with nothing to pair it to, and OpenAI rejects that with an HTTP 400 because the function call is missing its reasoning item. we worked around it by stripping the ID off of any calls between the dropped reasoning item and the next reasoning item

@q734738781

Copy link
Copy Markdown

Confirmed this also affects DeepAgents using LangChain's Codex OAuth (ChatOpenAICodex), with the exact rs* 404 under store=False.

@ccurme
ccurme (ccurme) merged commit 7b954aa into master Aug 14, 2026
91 checks passed
@ccurme
ccurme (ccurme) deleted the fix/openai-stream-encrypted-reasoning branch August 14, 2026 15:33
@ccurme

Copy link
Copy Markdown
Collaborator

Released in langchain-openai 1.5.1.

@wiggzz

Copy link
Copy Markdown

thanks for the quick patch, we also got hit by this today

dropping the reasoning item can leave its function_call replaying an fc_ id with nothing to pair it to, and OpenAI rejects that with an HTTP 400 because the function call is missing its reasoning item. we worked around it by stripping the ID off of any calls between the dropped reasoning item and the next reasoning item

Jordan Hayashi (@jhhayashi) heads up that if you do that, you're dropping reasoning on subsequent turns, which could decrease performance (e.g. the model will lose track of what it was doing and need to re-reason)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix For PRs that implement a fix integration PR made that is related to a provider partner package integration internal openai `langchain-openai` package issues & PRs size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants