fix(responses): only dedup user messages when function_call_outputs are present#6022
fix(responses): only dedup user messages when function_call_outputs are present#6022derekhiggins wants to merge 2 commits into
Conversation
| if previous_messages and input_item.role == "user": | ||
| # Skip user messages that duplicate the last user message in previous_messages, | ||
| # but only when function_call_outputs are present (the user resent context for them) | ||
| if previous_messages and input_item.role == "user" and tool_call_results: |
There was a problem hiding this comment.
🟡 Duplicate-user-message check uses mutable tool_call_results dict that may already be emptied by preceding function-call processing
The new condition and tool_call_results on line 383 checks whether the tool_call_results dict is non-empty to determine if function_call_outputs are present. However, tool_call_results is mutated during the same loop — entries are deleted at utils.py:332 (del tool_call_results[input_item.call_id]) each time a matching OpenAIResponseOutputMessageFunctionToolCall is processed. If all function_call_outputs in the input have matching function_calls in the same input, and those function_calls appear before the duplicate user message, tool_call_results will be empty by the time the user message is reached, causing the dedup logic to be skipped.
Example scenario where the bug manifests
Input with previous_messages provided:
input = [
OpenAIResponseOutputMessageFunctionToolCall(call_id="abc", ...), # consumes tool_call_results["abc"]
OpenAIResponseInputFunctionToolCallOutput(call_id="abc", ...), # pre-extracted into tool_call_results
OpenAIResponseMessage(role="user", content=...) , # duplicate user message
]After processing index 0, tool_call_results is empty. At index 2, tool_call_results is falsy, so the dedup condition fails and the duplicate user message is included.
The fix should capture whether function_call_outputs were originally present before the main loop mutates the dict, e.g. has_function_call_outputs = bool(tool_call_results) right after line 306, and use that flag instead.
Prompt for agents
The condition `and tool_call_results` on line 383 uses the mutable dict `tool_call_results` as a boolean indicator of whether function_call_outputs were present in the input. However, this dict is depleted during the main loop as matching function_calls consume entries (line 332: `del tool_call_results[input_item.call_id]`). If all entries are consumed before a duplicate user message is encountered, the dedup logic is incorrectly skipped.
Fix: After the pre-extraction loop (after line 306), capture a boolean flag:
has_function_call_outputs = bool(tool_call_results)
Then on line 383, replace `and tool_call_results` with `and has_function_call_outputs`.
This ensures the dedup check is based on whether function_call_outputs existed in the original input, not on whether they have been consumed during processing.
Was this helpful? React with 👍 or 👎 to provide feedback.
Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
|
✅ Recordings committed successfully Recordings from the integration tests have been committed to this PR. |
Fixes #6018
Summary
function_call_outputitems are present in the inputprevious_response_idwith repeated contentTest plan
previous_response_id