fix(codex): omit tools key from Codex Responses kwargs when no tools registered#33409
Merged
Conversation
…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>
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
2 |
no-matching-overload |
1 |
First entries
tests/run_agent/test_codex_no_tools_nonetype.py:35: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/run_agent/test_codex_no_tools_nonetype.py:42: [no-matching-overload] no-matching-overload: No overload of bound method `MutableMapping.setdefault` matches arguments
tests/run_agent/test_codex_no_tools_nonetype.py:176: [unresolved-import] unresolved-import: Cannot resolve imported module `openai.resources.responses.responses`
✅ Fixed issues: none
Unchanged: 5006 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
1 task
aaka3207
added a commit
to aaka3207/hermes
that referenced
this pull request
May 29, 2026
The Hermes codex transport patch in this Dockerfile moves `tools` into the `if response_tools:` block so tool-less Codex calls don't send an empty `tools` field. That exact change shipped upstream in NousResearch/hermes-agent#33409, which is part of v0.15.0 (2026.5.28) and therefore already present in `nousresearch/hermes-agent:latest`. The patch's `if 'kwargs["tools"] = response_tools' in s:` early-return was already making this RUN block a no-op at build time; this PR drops the dead code. The other two patches (openai SDK null-guard, mnemosyne lazy-register) are kept: - openai SDK null-guard: upstream fix PR #34544 merged today (May 29) but did NOT land in v0.15.2 — keep until v0.15.3. - mnemosyne lazy-register: separate concern, not yet superseded.
aaka3207
added a commit
to aaka3207/hermes
that referenced
this pull request
May 29, 2026
) The Hermes codex transport patch in this Dockerfile moves `tools` into the `if response_tools:` block so tool-less Codex calls don't send an empty `tools` field. That exact change shipped upstream in NousResearch/hermes-agent#33409, which is part of v0.15.0 (2026.5.28) and therefore already present in `nousresearch/hermes-agent:latest`. The patch's `if 'kwargs["tools"] = response_tools' in s:` early-return was already making this RUN block a no-op at build time; this PR drops the dead code. The other two patches (openai SDK null-guard, mnemosyne lazy-register) are kept: - openai SDK null-guard: upstream fix PR #34544 merged today (May 29) but did NOT land in v0.15.2 — keep until v0.15.3. - mnemosyne lazy-register: separate concern, not yet superseded.
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.
Salvage of the transport-side fix from #32911 (@xxxigm). Closes #32892.
Why
The openai SDK's
responses.stream()/responses.parse()eagerly call_make_tools(tools), which iteratestoolswithout a None guard. Passingtools=NoneraisesTypeError: 'NoneType' object is not iterablebefore any HTTP request is issued (openai==2.24.0).#33042 already removed
responses.stream()from our own Codex call paths, so the specific iteration crash inside_make_toolsis no longer on the hot path. But the right API contract is to omittoolsentirely when there are no functions to expose — passingtools=Noneto 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 offresponses.stream().Changes
agent/transports/codex.py: move'tools': response_toolsinto theif response_tools:branch so the key is omitted when there are no tools (mirrors howtool_choiceandparallel_tool_callsare already handled).tests/run_agent/test_codex_no_tools_nonetype.py: 6 tests covering the transport invariant + SDK contract sanity check.Why not pure cherry-pick
@xxxigm's original PR had two parts:
toolsomission (this PR — still real and useful)agent/codex_runtime._strip_sdk_none_iterablesdefensive shim (obsolete — the SDK helper that needed defending is gone after refactor(codex): drop SDK responses.stream() helper; consume events directly #33042)This salvages just part 1. The trimmed test file drops the 7 tests for the obsolete shim + recording-stream helper that don't exist on main anymore, keeps the 5 transport behavior tests + the SDK contract sanity check (
test_openai_sdk_raises_typeerror_on_tools_none) so we notice if upstream ever fixes_make_tools(None).Validation
tests/run_agent/test_codex_no_tools_nonetype.py→ 6/6 passing locallyAttribution
Co-authored by @xxxigm. Authorship preserved via author field + co-author trailer.