fierce-jordan-44682
10/25/2025, 9:21 AMtall-airline-16756
10/25/2025, 9:21 AMtall-airline-16756
10/25/2025, 9:22 AMprewarm function is called once per job process when starting a LiveKit worker. It helps to initialize or warm up processes, like preloading resources, before jobs are assigned.
One important thing to keep in mind is that the prewarm function itself can’t be defined as an async function. It needs to be a synchronous callable, as outlined in the WorkerOptions interface. While you’re free to use asyncio functions elsewhere in your code, the prewarm function is designed specifically for synchronous setup tasks.
If you do need to perform async initialization, a great place to handle that is in your entrypoint function, where async operations are fully supported. I hope this helps clarify things! Feel free to ask if you have any more questions.
Sources: Worker options | LiveKit Docs | agent/main.py | examples/voice_agents/realtime_turn_detector.pyfierce-jordan-44682
10/25/2025, 9:31 AMtall-airline-16756
10/25/2025, 9:31 AMctx.proc isn’t shared across all jobs in a LiveKit worker. Each job runs in its own separate process, and ctx.proc (which is an instance of JobProcess) belongs specifically to that individual job process.
Now, the JobProcess object does have a userData dictionary where you can store resources across job invocations within the same process. However, this data isn’t shared between different job processes. This isolation helps keep everything stable and ensures that one job’s issues won’t impact others.
Sources: Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit Docs | Worker lifecycle | LiveKit Docsfierce-jordan-44682
10/25/2025, 9:40 AMtall-airline-16756
10/25/2025, 9:41 AMUserData class pattern.
Here’s a friendly guide on how to manage your database connections smoothly:
• Wrap your database connection inside a UserData class and initialize it in the entrypoint function. This way, the connection stays accessible throughout the life of that process.
• Use a ThreadPoolExecutor for your database operations to keep the async event loop running smoothly—this is especially helpful if you’re working with SQLite.
• If you’re working with distributed deployments, it’s a great idea to use message buses for real-time state sharing instead of relying solely on databases, since databases can sometimes become bottlenecks in these scenarios.
If you’d like, I’m here to help with more detailed guidance or examples—just let me know!
Sources: complex-agents/personal_shopper/README.md | How We Built a Globally Distributed WebRTC Mesh Network | How We Built a Globally Distributed WebRTC Mesh Network | examples/avatar_agents/audio_wave/dispatcher.py