豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

fix(realtime): preserve transport audio formats during agent handoff#2961

Open
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-1632-realtime-handoff-audio-format
Open

fix(realtime): preserve transport audio formats during agent handoff#2961
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-1632-realtime-handoff-audio-format

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 19, 2026

Summary

Fixes #1632 — Realtime agent handoff to Twilio closes the session and sends noise over the phone.

Root Cause

During a Realtime agent handoff, _handle_tool_call called _get_updated_model_settings_from_agent with starting_settings=None. This caused session.update to reset input_audio_format and output_audio_format back to their pcm16 defaults, overwriting the transport-configured g711_ulaw format that Twilio requires.

The asymmetry was:

  • __aenter__ (initial connect): correctly passes starting_settings=self._model_config.get("initial_model_settings", None)
  • _handle_tool_call (handoff): was passing starting_settings=Nonebug

Fix

In _handle_tool_call, pass initial_model_settings as starting_settings to _get_updated_model_settings_from_agent, matching the behavior of __aenter__:

# Before
updated_settings = await self._get_updated_model_settings_from_agent(
    starting_settings=None,
    agent=self._current_agent,
)

# After
updated_settings = await self._get_updated_model_settings_from_agent(
    starting_settings=self._model_config.get("initial_model_settings", None),
    agent=self._current_agent,
)

This ensures transport-configured audio formats (e.g. g711_ulaw set via model_config["initial_model_settings"]) are preserved when updating session settings during handoff, instead of being reset to pcm16 defaults.

Testing

All 215 realtime tests pass.

During agent handoff in _handle_tool_call, _get_updated_model_settings_from_agent
was called with starting_settings=None, causing session.update to reset
input_audio_format and output_audio_format back to pcm16 defaults.

This overwrote transport-configured audio formats (e.g. g711_ulaw for Twilio),
closing the Twilio session and sending noise over the phone.

Fix: pass starting_settings=self._model_config.get("initial_model_settings", None)
to mirror the behaviour of __aenter__, which correctly preserves audio formats
on initial connect.

Fixes openai#1632
@github-actions github-actions bot added bug Something isn't working feature:realtime labels Apr 19, 2026
Copy link
Copy Markdown

@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: ff03a4d43c

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

# reset to defaults during the handoff session update.
updated_settings = await self._get_updated_model_settings_from_agent(
starting_settings=None,
starting_settings=self._model_config.get("initial_model_settings", None),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit handoff merge to transport-safe model settings

Passing initial_model_settings into _get_updated_model_settings_from_agent on handoff causes those values to overwrite agent-derived fields, because that helper applies starting_settings after computing instructions, tools, and handoffs. If a caller sets any of those keys in initial_model_settings (they are valid RealtimeSessionModelSettings fields), a handoff will keep the original configuration instead of switching to the new agent’s behavior. Previously this path passed None, so the new agent settings were preserved.

Useful? React with 👍 / 👎.

@seratch
Copy link
Copy Markdown
Member

seratch commented Apr 20, 2026

Codex's review point sounds valid. I haven't investigated the right solution for this issue, but simply passing the config this way may not work well.

@seratch seratch marked this pull request as draft April 20, 2026 00:52
@xodn348 xodn348 marked this pull request as ready for review April 20, 2026 16:34
@xodn348 xodn348 marked this pull request as ready for review April 20, 2026 16:34
Copy link
Copy Markdown

@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: ff03a4d43c

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

# reset to defaults during the handoff session update.
updated_settings = await self._get_updated_model_settings_from_agent(
starting_settings=None,
starting_settings=self._model_config.get("initial_model_settings", None),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit handoff merge to transport-safe settings

Passing full initial_model_settings into handoff recomputation can stop the new agent from taking effect when users include instructions, tools, handoffs, or prompt there. Fresh evidence in the current tree: _get_updated_model_settings_from_agent computes agent-derived values and then applies starting_settings with update, so this new call path restores the original values on every handoff. In those configurations, the session.update after handoff keeps old behavior instead of switching to the target agent, so only transport-safe fields (like audio formats) should be preserved here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@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: ff03a4d43c

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

# reset to defaults during the handoff session update.
updated_settings = await self._get_updated_model_settings_from_agent(
starting_settings=None,
starting_settings=self._model_config.get("initial_model_settings", None),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid overriding handoff agent settings with initial session config

Passing self._model_config["initial_model_settings"] into the handoff path causes _get_updated_model_settings_from_agent to reapply any instructions, tools, handoffs, or prompt from startup config after the new agent is resolved. In sessions that set any of those keys in initial_model_settings, handoff no longer switches model behavior to the target agent and may keep using the original tool/handoff set. This regression is introduced by the new starting_settings=... call here; preserve only transport-safe fields (for example audio format) instead of the full settings dict.

Useful? React with 👍 / 👎.

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

Labels

bug Something isn't working feature:realtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Realtime agent handoff to twilio closes twilio session and sends noise over phone

2 participants