Skip to content

fix(realtime): #1434 update assistant message status to completed when audio is done#2942

Open
DevAbdullah90 wants to merge 2 commits intoopenai:mainfrom
DevAbdullah90:fix/assistant-history-status
Open

fix(realtime): #1434 update assistant message status to completed when audio is done#2942
DevAbdullah90 wants to merge 2 commits intoopenai:mainfrom
DevAbdullah90:fix/assistant-history-status

Conversation

@DevAbdullah90
Copy link
Copy Markdown

Fix Assistant Message History Status

Summary

This PR resolves an issue where assistant message items in the RealtimeSession history incorrectly retain an in_progress status even after the model has finished generating audio/text.

Related Issues

Fixes #1434

Changes

  • src/agents/realtime/session.py: Updated the on_event handler for audio_done events. It now locates the corresponding item in the session history and updates its status field to "completed".
  • src/agents/realtime/session.py: Added an explicit emission of the RealtimeHistoryUpdated event after the status transition to ensure the UI is notified of the final state.
  • tests/realtime/test_session.py: Updated existing tests to verify the new event emission and ensure the queue state is consistent.

Verification

  • Verified that audio_done events correctly transition the targeted item's status to completed in a local reproduction script.
  • Confirmed that all existing tests in tests/realtime/test_session.py pass.

Why this is necessary

Without this fix, client applications relying on the status field of history items would indefinitely show generation as "in progress," which leads to confusing UI states (e.g., perpetual loading indicators) even after the assistant has clearly finished speaking.

@github-actions github-actions bot added bug Something isn't working feature:realtime labels Apr 18, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d96a8f5a7b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/realtime/session.py Outdated
Comment on lines +280 to +282
for i, item in enumerate(self._history):
if item.item_id == item_id and hasattr(item, "status"):
self._history[i] = item.model_copy(update={"status": "completed"})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid marking message completed on first audio_done

audio_done is emitted per audio content part (item_id + content_index), but this branch marks the entire history item as completed on the first such event. For responses that keep streaming other content (e.g., additional content parts or later item_updated/output_item.done state), clients will observe a premature terminal status and may stop rendering/loading indicators too early. Please gate this transition on true item completion (or on all relevant parts being done) rather than any single audio_done.

Useful? React with 👍 / 👎.

@DevAbdullah90 DevAbdullah90 force-pushed the fix/assistant-history-status branch from 0f01c8d to ac9b7a4 Compare April 18, 2026 16:26
@DevAbdullah90
Copy link
Copy Markdown
Author

DevAbdullah90 commented Apr 18, 2026

Updated: The fix now correctly handles item status transitions in _get_new_history, ensuring that 'completed' states are applied even when the completion event contains empty content, while preserving existing message parts.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 933653ef85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# Preserve existing content but update status and other metadata.
incoming_item = existing_item.model_copy(
update={
"status": event.status,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard status access on empty-content message updates

In _get_new_history, the new empty-content path unconditionally reads event.status when event.type == "message". That works for AssistantMessageItem, but UserMessageItem/SystemMessageItem do not define a status field, so a sparse update such as an item_updated event with content=[] for an existing user/system item will raise AttributeError and break event processing. This is a regression from the previous behavior (which skipped empty-content message updates) and should be guarded with getattr(...) or restricted to assistant-role updates.

Useful? React with 👍 / 👎.

@seratch seratch changed the title fix(realtime): update assistant message status to completed when audio is done fix(realtime): #1434 update assistant message status to completed when audio is done Apr 18, 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.

in history_updated events, the status of 'assistant' is always 'in_progress'. After the assistant has spoken or generated audio, it must say 'Completed'

1 participant