Skip to content

FIX bound OpenAI Realtime completion grace - #2420

Open
Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-fix-realtime-completion-grace
Open

FIX bound OpenAI Realtime completion grace#2420
Roman Lutz (romanlutz) wants to merge 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-fix-realtime-completion-grace

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

OpenAI Realtime atomic event handling started a fresh one-second grace timeout after every event received following audio.done. Repeated late lifecycle, stale, duplicate, or provider-noise events could therefore postpone completion indefinitely.

This change records a one-shot monotonic deadline when the first audio.done arrives and recomputes only the remaining wait time for later events. Duplicate audio.done events cannot move the deadline, a legitimate response.done can still complete within the grace window, and cancellation continues to propagate. The separate streaming dispatcher path is unchanged because it owns its own event iterator and turn-completion state.

Tests and Documentation

Added focused unit coverage for bounded termination under stale/noisy traffic, acceptance of a late terminal event, and cancellation without real sleeping. Also added a live integration test that sends two turns on one conversation and verifies websocket reuse plus cross-turn context on both Platform OpenAI API-key and Azure OpenAI Entra endpoints.

Validation:

  • 133 focused realtime unit tests passed.
  • 2 live same-conversation integration cases passed against configured Realtime endpoints.
  • Ruff check, Ruff format check, type checking, async-suffix checks, and git diff --check passed.

Documentation was not changed because this fixes internal completion timing without changing the public API. JupyText is not applicable.

Copilot AI added 2 commits August 14, 2026 12:53
Use a one-shot monotonic deadline after audio completion so stale or noisy events cannot indefinitely postpone atomic turn termination. Cover late terminal events, duplicate and stale traffic, and cancellation without real sleeps.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exercise two turns on one RealtimeTarget conversation against platform and Azure endpoints, asserting websocket reuse and cross-turn context retention.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bfe299e4-3111-4ab9-ab9f-46e0dd827f13
@hannahwestra25 hannahwestra25 self-assigned this Aug 19, 2026
Comment thread pyrit/prompt_target/openai/openai_realtime_target.py
Bind atomic receive state to response.created and discard response-scoped events carrying another response ID so late deltas from a soft-finished turn cannot contaminate the next turn.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bfe299e4-3111-4ab9-ab9f-46e0dd827f13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants