fix: send error output to model when realtime tool call raises exception#3437
Closed
rmotgi1227 wants to merge 1 commit into
Closed
fix: send error output to model when realtime tool call raises exception#3437rmotgi1227 wants to merge 1 commit into
rmotgi1227 wants to merge 1 commit into
Conversation
Closes openai#3356. When a known tool raised an exception (e.g. ToolTimeoutError with timeout_behavior="raise_exception", or any user-raised error), the exception propagated out of _handle_tool_call, got logged by _on_tool_call_task_done, but NO RealtimeModelSendToolOutput was ever sent. The model would then wait for a function result that never arrived — effectively hanging the session for ~30 seconds until the server-side timeout fired. Wrap invoke_function_tool in a try/except. On failure, format an error string via default_tool_error_function and send it as tool output with start_response=True so the model can recover and continue. The exception is not re-raised, so the task completes normally and _stored_exception is not set (the session stays alive). The pattern mirrors the existing unknown-tool branch (fixed in openai#3287): both cases now guarantee the model always receives a tool output. Update three tests that asserted the old "exception propagates, no output sent" behavior to reflect the new correct contract. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3356.
When a known tool raised an exception (
ToolTimeoutErrorwithtimeout_behavior="raise_exception", or any user-raised error), the exception propagated out of_handle_tool_call, got logged by_on_tool_call_task_done, but noRealtimeModelSendToolOutputwas ever sent. The model waited for a function result that never arrived — effectively hanging the session for ~30 seconds until the server-side timeout fired.The same class of problem was already fixed for the unknown-tool branch in #3287, which ensures the model always gets a reply. The known-tool exception branch was the remaining gap.
Fix: Wrap
invoke_function_toolin atry/exceptinside_handle_tool_call. On failure, format an error string viadefault_tool_error_functionand send it as a tool output withstart_response=Trueso the model can recover and continue. The exception is not re-raised — the task completes normally and_stored_exceptionis not set, keeping the session alive.Before/after for the three affected paths:
Test plan
test_function_tool_timeout_raise_exception_propagates— no longer expectsToolTimeoutErrorto propagate; now verifies a model-visible error output is senttest_function_call_event_timeout_raise_exception_enqueues_error—_stored_exceptionis nowNone(session stays alive); model receives tool output instead of hangingtest_function_tool_exception_handling— exception is now caught; model receives error outputIssue number
Closes #3356.
Checks
make lintandmake format