fix(agent): sanitize Codex tool-call history summaries - #18176
Merged
Conversation
19 tasks
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 #17645 (@stephenschoettler) onto current main — the original branch was 154 commits behind and CI had been failing on base-suite regressions addressed separately by #17660 (already merged).
Codex/OpenAI Responses sessions no longer 400 on the final max-iterations summary with 'No tool call found for function call output with call_id …'.
Changes
agent/context_compressor.py:_get_tool_call_idpreferscall_idoverid.run_agent.py:_get_tool_call_id_staticmatches._handle_max_iterationsnow runs_sanitize_api_messagesbefore the summary call (same safety net as the main loop).Root cause
Codex Responses tool_calls carry both
id(anfc_*response-item id used for streaming correlation) andcall_id(thecall_*id the API expects infunction_call_output.call_idand that we persist intotool_call_idon tool results). The sanitizer builtsurviving_call_idsfromtc.id, so every Codex tool result looked orphaned — either the result got dropped or a stub was inserted with the wrong id, leaving the realcall_*output unpaired. Chat-completions tool_calls only haveid(nocall_id), so the fallback keeps that path unchanged.Validation
tests/agent/test_context_compressor.py+tests/run_agent/test_run_agent.py: 375/375 passing.Credit: @stephenschoettler. Closes #17645.