fix: tolerate None text in ResponseOutputText content items#2883
Merged
seratch merged 2 commits intoopenai:mainfrom Apr 15, 2026
Merged
fix: tolerate None text in ResponseOutputText content items#2883seratch merged 2 commits intoopenai:mainfrom
seratch merged 2 commits intoopenai:mainfrom
Conversation
`ItemHelpers.extract_text` does `text += content_item.text`, which raises `TypeError: can only concatenate str (not "NoneType") to str` when a `ResponseOutputText` content item has `text=None`. Although the Responses API schema declares `text: str`, this surfaces in practice when output items are assembled via `model_construct` during streaming or forwarded through provider gateways (e.g. LiteLLM partial responses). The crash propagates from inside `execute_tools_and_side_effects`, aborting the agent turn. Coerce with `or ""` so callers see an empty contribution instead of crashing. Adds a regression test covering single None-text content items and mixed (None + real text) content lists.
Member
|
@codex review again |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
seratch
approved these changes
Apr 15, 2026
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.
Summary
ItemHelpers.extract_textdoestext += content_item.text, which raisesTypeError: can only concatenate str (not "NoneType") to strwhen aResponseOutputTextcontent item hastext=None.Although the Responses API schema declares
text: str, this surfaces in practice when output items are assembled viamodel_constructduring streaming or forwarded through provider gateways (e.g. LiteLLM partial responses). The crash propagates up from insideexecute_tools_and_side_effects(called fromrun_single_turn_streamed), aborting the entire agent turn.We hit this in production on an agent backed by a LiteLLM → Azure OpenAI Responses gateway: ~57 user-facing failures per day, all surfacing as the same unhelpful "Something went wrong" message. The full traceback ends in:
Fix: coerce with
or ""so a missing.textcontributes nothing instead of crashing. Behavior on well-formed messages is unchanged (covered by the existingtest_extract_text_concatenates_all_text_segments).Test plan
uv run pytest tests/test_items_helpers.py— all 26 tests pass, including the new regression test.test_extract_text_tolerates_none_text_contentcovers:ResponseOutputTextwithtext=None→ returnsNone(perreturn text or None)Nonetext + real text → returns the real text, both orderings.make lintandmake formatclean.Issue number
N/A — opening a fresh report.
Checks
make lintandmake format