fix(realtime): emit history_updated for transcript deltas#2941
fix(realtime): emit history_updated for transcript deltas#2941LocNguyenSGU wants to merge 3 commits intoopenai:mainfrom
Conversation
| content=[AssistantAudio(transcript=self._item_transcripts[item_id])], | ||
| ), | ||
| ) | ||
| await self._put_event( |
There was a problem hiding this comment.
Line 318: history=self._history passes a direct reference to the session's internal _history list rather than a copy. If any subscriber mutates this list, it silently corrupts RealtimeSession._history without the session knowing.
Consider: history=list(self._history) to prevent external mutation from affecting internal state.
There was a problem hiding this comment.
Fixed in 7f3eff8. RealtimeHistoryUpdated now receives list(self._history), so consumers can no longer mutate the session's internal history list through the event payload.
I also made the snapshot behavior consistent across all full-history RealtimeHistoryUpdated emissions and added a regression test for the transcript_delta path.
|
Fixed the lint formatting issue in Verified locally:
Commit: |
Summary
RealtimeSession.on_event()already updates local history when it receives atranscript_delta, but it did not emit a matching high-level history event.This patch emits
RealtimeHistoryUpdatedafter the transcript-delta history mutation so consumers that followhistory_added/history_updatedstay in sync with live transcript updates.Reproduction
A single
RealtimeModelTranscriptDeltaEventproduced:_historyentry containing the partial assistant transcriptRealtimeHistoryUpdatedChanges
RealtimeHistoryUpdatedin thetranscript_deltabranch after updating_historyVerification
uv run pytest tests/realtime/test_session.py -k "transcript_delta_updates_history_and_emits_history_updated or ignored_events_only_generate_raw_events or transcript_delta_triggers_guardrail_at_threshold or transcript_delta_multiple_thresholds_same_item or transcript_delta_different_items_tracked_separately" -qResult:
5 passedRisks
Low. The change only adds the missing high-level event emission for an already-applied history mutation.
Closes #2940