Repository navigation
fix(realtime-session): preserve audio format and config fields on agent update - #318
Merged
seratch merged 3 commits intoAug 11, 2025
Conversation
…s on agent update
…nt update Fixes openai#317 - Caches and merges last session config to ensure fields like inputAudioFormat/outputAudioFormat are preserved across agent updates - Adds regression test for Twilio scenario - Adds changeset for release tracking
🦋 Changeset detectedLatest commit: 6f2abed The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
seratch
approved these changes
Aug 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request fixes a critical bug where updating the agent in a
RealtimeSessionwould cause important session config fields (such asinputAudioFormatandoutputAudioFormat) to revert to defaults, breaking integrations like Twilio that require specific audio formats.Related Issue
Fixes #317
Problem
When calling
updateAgent()on aRealtimeSession, the session config was rebuilt from a minimal set of fields, omitting values likeinputAudioFormat,outputAudioFormat,modalities,speed, etc.This caused the server to fall back to defaults (e.g.,
pcm16), resulting in loud static or broken audio for Twilio and other integrations that require a specific format.Steps to Reproduce
Create a
RealtimeSessionwith a custominputAudioFormat(e.g.,g711_ulaw).Call
updateAgent()to switch to a new agent.Observe that the session config sent to the server reverts to pcm16 and Twilio calls break.
Solution
Added a
#lastSessionConfigcache toRealtimeSessionto store the last full session config sent to the server.Updated
#getSessionConfigto merge the last config, user options, and per-call overrides, always refreshing dynamic fields (instructions, voice, tools, tracing). This ensures all config fields (including audio formats) are preserved across agent updates.Added a regression test to ensure this behavior is maintained.
Testing
Ran pnpm build && pnpm test && pnpm lint — all checks pass.
Added a test that verifies
inputAudioFormatandoutputAudioFormatpersist afterupdateAgent().Checklist
Notes
If you have any feedback or need further changes, let me know!