Skip to content

fix(rtc): log a TypeError raised inside an EventEmitter handler instead of re-raising it - #958

Open
TANGBUDU wants to merge 2 commits into
livekit:mainfrom
TANGBUDU:fix/emitter-handler-type-error
Open

TANGBUDU wants to merge 2 commits into
livekit:mainfrom
TANGBUDU:fix/emitter-handler-type-error

Conversation

@TANGBUDU

@TANGBUDU TANGBUDU commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #957

Problem

EventEmitter.emit logs an exception raised by a handler and moves on, except for a TypeError, which it re-raises. #293 added that so an event carrying fewer arguments than the handler takes would raise. But except TypeError: raise also covers a TypeError raised inside the handler, so a mistake such as subscripting None stops the remaining handlers and interrupts whoever called emit. In livekit-agents a handler on conversation_item_added that does this ends the generation task, and the tool result is never sent to the model.

Fix

emit now checks the arguments against the handler's signature with sig.bind() before the call. Too few arguments still raise a TypeError, as test_args expects. The call itself is wrapped on its own, so anything raised inside the handler is logged, a TypeError included.

once() registers a wrapper that takes any arguments, so for those handlers the check is made against the callback the wrapper holds. A once handler 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 subscripts None followed by a second handler, for on and for once, and a once handler given too few arguments. On main the first two fail (emit raises 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 on conversation_item_added, function_tools_executed, speech_created or agent_state_changed, the error is logged and the tool result reaches the model.

…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.
devin-ai-integration[bot]

This comment was marked as resolved.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EventEmitter.emit re-raises a TypeError raised inside a handler, while other exceptions are only logged

1 participant