Skip to content

fix: send realtime tool failure outputs#3435

Open
pragnyanramtha wants to merge 1 commit into
openai:mainfrom
pragnyanramtha:pragnyan/fix-realtime-tool-failure-output
Open

fix: send realtime tool failure outputs#3435
pragnyanramtha wants to merge 1 commit into
openai:mainfrom
pragnyanramtha:pragnyan/fix-realtime-tool-failure-output

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Summary

Known realtime function tool and handoff failures could leave the model-visible tool call incomplete. When tool execution ran in the background, the SDK emitted a local RealtimeError, but it did not send a RealtimeModelSendToolOutput back to the model, so the realtime session could wait until the server-side tool timeout.

This PR keeps the existing exception path intact while completing the model-visible tool call:

  • send RealtimeModelSendToolOutput(start_response=True) when a known function tool raises, including timeout_behavior="raise_exception"
  • send the same model-visible failure output when a realtime handoff invocation raises or returns an invalid result
  • preserve the propagated exception / stored exception behavior so application observers still receive the local error path
  • add regression coverage for direct tool calls, async background tool calls, timeout exceptions, and handoff failures

Test plan

Passed:

  • make format
  • make format-check
  • make lint
  • uv run pytest tests/realtime/test_session.py::TestToolCallExecution::test_function_tool_timeout_raise_exception_propagates tests/realtime/test_session.py::TestToolCallExecution::test_function_call_event_timeout_raise_exception_enqueues_error tests/realtime/test_session.py::TestToolCallExecution::test_function_call_event_exception_sends_model_visible_output tests/realtime/test_session.py::TestToolCallExecution::test_handoff_tool_failure_sends_model_visible_output -q
  • uv run pytest tests/realtime/test_session.py -q (78 passed)
  • uv run pytest tests/realtime -q (246 passed)
  • uv run mypy src/agents/realtime/session.py tests/realtime/test_session.py
  • uv run pyright src/agents/realtime/session.py tests/realtime/test_session.py
  • git diff --check

Attempted:

  • make typecheck was attempted, but repo-wide checks failed outside this patch on existing optional-extra/baseline issues, including missing numpy, litellm, temporalio, sqlalchemy, boto3/botocore, and existing runloop sandbox type-form errors. The touched realtime files pass targeted mypy and pyright as listed above.

Issue number

Fixes #3356

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation (no docs change needed for this internal bug fix)
  • I've run make lint and make format
  • I've made sure tests pass

@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 16, 2026 18:55
Copilot AI review requested due to automatic review settings May 16, 2026 18:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Realtime known tool failures (exception/timeout) do not send model-visible output

2 participants