Deliver queued realtime messages after a mid-reply reconnect on OpenAI, Azure and xAI
- Closes #7192
On OpenAI, Azure and xAI realtime sessions with a reconnect policy, a connection that dropped mid-reply left messages queued behind that reply (ctx.enqueue(...) / session.enqueue(..., priority='when_idle')) stranded for good. The partial reply was already recorded as interrupted and state_restored=False reported. But the session only drains its queue on a codec ResponseDone, and the re-dialed socket never sends one for the lost response: it replays finalized turns only and never continues the cut generation.
The OpenAI-protocol connection now does what the Gemini connection already does (#6324): when the reconnect ends a streaming response as lost, it puts a StaleEvent(ResponseDone(interrupted=True)) ahead of the RealtimeSessionReconnectEvent. The event is stale, so the core doesn't settle the response twice; it only marks the boundary the queue waits for. Azure and xAI inherit the fix from OpenAIRealtimeConnection.frames(). A drop with no reply streaming is unchanged.
Verification
I ran a live repro against each API with a reconnect policy: ask for a long story, session.enqueue(..., priority='when_idle') once the reply starts, then abort the TCP transport.
main | this branch | |
|---|---|---|
OpenAI gpt-realtime-2.1 | nothing after the reconnect event for 15 s; queued message never sent | queued message sent, answered, RealtimeTurnCompleteEvent |
Azure gpt-realtime-2 (Voice Live) | same as OpenAI | same as OpenAI |
xAI grok-voice-latest | same as OpenAI | same as OpenAI |
On main the servers never continued the in-flight response, which the issue had asked to confirm. A control run without the drop delivered the queued message on main.
The regression test test_reconnect_closes_the_reply_it_orphaned fails on main.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code