Skip to content

Conversation

@AnkanMisra
Copy link
Contributor

Fixes #2171

Problem

When nest_handoff_history is enabled, the next agent receives duplicate conversation items:

Before this fix:

  1. Summary message with <CONVERSATION HISTORY> containing tool calls as text
  2. Raw function_call items (duplicated)
  3. Raw function_call_output items (duplicated)

This causes the model to see the same information twice, wasting tokens and potentially causing confusion.

Solution

Introduced separation between items sent to the model vs items preserved for session history:

  • Model input: Filtered - excludes function_call and function_call_output items already in the summary
  • Session history: Unfiltered - preserves all items for observability and session saving

Key changes:

  • Added input_items field to HandoffInputData for filtered model input
  • Added session_step_items field to SingleStepResult for full session history
  • Updated generated_items property to use session items when available
  • Streaming events now use unfiltered items for full observability

Behavior

Scenario Before After
Model receives Summary + raw tool items (duplicated) Summary only (no duplicates)
Session saves All items All items (unchanged)
Streaming events All items All items (unchanged)

Testing

  • Added 6 dedicated tests covering the fix
  • Updated existing test assertions to reflect new expected counts
  • All 1111 tests pass

AnkanMisra and others added 2 commits January 3, 2026 00:38
…ation-2171

fix(handoffs): filter duplicate items from model input when nest_handoff_history is enabled (openai#2171)
@AnkanMisra
Copy link
Contributor Author

@seratch Please review for any fixes

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

guardrail_result.output.tripwire_triggered
for guardrail_result in input_guardrail_results
):
await self._save_result_to_session(
session, [], turn_result.new_step_items

P1 Badge Session save drops unfiltered handoff items

For handoffs, new_step_items now holds the filtered model input while session_step_items keeps the full turn, but _save_result_to_session is still called with turn_result.new_step_items. With nest_handoff_history enabled this means tool call/output items removed from input_items are never persisted to the session even though they’re retained in session_step_items, contradicting the stated goal that session history remains unfiltered.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@seratch
Copy link
Member

seratch commented Jan 6, 2026

Thanks for sharing this. We're going to move the nested handoff feature to an opt-in starting in 0.7.0: #2211 We'll continue improving the quality, but for now, I'll focus on completing other priorities.

@AnkanMisra
Copy link
Contributor Author

Makes sense! Thanks for the context
Happy to help improve the feature further once it's in opt-in mode

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Next agent receives duplicate history (summary + raw tool calls) when nest_handoff_history is enabled

2 participants