fix: handle cancelled single function tools as tool failures#2762
Merged
fix: handle cancelled single function tools as tool failures#2762
Conversation
Co-authored-by: Codex <noreply@openai.com>
55dede7 to
7abbed9
Compare
Co-authored-by: Codex <noreply@openai.com>
seratch
requested changes
Mar 25, 2026
Co-authored-by: Codex <noreply@openai.com>
Contributor
Author
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe9f06e436
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-authored-by: Codex <noreply@openai.com>
seratch
approved these changes
Mar 25, 2026
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
CancelledErrorfrom a function tool via the normal tool-failure path, even when it is the only function tool in the turnAgent.as_tool()fallback output when a recovered nested run ends without a final messageWhy
Single-tool turns were handling
CancelledErrordifferently from turns with multiple function tools. That asymmetry could cancel the entire run instead of surfacing a normal tool error back to the model.The same path also exposed a nested agent-tool regression: when a recovered nested run ended without a final message,
Agent.as_tool()returned an empty string instead of the nested tool failure output.Validation
ruff check src/agents/agent.py src/agents/run_internal/tool_execution.py tests/test_example_workflows.py tests/test_run_step_execution.py tests/test_agent_runner.py tests/test_agent_runner_streamed.pyPYTHONPATH=src pytest -q tests/test_example_workflows.pyPYTHONPATH=src pytest -q tests/test_run_step_execution.py -k 'single_tool_call_uses_default_failure_error_function_for_cancelled_tool or multiple_tool_calls_use_default_failure_error_function_for_manual_cancelled_tool or test_execute_function_tool_calls_parent_cancellation_skips_post_invoke_work'PYTHONPATH=src pytest -q tests/test_agent_runner.py -k 'single_tool_call_with_cancelled_tool_reaches_final_output or parallel_tool_call_with_cancelled_sibling_reaches_final_output'PYTHONPATH=src pytest -q tests/test_agent_runner_streamed.py -k 'streamed_single_tool_call_with_cancelled_tool_reaches_final_output or streamed_parallel_tool_call_with_cancelled_sibling_reaches_final_output'