Skip to content

all attached plugin-specific realtime session event handlers lost when retart_session with the same model. #6559

Description

@moz164164

Bug Description

According to deepwiki https://deepwiki.com/search/can-fallbackrealtimesession-im_15e6ca5e-6280-4091-b3d6-65ddfb72aedf?mode=deep,
for livekit.agents.llm.RealtimeModelAapter, openai specific realtime session event handlers are attached to its child realtime session and handlers for general reatime session event in

_FORWARDED_EVENTS: tuple[EventTypes, ...] = (
) are forwarded to attached to its parent realtime session.

According to source codes, when implementing llm.restart_session(switch_model=False) , its old child realtime session are closed and discarded and its parent realtime session only keep those handlers of those general realtime session event, and thus all attached plugin-specific realtime session event handlers (eg. openai specific realtime event handlers etc.) will lose

We think this is not a right behavior since you mentioned livekit.agents.llm.RealtimeModelAapter will preserve the agent's bound event handlers in PR #6282.

Please correct the source code so that all attached plugin-specific realtime session event handlers should be automatically forwarded to the new child realtime session if llm.restart_session(switch_model=False) is implemented.

Expected Behavior

all attached plugin-specific realtime session event handlers should be automatically forwarded to the new child realtime session if llm.restart_session(switch_model=False) is implemented.

Reproduction Steps

  1. set
llm=RealtimeModelFallbackAdapter(
 [openai.realtime.RealtimeModel(),
openai.realtime.RealtimeModel.with_azure()]
)
  1. attach openai-specific realtime session event handlers:
   rt_session = agent.realtime_llm_session
   @rt_session._active.on("openai_server_event_received")
   def on_openai_server_event_received(event: dict[str, Any]) -> None:
        logger.info("openai_server_event_received handling"
  1. implement
await agent.llm.restart_session(switch_model=False)
  1. try to simulate to emit "openai_server_event_received" realtime session event
  2. check whether the attached openai-specific realtime session event handlers still work

Operating System

MacOS, linux

Models Used

Openai gpt-realtime, Azure gpt-realtime

Package Versions

livekit=1.1.13
livekit-agents=1.6.6
livekit-api=1.2.0

Session/Room/Call IDs

No response

Proposed Solution

Additional Context

No response

Screenshots and Recordings

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions