fix(openai): skip realtime truncate when no audio was played fixes : #6157#6158
fix(openai): skip realtime truncate when no audio was played fixes : #6157#6158ByteMaster-1 wants to merge 2 commits into
Conversation
0de3d9f to
9fa9693
Compare
| content_index=0, | ||
| item_id=message_id, | ||
| audio_end_ms=audio_end_ms, | ||
| if audio_end_ms > 0: |
There was a problem hiding this comment.
could there be two situations with audio_end_ms == 0:
- the generation was interrupted/cancelled before any audio generated on the server side
- there are audio generated but agent didn't play any of frames
this fix works for 1 but leaks the not played message for 2? maybe we should delete this item if the audio end ms is 0
There was a problem hiding this comment.
Good catch — you're right that audio_end_ms == 0 conflates two cases. Updated to delete the item (case 2) so the unplayed message isn't left dangling in the remote chat ctx, instead of just skipping. One thing I found while doing this: _handle_error only suppresses "Cancellation failed", so an unconditional delete would itself surface an error in case 1 (item never committed server-side). So I guarded the delete on the item being present in _remote_chat_ctx. Added tests for all three branches.
One open question: there's a small race where the item exists server-side but the conversation.item.added hasn't reflected into _remote_chat_ctx yet — in that window we'd skip the delete and the leak could persist. Happy to handle that differently (e.g. always delete and suppress the not-found error) if you'd prefer.
Address review (longcw): when audio_end_ms == 0 the server may hold a generated-but-unheard audio item (case 2). Delete it so the remote chat ctx matches the local one, guarded on the item actually existing remotely so we don't surface a delete error for the never-committed case (case 1).
Fixes #6157
Skip the realtime
conversation.item.truncatewhen the generation isinterrupted before any audio frame has played (
audio_end_ms == 0), whichthe Realtime API rejects with
unsupported_content_type("Only model output audio messages can be truncated").