fix: reset turn detection timers when re-enabling server VAD#1346
fix: reset turn detection timers when re-enabling server VAD#1346ATOM00blue wants to merge 1 commit into
Conversation
Disabling server VAD with `turnDetection: null` left the previous idle timer running on the server. When detection was off longer than the idle timeout and then re-enabled, the stale timer fired immediately and the model spoke before the user could respond. `updateSessionConfig` now tracks the turn detection state and clears the input audio buffer when detection transitions from off to on, so the idle timer only starts counting from fresh speech. Updates that do not touch turn detection are left untouched to avoid dropping in-flight audio.
🦋 Changeset detectedLatest commit: 28b2210 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28b2210c6b
ℹ️ 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".
| // `undefined` means this update did not touch turn detection, so leave the | ||
| // tracked state (and any in-flight audio) untouched. | ||
| if (typeof turnDetection === 'undefined') { | ||
| return; |
There was a problem hiding this comment.
Clear stale timer when updates implicitly re-enable VAD
_resetTurnDetectionTimersIfReenabled treats turnDetection === undefined as “turn detection unchanged”, but updateSessionConfig sends a fully merged payload where turn_detection is still set (falling back to default server VAD). After a caller disables VAD with turnDetection: null, a later unrelated update (for example { voice: 'echo' }) can re-enable VAD in the outbound session.update without triggering input_audio_buffer.clear, so the stale idle timer this patch is fixing can still fire immediately. The re-enable check should be based on the applied session payload/state, not just whether the input delta explicitly included turnDetection.
Useful? React with 👍 / 👎.
|
This PR is stale because it has been open for 10 days with no activity. |
Summary
Re-enabling server VAD after turning it off triggers an immediate idle prompt. Disabling turn detection (
turnDetection: null) leaves the server's idle timer running, so if VAD stays off longer thanidleTimeoutMsand is then re-enabled, the stale timer fires right away and the model speaks before the user gets a chance to.updateSessionConfignow tracks the turn detection state and clears the input audio buffer when detection transitions from off to on, which resets the server-side idle/turn timers so they only start counting from fresh speech. Updates that don't touch turn detection are left untouched so in-flight audio isn't dropped.Fixes #1208
Test plan
cd packages/agents-realtime && CI=1 pnpm vitest run(new tests intest/openaiRealtimeBase.test.tscover re-enable / stay-enabled / disable / untouched cases; the re-enable test fails onmain)pnpm build && pnpm -r build-check && pnpm lintNote
This resets the timer for the supported
transport.updateSessionConfigpath. Callers that toggle VAD by sending rawsession.updateevents viatransport.sendEventbypass this and should send aninput_audio_buffer.clearthemselves (or switch toupdateSessionConfig).