Skip to content

fix: bundle of handoff and tracing fixes (#2258, #2151, #2094)#2645

Draft
hkc5 wants to merge 1 commit intoopenai:mainfrom
hkc5:fix/bundle-handoff-and-tracing-issues
Draft

fix: bundle of handoff and tracing fixes (#2258, #2151, #2094)#2645
hkc5 wants to merge 1 commit intoopenai:mainfrom
hkc5:fix/bundle-handoff-and-tracing-issues

Conversation

@hkc5
Copy link

@hkc5 hkc5 commented Mar 9, 2026

This PR fixes three related issues:

1. Fix #2258: Exclude handoff-internal messages from to_input_list()

When nest_handoff_history=True, the SDK creates internal assistant messages containing conversation history summaries. These messages should be excluded from to_input_list() as they are not valid API input items.

Changes:

  • Add _is_handoff_internal_message() helper to detect handoff summary messages
  • Filter out handoff-internal messages in run_item_to_input_item()

2. Fix #2151: Add validation for nest_handoff_history with server-managed conversations

Using nest_handoff_history=True with server-managed conversations (conversation_id, previous_response_id) is not supported and now raises a clear error.

Changes:

  • Add validate_nest_handoff_history_settings() helper
  • Call validation before agent runner initialization

3. Fix #2094: Handle big integers in tracing data serialization

Large integers (> 2^53-1) caused JSON serialization errors in tracing. Now converts them to strings to prevent data loss.

Changes:

  • Add _sanitize_for_json() helper to recursively sanitize data
  • Apply sanitization in SpanExporter._process_data()

Testing

All changes include comprehensive test coverage:

  • tests/test_issue_2258_handoff_internal_messages.py - 9 tests
  • tests/test_issue_2151_nest_handoff_server_managed.py - 7 tests
  • tests/test_issue_2094_big_int_tracing.py - 7 tests

All 23 new tests pass.


Fixes #2258
Fixes #2151
Fixes #2094

…penai#2094)

This PR fixes three related issues:

1. Fix openai#2258: Exclude handoff-internal messages from to_input_list()
   When nest_handoff_history=True, the SDK creates internal assistant messages
   containing conversation history summaries. These messages should be excluded
   from to_input_list() as they are not valid API input items.
   - Add _is_handoff_internal_message() helper to detect handoff summary messages
   - Filter out handoff-internal messages in run_item_to_input_item()

2. Fix openai#2151: Add validation for nest_handoff_history with server-managed conversations
   Using nest_handoff_history=True with server-managed conversations (conversation_id,
   previous_response_id) is not supported and now raises a clear error.
   - Add validate_nest_handoff_history_settings() helper
   - Call validation before agent runner initialization

3. Fix openai#2094: Handle big integers in tracing data serialization
   Large integers (> 2^53-1) caused JSON serialization errors in tracing.
   Now converts them to strings to prevent data loss.
   - Add _sanitize_for_json() helper to recursively sanitize data
   - Apply sanitization in SpanExporter._process_data()

All changes include comprehensive test coverage.

Fixes openai#2258
Fixes openai#2151
Fixes openai#2094
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

Here are some automated review suggestions for this pull request.

Reviewed commit: 76261d462f

ℹ️ 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".

if role != "assistant" or not isinstance(content, str):
return False
# Check for the conversation history markers
return "<CONVERSATION HISTORY>" in content

Choose a reason for hiding this comment

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

P2 Badge Narrow handoff-internal detection to synthetic summaries

This check treats any assistant message containing <CONVERSATION HISTORY> as internal and drops it, but run_item_to_input_item() runs for all transcripts (including when nest_handoff_history is disabled) and feeds to_input_list()/session replay paths. A normal model response that legitimately includes that marker text (for example when discussing XML-like tags) will now be silently removed from history, causing later turns to lose context. The filter should match the full synthetic handoff-summary signature (or a dedicated metadata flag) rather than a single substring.

Useful? React with 👍 / 👎.

@seratch seratch marked this pull request as draft March 10, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant