Skip to content

fix: cancel sibling enablement checks on failure - #4005

Merged
seratch merged 2 commits into
openai:mainfrom
hsusul:fix/cancel-failed-enable-checks
Jul 29, 2026
Merged

seratch merged 2 commits into
openai:mainfrom
hsusul:fix/cancel-failed-enable-checks

Conversation

@hsusul

@hsusul hsusul commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Dynamic FunctionTool.is_enabled and Handoff.is_enabled callbacks are evaluated concurrently. If one callback raised, asyncio.gather() propagated its exception while sibling callbacks kept running after the SDK call returned.

This change adds a private cancel-and-drain gather helper and uses it for regular-agent, execution-time, and Realtime tool/handoff enablement checks. The original exception is preserved, while unfinished sibling callbacks are cancelled and awaited before control returns.

Test plan

  • UV_PYTHON=3.12 uv run pytest tests/test_function_tool.py::test_get_all_tools_cancels_sibling_enablement_checks_on_error tests/test_handoff_tool.py::test_get_handoffs_cancels_sibling_enablement_checks_on_error tests/test_run_step_execution.py::test_function_tool_enablement_error_cancels_sibling_checks_before_execution tests/realtime/test_realtime_model_settings.py::test_filter_enabled_tools_cancels_sibling_checks_on_error tests/realtime/test_realtime_handoffs.py::test_collect_enabled_handoffs_cancels_sibling_checks_on_error -q — 5 passed
  • UV_PYTHON=3.12 uv run pytest tests/test_function_tool.py tests/test_handoff_tool.py tests/realtime/test_realtime_handoffs.py tests/realtime/test_realtime_model_settings.py -q — 109 passed
  • UV_PYTHON=3.12 uv run pytest tests/test_run_step_execution.py -q — 89 passed
  • UV_PYTHON=3.12 make format — passed
  • UV_PYTHON=3.12 make lint — passed
  • UV_PYTHON=3.12 make typecheck — mypy and pyright passed; mypy checked 833 source files
  • UV_PYTHON=3.12 make tests — non-serial: 5,782 passed, 3 skipped; serial: 28 passed, 5 skipped
  • UV_PYTHON=3.12 bash .agents/skills/code-change-verification/scripts/run.sh — all commands passed

The regression tests coordinate callbacks with asyncio.Event, assert the original error, and verify that sibling cancellation and finalization complete before the caller regains control.

This changes no public API or successful-result ordering. Error paths now wait for cancelled callback cleanup, matching the existing concurrent guardrail cleanup behavior.

Issue number

N/A — no matching open or closed issue/PR was found. #3115 / #3118 concern execution-time authorization rechecks rather than cleanup after an enablement callback fails.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

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

Copy link
Copy Markdown

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: 66057f5ed7

ℹ️ 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".

Comment thread src/agents/realtime/_tool_filtering.py Resolved

@seratch seratch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. The underlying lifecycle issue is valid, and the cancel-and-drain helper is directionally correct.

One merge-blocking gap remains: the Realtime paths still compose tool, handoff, and instruction resolution with plain asyncio.gather() in _build_model_settings_from_agent(), _resolve_dispatch_snapshot(), _filter_enabled_dispatch_snapshot(), and _get_updated_model_settings_from_agent(). If a tool group raises while a handoff group is still blocked, the inner helper drains only the tool tasks; the outer gather returns while the handoff callback continues running.

Please apply the same cancel-and-drain ownership at all four outer Realtime resolution boundaries. Add regression coverage that places a failing callback in one group and a blocking callback in another through the Realtime settings/session path, then verifies that the original exception is preserved and the blocking callback is cancelled and finalized before control returns.

This is needed because the current tests cover only siblings within a single tool or handoff list. Once the outer ownership boundaries and cross-group regression coverage are addressed, this should be ready for another review.

@seratch seratch added this to the 0.19.x milestone Jul 29, 2026
@seratch
seratch merged commit e75cdd2 into openai:main Jul 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants