important-judge-78504
10/14/2025, 2:48 PMdrain_timeout=0, when it receives a SIGTERM, it should stop accepting new jobs and stay alive until all active calls finish right? when does the worker register an active call, like what is the event that causes the worker to consider a call "active". im seeing some instances of calls being shut down when the worker receives a SIGTERM, instead of waiting for those calls to completetall-airline-16756
10/14/2025, 2:48 PMtall-airline-16756
10/14/2025, 2:50 PMdrain_timeout=0 and receives a SIGTERM, it stops accepting new jobs but doesn’t wait for active calls to finish. This behavior is mainly designed for development scenarios where a quick shutdown is more important than a graceful termination.
To clarify, a call is considered "active" when it has a running job process. This means a job becomes active once the worker starts a new process and the agent begins execution. The worker keeps track of these active jobs and, usually, would wait for them to complete during the drain process.
However, with drain_timeout=0, the worker times out immediately and doesn’t wait for active jobs to finish, which might cause calls to be shut down abruptly. For production environments, I’d recommend setting a non-zero drain_timeout so active calls can complete gracefully, helping to avoid any disruptions. If you need help adjusting this or have any questions, feel free to ask—I’m here to help!
Sources: Worker options | LiveKit Docs | agents/src/cli.ts | livekit-agents/livekit/agents/cli/_run.py | Job lifecycle | LiveKit Docs | Deploying to custom environments | LiveKit Docsimportant-judge-78504
10/14/2025, 2:50 PMtall-airline-16756
10/14/2025, 2:51 PMdrain_timeout of 0 doesn’t make the worker wait forever. Instead, it means the worker will stop right away without waiting for any active processes to finish when it gets a shutdown signal. This is especially useful during development when you want things to shut down quickly.
If you’d prefer the worker to wait as long as needed for active jobs to complete before shutting down, you can set drain_timeout to None or simply leave the timeout out. This way, the worker patiently waits for all active processes to wrap up before it shuts down.
Sources: Worker options | LiveKit Docs | livekit-agents/livekit/agents/worker.pyimportant-judge-78504
10/14/2025, 3:15 PMtall-airline-16756
10/14/2025, 3:16 PMdrain_timeout of 0 is treated as False in the condition if timeout:. This means the asyncio.wait_for logic is skipped, and the worker goes straight to executing _join_jobs() without applying any timeout.
That said, this doesn't lead to indefinite waiting. Instead, it means the worker bypasses the waiting phase altogether and moves straight to shutting down. This behavior with drain_timeout=0 is intentionally designed to disable the draining process, which is why it’s often handy during development when you want quick shutdowns.
If your goal is for the worker to wait indefinitely until all active jobs complete, you’d want to set drain_timeout to None. This way, the worker patiently waits for all ongoing processes to finish without any timeout.
Sources: livekit-agents/livekit/agents/worker.py | Worker options | LiveKit Docsimportant-judge-78504
10/14/2025, 3:17 PMtall-airline-16756
10/14/2025, 3:18 PMdrain_timeout=0, it means the processes won’t have a chance to shut down naturally. Instead, it skips the usual draining phase and forces an immediate shutdown, without waiting for any active jobs to finish. This is designed on purpose and is mostly useful in development or testing settings where you need things to stop quickly.
Now, if you'd like your worker to wait and allow processes to shut down more gently, you can set a positive drain_timeout value—like 1800 seconds (which is 30 minutes)—or simply leave it as None. That way, the worker gives active jobs some time to wrap up nicely before shutting down. I hope this helps you get the behavior you’re looking for!
Sources: Job lifecycle | LiveKit Docs | Worker options | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...important-judge-78504
10/14/2025, 3:19 PMtall-airline-16756
10/14/2025, 3:19 PMdrain method code! I’d love to help clarify how setting drain_timeout=0 works. When you set it to zero, it doesn’t explicitly force a shutdown. Instead, it skips the timeout logic because the condition if timeout: evaluates as False. So, the method bypasses asyncio.wait_for and directly calls _join_jobs(). This means the worker tries to join active processes without enforcing any timeout.
In real-world use, drain_timeout=0 is often chosen during development when you want a quick shutdown. The worker stops accepting new jobs and goes into draining mode, but it won’t wait for active jobs to finish before shutting down. This behavior is intentional and really useful when you want immediate termination in non-production settings.
If your goal is for the worker to wait patiently for processes to finish shutting down naturally, I’d recommend using a positive drain_timeout value or setting it to None so it waits indefinitely.
Sources: livekit-agents/livekit/agents/worker.py | agents/src/cli.tsimportant-judge-78504
10/14/2025, 3:21 PMtall-airline-16756
10/14/2025, 3:22 PMproc.join() does wait for each process to exit during the drain process. In your code, the _join_jobs() function goes through all the processes in the pool and calls await proc.join() for each one that has an active job. This way, the worker patiently waits for these processes to finish before moving forward.
Also, if you’ve set a timeout (like drain_timeout), the worker will kindly raise an error if the processes don’t finish within that time. Otherwise, without a timeout, it will wait as long as needed for all jobs to complete. I hope this helps clarify things!
Sources: Worker options | LiveKit Docs | livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py | agents/src/cli.tsimportant-judge-78504
10/14/2025, 3:23 PMtall-airline-16756
10/14/2025, 3:23 PMdrain_timeout=0, the worker doesn’t enforce a timeout and patiently waits for each process to finish naturally by calling proc.join(). This means the worker won’t forcefully terminate any processes but kindly allows them to complete their active jobs before shutting down.
I understand how this can be a bit confusing. The key thing is that while drain_timeout=0 skips the timeout logic, it definitely doesn’t skip waiting for those active jobs to finish. So, the worker will still wait for all processes to exit unless they’re explicitly terminated by other means.important-judge-78504
10/14/2025, 5:05 PMtall-airline-16756
10/14/2025, 5:06 PMdrain_timeout=0, the worker is designed to wait for active processes to finish naturally before shutting down. However, if you notice the worker shutting down while a process is still active, it might be due to a couple of reasons:
• The worker could be running in development mode, where drain_timeout=0 allows for a quicker shutdown and might skip the full drain process.
• There might be a misconfiguration or some unexpected behavior during the shutdown sequence, such as the worker not properly waiting for proc.join() to complete.
To help you get to the bottom of this, you might want to:
• Check whether the worker is in development or production mode to see if this behavior matches the expected setup.
• Take a look at the logs for any errors or interruptions happening during the drain process.
• Make sure the proc.join() logic is running as it should and isn’t being skipped too early.
If you find that this issue continues to happen in production mode, it would be a good idea to dig a little deeper into the worker’s shutdown sequence. I’m here to help if you need any further guidance!
Sources: Worker lifecycle | LiveKit Docs | Worker options | LiveKit Docs | Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/utils/connection_pool.py | agents/src/cli.tsimportant-judge-78504
10/14/2025, 5:19 PMtall-airline-16756
10/14/2025, 5:19 PMCreateSIPParticipantRequest if the SIP participant isn’t being tracked properly within the active session. This can happen in a few ways:
• If the wait_until_answered flag isn’t set to true, the worker might assume the participant is active too soon.
• If the SIP participant isn’t correctly linked to the room or job context, the worker might mistakenly treat the job as inactive.
• If the SIP call setup steps (like INVITE, ring, answer) take longer than the default shutdown_process_timeout of 60 seconds, the worker could end the process before the call is fully established.
To help you move forward smoothly, here are some friendly suggestions:
• Make sure to set wait_until_answered=true in the CreateSIPParticipantRequest so the worker waits until the call is actually answered.
• Double-check that the SIP participant is properly added to the room and that the worker is keeping an eye on the room for active participants.
• If you notice the SIP call setup often takes longer than 60 seconds, consider increasing the shutdown_process_timeout in WorkerOptions.
• Keep an eye on the SIP participant’s call status to ensure it moves to "active" during the process.
Following these steps should help the worker recognize the process as active and prevent any premature shutdowns. If you need any more help or have questions, I’m here for you!
Sources: pkg/service/service.go | livekit-agents/livekit/agents/worker.py | Job lifecycle | LiveKit Docs | Making outbound calls | LiveKit Docs