fix(realtime): #1434 update assistant message status to completed when audio is done#2942
fix(realtime): #1434 update assistant message status to completed when audio is done#2942DevAbdullah90 wants to merge 2 commits intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
💡 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".
| 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"}) |
There was a problem hiding this comment.
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 👍 / 👎.
0f01c8d to
ac9b7a4
Compare
|
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. |
There was a problem hiding this comment.
💡 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, |
There was a problem hiding this comment.
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 👍 / 👎.
Fix Assistant Message History Status
Summary
This PR resolves an issue where assistant message items in the
RealtimeSessionhistory incorrectly retain anin_progressstatus even after the model has finished generating audio/text.Related Issues
Fixes #1434
Changes
src/agents/realtime/session.py: Updated theon_eventhandler foraudio_doneevents. It now locates the corresponding item in the session history and updates itsstatusfield to"completed".src/agents/realtime/session.py: Added an explicit emission of theRealtimeHistoryUpdatedevent 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
audio_doneevents correctly transition the targeted item's status tocompletedin a local reproduction script.tests/realtime/test_session.pypass.Why this is necessary
Without this fix, client applications relying on the
statusfield 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.