fix(codex): avoid tools=None TypeError on openai-codex when no tools are registered (#32892)#32911
Open
xxxigm wants to merge 3 commits into
Open
fix(codex): avoid tools=None TypeError on openai-codex when no tools are registered (#32892)#32911xxxigm wants to merge 3 commits into
xxxigm wants to merge 3 commits into
Conversation
…arch#32892) ``responses.stream()`` / ``responses.parse()`` in openai==2.24.0 unconditionally invoke ``_make_tools(tools)`` which iterates ``tools`` without a None guard, so passing ``tools=None`` raises ``TypeError: 'NoneType' object is not iterable`` before any HTTP request is sent. The agent's outer loop catches the TypeError, sees no HTTP status, classifies it as non-retryable and aborts — breaking every ``openai-codex`` / ``gpt-5.5`` turn for users who run Hermes without external tools registered. Only attach ``tools`` (and the meaningless ``tool_choice`` / ``parallel_tool_calls`` partners) to the kwargs dict when the converted list is non-empty. Preflight already strips ``tools=None`` on its own pass; keeping the build_kwargs output clean removes the need for that downstream rescue and matches how the chat_completions transport already gates the same fields.
Add ``_strip_sdk_none_iterables`` and call it from ``run_codex_stream`` and ``run_codex_create_stream_fallback`` so any code path that still ships ``tools=None`` (a custom transport, a plugin re-injecting the key, a future regression in preflight) is caught before reaching openai==2.24.0's ``_make_tools(None)``. When ``tools`` is None we also drop ``tool_choice`` and ``parallel_tool_calls`` — both are meaningless without tools and already 400 on a few Codex-style relays — so the kwargs stay internally consistent. The helper mutates in place so the caller's dict reflects what was actually sent to the SDK (debug dumps and retries pick up the scrubbed shape automatically).
…ch#32892) Pin both defences against the openai SDK ``_make_tools(None)`` crash: * ``build_kwargs`` must never emit ``tools=None`` (or the orphaned ``tool_choice`` / ``parallel_tool_calls`` partners), and it must still surface the key when tools ARE registered. * ``_strip_sdk_none_iterables`` must scrub ``tools=None`` in place while leaving populated tool lists untouched and tolerating non-dict inputs. * End-to-end through ``run_codex_stream`` with a fake stream that records the kwargs the SDK saw — the actual NousResearch#32892 reproducer. A small ``_make_tools(None)`` assertion is included so we notice if the openai SDK ever fixes the upstream behaviour and the agent defences become belt-only.
19 tasks
1 task
1 task
teknium1
pushed a commit
that referenced
this pull request
May 27, 2026
…registered Salvages the transport-side fix from #32911 (@xxxigm). Closes #32892. The openai SDK's responses.stream() / responses.parse() eagerly call _make_tools(tools), which iterates tools without a None guard. Passing tools=None raises TypeError: 'NoneType' object is not iterable before any HTTP request is issued (openai==2.24.0). PR #33042 already removed responses.stream() from our own Codex call paths, so the specific iteration crash inside _make_tools is no longer on the hot path. But the right API contract is to omit tools entirely when there are no functions to expose — passing tools=None to the backend is semantically wrong regardless of the SDK's iteration behavior, and we'd hit it again on any future code path that hasn't migrated off responses.stream(). This applies the transport-level part of @xxxigm's fix: move 'tools': response_tools into the if response_tools: branch so the key is omitted when there are no tools, just like tool_choice and parallel_tool_calls already are. Skips the run_agent.py-side _strip_sdk_none_iterables helper from their PR — that path is now obsolete because the SDK helper that needed defending is gone. Tests - tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests trimmed from @xxxigm's original 13-test file. Drops the obsolete tests for _strip_sdk_none_iterables and _RecordingResponsesStream (helpers that don't exist on main anymore), keeps the transport behavior tests + the SDK contract sanity check that ensures we notice if upstream ever fixes _make_tools(None). - 6/6 passing locally. Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com>
mathias3
pushed a commit
to mathias3/hermes-agent
that referenced
this pull request
May 28, 2026
…registered Salvages the transport-side fix from NousResearch#32911 (@xxxigm). Closes NousResearch#32892. The openai SDK's responses.stream() / responses.parse() eagerly call _make_tools(tools), which iterates tools without a None guard. Passing tools=None raises TypeError: 'NoneType' object is not iterable before any HTTP request is issued (openai==2.24.0). PR NousResearch#33042 already removed responses.stream() from our own Codex call paths, so the specific iteration crash inside _make_tools is no longer on the hot path. But the right API contract is to omit tools entirely when there are no functions to expose — passing tools=None to the backend is semantically wrong regardless of the SDK's iteration behavior, and we'd hit it again on any future code path that hasn't migrated off responses.stream(). This applies the transport-level part of @xxxigm's fix: move 'tools': response_tools into the if response_tools: branch so the key is omitted when there are no tools, just like tool_choice and parallel_tool_calls already are. Skips the run_agent.py-side _strip_sdk_none_iterables helper from their PR — that path is now obsolete because the SDK helper that needed defending is gone. Tests - tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests trimmed from @xxxigm's original 13-test file. Drops the obsolete tests for _strip_sdk_none_iterables and _RecordingResponsesStream (helpers that don't exist on main anymore), keeps the transport behavior tests + the SDK contract sanity check that ensures we notice if upstream ever fixes _make_tools(None). - 6/6 passing locally. Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com>
Bryce-huang
pushed a commit
to wbkunlun/hermes-agent
that referenced
this pull request
May 29, 2026
…registered Salvages the transport-side fix from NousResearch#32911 (@xxxigm). Closes NousResearch#32892. The openai SDK's responses.stream() / responses.parse() eagerly call _make_tools(tools), which iterates tools without a None guard. Passing tools=None raises TypeError: 'NoneType' object is not iterable before any HTTP request is issued (openai==2.24.0). PR NousResearch#33042 already removed responses.stream() from our own Codex call paths, so the specific iteration crash inside _make_tools is no longer on the hot path. But the right API contract is to omit tools entirely when there are no functions to expose — passing tools=None to the backend is semantically wrong regardless of the SDK's iteration behavior, and we'd hit it again on any future code path that hasn't migrated off responses.stream(). This applies the transport-level part of @xxxigm's fix: move 'tools': response_tools into the if response_tools: branch so the key is omitted when there are no tools, just like tool_choice and parallel_tool_calls already are. Skips the run_agent.py-side _strip_sdk_none_iterables helper from their PR — that path is now obsolete because the SDK helper that needed defending is gone. Tests - tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests trimmed from @xxxigm's original 13-test file. Drops the obsolete tests for _strip_sdk_none_iterables and _RecordingResponsesStream (helpers that don't exist on main anymore), keeps the transport behavior tests + the SDK contract sanity check that ensures we notice if upstream ever fixes _make_tools(None). - 6/6 passing locally. Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com> #AI commit#
mosaiq-systems
pushed a commit
to mosaiq-systems/hermes-agent
that referenced
this pull request
May 29, 2026
…registered Salvages the transport-side fix from NousResearch#32911 (@xxxigm). Closes NousResearch#32892. The openai SDK's responses.stream() / responses.parse() eagerly call _make_tools(tools), which iterates tools without a None guard. Passing tools=None raises TypeError: 'NoneType' object is not iterable before any HTTP request is issued (openai==2.24.0). PR NousResearch#33042 already removed responses.stream() from our own Codex call paths, so the specific iteration crash inside _make_tools is no longer on the hot path. But the right API contract is to omit tools entirely when there are no functions to expose — passing tools=None to the backend is semantically wrong regardless of the SDK's iteration behavior, and we'd hit it again on any future code path that hasn't migrated off responses.stream(). This applies the transport-level part of @xxxigm's fix: move 'tools': response_tools into the if response_tools: branch so the key is omitted when there are no tools, just like tool_choice and parallel_tool_calls already are. Skips the run_agent.py-side _strip_sdk_none_iterables helper from their PR — that path is now obsolete because the SDK helper that needed defending is gone. Tests - tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests trimmed from @xxxigm's original 13-test file. Drops the obsolete tests for _strip_sdk_none_iterables and _RecordingResponsesStream (helpers that don't exist on main anymore), keeps the transport behavior tests + the SDK contract sanity check that ensures we notice if upstream ever fixes _make_tools(None). - 6/6 passing locally. Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com>
KKT-OPT
pushed a commit
to KKT-OPT/hermes-agent
that referenced
this pull request
May 31, 2026
…registered Salvages the transport-side fix from NousResearch#32911 (@xxxigm). Closes NousResearch#32892. The openai SDK's responses.stream() / responses.parse() eagerly call _make_tools(tools), which iterates tools without a None guard. Passing tools=None raises TypeError: 'NoneType' object is not iterable before any HTTP request is issued (openai==2.24.0). PR NousResearch#33042 already removed responses.stream() from our own Codex call paths, so the specific iteration crash inside _make_tools is no longer on the hot path. But the right API contract is to omit tools entirely when there are no functions to expose — passing tools=None to the backend is semantically wrong regardless of the SDK's iteration behavior, and we'd hit it again on any future code path that hasn't migrated off responses.stream(). This applies the transport-level part of @xxxigm's fix: move 'tools': response_tools into the if response_tools: branch so the key is omitted when there are no tools, just like tool_choice and parallel_tool_calls already are. Skips the run_agent.py-side _strip_sdk_none_iterables helper from their PR — that path is now obsolete because the SDK helper that needed defending is gone. Tests - tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests trimmed from @xxxigm's original 13-test file. Drops the obsolete tests for _strip_sdk_none_iterables and _RecordingResponsesStream (helpers that don't exist on main anymore), keeps the transport behavior tests + the SDK contract sanity check that ensures we notice if upstream ever fixes _make_tools(None). - 6/6 passing locally. Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com>
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
…registered Salvages the transport-side fix from NousResearch#32911 (@xxxigm). Closes NousResearch#32892. The openai SDK's responses.stream() / responses.parse() eagerly call _make_tools(tools), which iterates tools without a None guard. Passing tools=None raises TypeError: 'NoneType' object is not iterable before any HTTP request is issued (openai==2.24.0). PR NousResearch#33042 already removed responses.stream() from our own Codex call paths, so the specific iteration crash inside _make_tools is no longer on the hot path. But the right API contract is to omit tools entirely when there are no functions to expose — passing tools=None to the backend is semantically wrong regardless of the SDK's iteration behavior, and we'd hit it again on any future code path that hasn't migrated off responses.stream(). This applies the transport-level part of @xxxigm's fix: move 'tools': response_tools into the if response_tools: branch so the key is omitted when there are no tools, just like tool_choice and parallel_tool_calls already are. Skips the run_agent.py-side _strip_sdk_none_iterables helper from their PR — that path is now obsolete because the SDK helper that needed defending is gone. Tests - tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests trimmed from @xxxigm's original 13-test file. Drops the obsolete tests for _strip_sdk_none_iterables and _RecordingResponsesStream (helpers that don't exist on main anymore), keeps the transport behavior tests + the SDK contract sanity check that ensures we notice if upstream ever fixes _make_tools(None). - 6/6 passing locally. Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com>
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.
What does this PR do?
Fixes #32892 — every Hermes turn against
openai-codex/gpt-5.5(chatgpt.com/backend-api/codex) crashed before sending the request when
the agent was running without external tools registered, surfacing as:
Root cause
openai==2.24.0'sresponses.stream()(andresponses.parse()) call_make_tools(tools)eagerly:is_given(None)returnsTrue, so passingtools=Noneskips theomitearly-return and crashes withTypeError: 'NoneType' object is not iterablebefore any HTTP requestis issued. The agent's outer loop catches the TypeError, sees no HTTP
status, classifies it as non-retryable and aborts.
Hermes' Codex transport was unconditionally placing
"tools": response_toolsinto the kwargs dict, soresponse_tools=None(the "no tools registered" case) shipped
tools=Nonestraight into theSDK.
Fix (two defences, three small commits)
agent/transports/codex.py::build_kwargs— only attachtools(and the meaningless
tool_choice/parallel_tool_callspartners)when the converted list is non-empty. Matches how the
chat_completions transport already gates the same keys.
agent/codex_runtime.py::_strip_sdk_none_iterables— defensiveshim called from
run_codex_streamandrun_codex_create_stream_fallbackso any future code path thatstill ships
tools=None(a custom transport, a plugin re-injectingthe key, a future preflight regression) is scrubbed at the SDK
boundary. Mutates in place so debug dumps / retries see exactly
what was sent.
tests/run_agent/test_codex_no_tools_nonetype.py— 12 newtests covering both defences plus an end-to-end
run_codex_streamreproducer.
Related Issue
Fixes #32892
Type of Change
Changes Made
agent/transports/codex.py— drop the unconditional"tools": response_toolsslot; only addtools/tool_choice/parallel_tool_callswhen there are real tools.agent/codex_runtime.py— add_strip_sdk_none_iterables, callfrom
run_codex_streamandrun_codex_create_stream_fallback,export from
__all__.tests/run_agent/test_codex_no_tools_nonetype.py— 12 new testspinning build_kwargs, the strip helper, end-to-end through
run_codex_stream, and an upstream SDK assertion so we notice if_make_tools(None)ever gets fixed.How to Test
Direct reproduction of the upstream bug (and confirmation of the fix):
Checklist
fix(codex):,fix(codex):,test(codex):)xxxigm)remaining failures in the broader run are pre-existing on
upstream/main(missing optionalanthropicSDK,test_bundled_plugins_discoveredplugin-discovery flake) andunrelated to this PR.
kwargs are byte-for-byte identical to before; only the toolless
path changes shape.