Skip to content

fix(responses): only dedup user messages when function_call_outputs are present#6022

Open
derekhiggins wants to merge 2 commits into
ogx-ai:mainfrom
derekhiggins:fix/user-message-dedup
Open

fix(responses): only dedup user messages when function_call_outputs are present#6022
derekhiggins wants to merge 2 commits into
ogx-ai:mainfrom
derekhiggins:fix/user-message-dedup

Conversation

@derekhiggins

@derekhiggins derekhiggins commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #6018

Summary

  • Restrict user message deduplication to only apply when function_call_output items are present in the input
  • Prevents dropping the new user message when using previous_response_id with repeated content

Test plan

  • Unit test covering the dedup-with-function-call-outputs path
  • Integration test with Anthropic provider and previous_response_id

Open in Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Recordings committed successfully

Recordings from the integration tests have been committed to this PR.

View commit workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User message dedup drops messages when using previous_response_id

1 participant