fix(handoffs): preserve user messages containing history wrappers - #3815
#3815fix(handoffs): preserve user messages containing history wrappers#3815seratch merged 2 commits intoopenai:mainopenai/openai-agents-python:mainfrom russeell:fix/preserve-user-handoff-wrapper-contentrusseell/openai-agents-python:fix/preserve-user-handoff-wrapper-contentCopy head branch name to clipboard
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b724e30d5
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if item.get("role") != "assistant": | ||
| return None |
There was a problem hiding this comment.
Use more than role to identify generated history
This still treats any assistant message containing the wrapper pair as an SDK-generated summary. When callers provide or replay prior transcript items in input_history, an ordinary assistant response that literally includes a <CONVERSATION HISTORY> example is parsed and replaced with records such as 1. user: injected, dropping the surrounding assistant text before the mapper sees it. The parser needs a stronger signature than the public assistant role to avoid corrupting regular assistant history.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch. I’ll tighten the parser to require the complete SDK-generated summary envelope, not just the assistant role, and add regression coverage for ordinary assistant messages containing these wrappers.
Summary
This pull request fixes nested handoff history parsing so ordinary user messages containing the configured conversation wrapper strings are preserved instead of being interpreted as SDK-generated summaries.
nest_handoff_history()now requires both the assistant role and a complete SDK-generated summary envelope before extracting a nested transcript. The parser recognizes the current and legacy SDK preambles, requires the configured start wrapper in its expected position, and requires the message to end with the configured end wrapper.Regression tests cover user and assistant messages containing parseable
<CONVERSATION HISTORY>blocks with surrounding text and verify that the complete original items reach the history mapper unchanged. Existing SDK-generated summaries, legacy summaries, and custom conversation wrappers continue to flatten normally.Test plan
bash .agents/skills/code-change-verification/scripts/run.shpytest tests/test_extension_filters.py -q(42 passed)pytest tests/test_handoff_history_duplication.py -q(12 passed)Issue number
Closes #3814
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR