Skip to content

fix: reset turn detection timers when re-enabling server VAD#1346

Draft
ATOM00blue wants to merge 1 commit into
openai:mainfrom
ATOM00blue:fix/realtime-vad-timer-reset
Draft

fix: reset turn detection timers when re-enabling server VAD#1346
ATOM00blue wants to merge 1 commit into
openai:mainfrom
ATOM00blue:fix/realtime-vad-timer-reset

Conversation

@ATOM00blue

Copy link
Copy Markdown

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 than idleTimeoutMs and is then re-enabled, the stale timer fires right away and the model speaks before the user gets a chance to.

updateSessionConfig now 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 in test/openaiRealtimeBase.test.ts cover re-enable / stay-enabled / disable / untouched cases; the re-enable test fails on main)
  • pnpm build && pnpm -r build-check && pnpm lint

Note

This resets the timer for the supported transport.updateSessionConfig path. Callers that toggle VAD by sending raw session.update events via transport.sendEvent bypass this and should send an input_audio_buffer.clear themselves (or switch to updateSessionConfig).

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.
Copilot AI review requested due to automatic review settings May 21, 2026 04:24
@changeset-bot

changeset-bot Bot commented May 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 28b2210

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-realtime Patch
@openai/agents Patch
@openai/agents-core Patch
@openai/agents-openai Patch
@openai/agents-extensions Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 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".

Comment on lines +888 to +891
// `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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@seratch
seratch marked this pull request as draft May 21, 2026 21:48
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions Bot added the stale label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turning server VAD off does not reset the internal timers

2 participants