Repository navigation
Conversation
…ad of re-raising it emit re-raised every TypeError so that an event with too few arguments for the handler would raise. A TypeError from inside the handler was re-raised as well, which skipped the remaining handlers and interrupted the caller. The arguments are now checked against the signature before the call, and the call is wrapped on its own.
TANGBUDU
requested review from
changt,
cloudwebrtc,
lukasIO and
xianshijing-lk
as code owners
November 19, 2026 00:57
once() registers a wrapper that takes any arguments, so the signature check passed for it and a once handler given too few arguments was logged instead of raising. The check now uses the callback the wrapper holds.
This branch has not been deployed
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.
Fixes #957
Problem
EventEmitter.emitlogs an exception raised by a handler and moves on, except for aTypeError, which it re-raises. #293 added that so an event carrying fewer arguments than the handler takes would raise. Butexcept TypeError: raisealso covers aTypeErrorraised inside the handler, so a mistake such as subscriptingNonestops the remaining handlers and interrupts whoever calledemit. In livekit-agents a handler onconversation_item_addedthat does this ends the generation task, and the tool result is never sent to the model.Fix
emitnow checks the arguments against the handler's signature withsig.bind()before the call. Too few arguments still raise aTypeError, astest_argsexpects. The call itself is wrapped on its own, so anything raised inside the handler is logged, aTypeErrorincluded.once()registers a wrapper that takes any arguments, so for those handlers the check is made against the callback the wrapper holds. Aoncehandler given the wrong number of arguments raises as it does on main.Testing
Three tests added to
tests/rtc/test_emitter.py: a handler that subscriptsNonefollowed by a second handler, foronand foronce, and aoncehandler given too few arguments. On main the first two fail (emitraises and the second handler does not run); with the change the suite is 15 passed.I also reran the livekit-agents cases from the issue against the patched
event_emitter.py. With a failing handler onconversation_item_added,function_tools_executed,speech_createdoragent_state_changed, the error is logged and the tool result reaches the model.