fix(realtime): raise UserError for input_type without on_handoff#3248
Merged
seratch merged 1 commit intoopenai:mainfrom May 8, 2026
Merged
Conversation
The assertion in realtime_handoff was tautological: `(A and B) or not (A and B)` is always True. Calling `realtime_handoff(agent, input_type=int)` would slip past it and hit a misleading downstream AssertionError under default Python, or silently produce a broken Handoff under `python -O`. Replace with an explicit UserError that runs unconditionally and matches the documented call-shape contract (the overloads only accept input_type alongside on_handoff).
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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
The validation guard at the top of `realtime_handoff()` is a tautology:
```python
assert (on_handoff and input_type) or not (on_handoff and input_type), (
"You must provide either both on_handoff and input_type, or neither"
)
```
`(X) or not (X)` is always `True`, so the assertion never fires. When a caller does `realtime_handoff(agent, input_type=int)` (input_type without on_handoff), the function falls through to a less helpful `assert callable(on_handoff)` further down, or — under `python -O` where assertions are stripped — silently constructs a `Handoff` whose `on_invoke_handoff` callable hits a confusing `TypeError: None is not a callable object` at first invocation.
This mirrors the same pattern in `agents/handoffs/init.py` line 255, but the realtime path was the only one missed when Wave 7 cleaned things up around #3243. Replace the dead assertion with an explicit `UserError` so the contract documented by the overloads (input_type only with on_handoff) is enforced uniformly, including under `-O`.
Test plan
🤖 Generated with Claude Code