Skip to content

fix(realtime): preserve existing transcript over stale delta accumulator#3214

Merged
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/realtime-transcript-stale-delta
May 8, 2026
Merged

fix(realtime): preserve existing transcript over stale delta accumulator#3214
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/realtime-transcript-stale-delta

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Summary

While merging a RealtimeModelItemUpdatedEvent whose incoming content lacks a transcript, RealtimeSession looked up the existing item to preserve its transcript, then unconditionally reassigned the local preserved variable from the in-flight _item_transcripts delta accumulator for assistant items.

That contradicted the adjacent comment ("If still missing and this is an assistant item, fall back to ...") and meant a stale or partial delta still buffered for the same item_id would clobber the complete transcript already in history. In practice this surfaced when the platform retrieves an item (e.g. after conversation.item.truncated) without a transcript while delta state from the same turn was still around.

The one-line fix adds the missing not preserved guard so the delta fallback only fires when the existing item really has nothing. The existing two preservation tests still pass; the new regression test fails on main and passes with the fix.

- if incoming_item.role == "assistant":
+ if not preserved and incoming_item.role == "assistant":
      preserved = self._item_transcripts.get(incoming_item.item_id)

Test plan

  • pytest tests/realtime/test_session.py::TestTranscriptPreservation (3 passed, including new regression test)
  • pytest tests/realtime/ (233 passed, no regressions)
  • Confirmed new test fails on main without the fix (assert 'stale partial' == 'Final complete transcript')

When merging an `item_updated` event, the merge logic falls back to the
in-flight `_item_transcripts` delta accumulator only when the existing
history item has no transcript. The previous implementation unconditionally
reassigned `preserved` from the delta dict for assistant items, clobbering
a complete transcript already in history with whatever partial (or stale)
delta state was still around.

This contradicted the inline comment ("If still missing and this is an
assistant item, fall back to ...") and meant a retrieve-without-transcript
update could replace the final transcript with stale partials.

Add the missing `not preserved` guard and a regression test that fails
without the fix.
@github-actions github-actions Bot added bug Something isn't working feature:realtime labels May 8, 2026
@seratch
Copy link
Copy Markdown
Member

seratch commented May 8, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch merged commit b4be175 into openai:main May 8, 2026
10 checks passed
@seratch seratch added this to the 0.17.x milestone May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:realtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants