Repository navigation
fix: cancel sibling enablement checks on failure - #4005
Conversation
There was a problem hiding this comment.
💡 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".
seratch
left a comment
There was a problem hiding this comment.
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.
Summary
Dynamic
FunctionTool.is_enabledandHandoff.is_enabledcallbacks 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 passedUV_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 passedUV_PYTHON=3.12 uv run pytest tests/test_run_step_execution.py -q— 89 passedUV_PYTHON=3.12 make format— passedUV_PYTHON=3.12 make lint— passedUV_PYTHON=3.12 make typecheck— mypy and pyright passed; mypy checked 833 source filesUV_PYTHON=3.12 make tests— non-serial: 5,782 passed, 3 skipped; serial: 28 passed, 5 skippedUV_PYTHON=3.12 bash .agents/skills/code-change-verification/scripts/run.sh— all commands passedThe 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
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR