Skip to content

fix: handle cancelled single function tools as tool failures#2762

Merged
seratch merged 4 commits intomainfrom
dev/elainegan/sevbot-fast-fail-sdk-clean
Mar 25, 2026
Merged

fix: handle cancelled single function tools as tool failures#2762
seratch merged 4 commits intomainfrom
dev/elainegan/sevbot-fast-fail-sdk-clean

Conversation

@elainegan-openai
Copy link
Contributor

@elainegan-openai elainegan-openai commented Mar 24, 2026

Summary

  • handle CancelledError from a function tool via the normal tool-failure path, even when it is the only function tool in the turn
  • preserve nested Agent.as_tool() fallback output when a recovered nested run ends without a final message
  • add regression coverage for execution, non-streamed runner, streamed runner, and nested agent-tool paths

Why

Single-tool turns were handling CancelledError differently 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.py
  • PYTHONPATH=src pytest -q tests/test_example_workflows.py
  • PYTHONPATH=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'

@github-actions github-actions bot added bug Something isn't working feature:core labels Mar 24, 2026
@elainegan-openai elainegan-openai changed the title [SEVBot] Recover single cancelled function tools Recover single cancelled function tools Mar 24, 2026
Co-authored-by: Codex <noreply@openai.com>
@elainegan-openai elainegan-openai force-pushed the dev/elainegan/sevbot-fast-fail-sdk-clean branch 2 times, most recently from 55dede7 to 7abbed9 Compare March 24, 2026 16:52
Co-authored-by: Codex <noreply@openai.com>
@elainegan-openai elainegan-openai changed the title Recover single cancelled function tools Handle cancelled single function tools as tool failures Mar 25, 2026
@elainegan-openai elainegan-openai marked this pull request as ready for review March 25, 2026 00:20
@seratch seratch changed the title Handle cancelled single function tools as tool failures fix: handle cancelled single function tools as tool failures Mar 25, 2026
@seratch seratch added this to the 0.13.x milestone Mar 25, 2026
Co-authored-by: Codex <noreply@openai.com>
@elainegan-openai
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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 seratch merged commit 687e974 into main Mar 25, 2026
9 checks passed
@seratch seratch deleted the dev/elainegan/sevbot-fast-fail-sdk-clean branch March 25, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants