Subject: Same Job ID dispatched twice to the same ...
# ask-ai
a
Subject: Same Job ID dispatched twice to the same room after agent session closes Hi team, We're experiencing an issue where the same job.id appears to be dispatched twice to the same room. Here's what we observed in our logs: Timeline: 145322 - [JOB:AJ_FxE7xhip4M8t] entrypoint() called (first time) 145412 - Warm transfer completed successfully 145414 - Agent session closed via session.aclose() 145522 - [JOB:AJ_FxE7xhip4M8t] entrypoint() called (second time) ← Same job ID! Context: • We're running a voice agent that handles inbound SIP calls • After a successful warm transfer, we call await self.session.aclose() to close the agent session • The room still has participants (original caller + transfer target) after the agent leaves • About 1 minute later, our entrypoint function gets called again with the same job ID • The second dispatch fails because it tries to get agent_id from participant metadata, but the participant is now the transfer target (who doesn't have agent metadata) Questions: 1. Is it expected behavior for LiveKit to re-dispatch an agent to a room when the agent leaves but participants remain? 2. If so, does it reuse the same job.id or create a new one? 3. What's the recommended way to prevent re-dispatch after a warm transfer? Should we update room metadata, delete the room, or handle this differently? Environment: • livekit-agents version: [your version] • Python SDK version: [your version] Thanks!
t
Thanks for reaching out, 한승준. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your three questions about the duplicate dispatch after the warm transfer and the best ways to prevent it. 1) Is re-dispatch expected when an agent leaves but participants remain? • Yes. If a room is configured for automatic dispatch (dispatch rules, SIP dispatch, or room dispatch settings), LiveKit will try to dispatch an agent whenever dispatch conditions are met and there is no active agent in the room. 2) Does LiveKit reuse the same job.id or create a new one? • Each new dispatch should create a new job with a unique job ID. Seeing the exact same job ID invoked a second time usually means the original job’s process/context was resumed or not fully cleaned up (for example, a job recovery, process restart, or the agent process re-entered the entrypoint), not a normal new-dispatch-with-same-ID flow. 3) Recommended ways to prevent re-dispatch after a warm transfer • Delete the room after transfer completion: calling the room deletion API is the simplest way to ensure no further dispatch happens once the agent’s work is finished. • Update room metadata/configuration to disable dispatch: set a flag (e.g.,
transfer_complete
) in room metadata and ensure your dispatch rules or logic exclude rooms with that flag. • Use one-time dispatch or explicit dispatch control: use one-time dispatch tokens (
once=true
) or avoid automatic dispatch entirely and dispatch agents only via your application logic so you control when agents can be assigned. Troubleshooting suggestions (brief) • Confirm
await self.session.aclose()
fully completes before your agent process exits. • Check agent server logs to see whether the second call is a job recovery/restart vs a new dispatch. • If the second invocation truly appears as the same job resuming, inspect job lifecycle / cleanup on the agent host. If you’d like, tell me which prevention approach you prefer (delete room vs metadata flag vs explicit/one-time dispatch) and I’ll provide the exact API/SDK calls or a short code example for your Python SDK. Sources: Job lifecycle | LiveKit docs | server-sdk-ruby | livekit/livekit_composite | DeepWiki