fix: complete realtime tool failures#3530
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03a3dde34c
ℹ️ 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".
| if await self._send_function_tool_failure_output( | ||
| event, | ||
| tool=func_tool, | ||
| tool_context=tool_context, | ||
| agent=agent, | ||
| error=exc, | ||
| ): | ||
| mark_completed = True |
There was a problem hiding this comment.
Preserve the original tool failure if output sending fails
When the model send for this synthesized failure output fails, _send_tool_output_completion raises _PendingToolOutputSendError from inside the except block, replacing the original tool exception. In the async tool-call path _on_tool_call_task_done treats that wrapper as a retryable send failure and returns without storing or surfacing the original tool error; when the same call id is retried it only flushes the cached output and the app never gets the expected RealtimeError/exception for the failed tool. This affects transient send_event failures while reporting a tool exception, so the new failure-output path does not always keep the existing local exception behavior.
Useful? React with 👍 / 👎.
03a3dde to
e1e6dd4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1e6dd44f3
ℹ️ 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".
| await self._send_handoff_failure_output( | ||
| event, | ||
| tool_context=tool_context, | ||
| error=exc, | ||
| ) |
There was a problem hiding this comment.
Preserve handoff failures when output sending fails
For handoff failures, if _send_tool_output_completion raises here (for example, a transient send_event failure while sending this synthesized error output), this await replaces the original handoff exception with _PendingToolOutputSendError; in the async task path _on_tool_call_task_done treats that wrapper as retryable and returns without storing or emitting the handoff failure, and a later duplicate call just flushes the cached output. That means applications can miss the handoff exception even though the model eventually receives the failure output.
Useful? React with 👍 / 👎.
Summary
Fixes #3356.
Known realtime tool calls could fail before the SDK sent a tool output back to the model. In that case the app still received the local exception path, but the model-visible function call stayed incomplete.
This change keeps the local exception behavior and completes the model-facing call first:
RealtimeModelSendToolOutput(start_response=True)when a known function tool raises, includingtimeout_behavior="raise_exception"RealtimeErrorpath for application observersTo verify
uv run pytest tests/realtime/test_session.py -quv run ruff check src/agents/realtime/session.py tests/realtime/test_session.pyuv run mypy src/agents/realtime/session.py tests/realtime/test_session.pygit diff --check