delightful-planet-44653
11/26/2025, 6:50 AMreq.reject()), what happens to the job request? Is it just dropped / failed, or does LiveKit queue it and retry when a worker becomes free?
What’s the recommended way to handle this scenario? What would the code changes look like to handle this?tall-airline-16756
11/26/2025, 6:51 AMtall-airline-16756
11/26/2025, 6:51 AMreq.reject(), and how you should handle that in your system—I'll explain what LiveKit does and give a recommended approach and code examples.
What happens to the job
• LiveKit does not permanently drop the request. If a worker rejects a job (via req.reject()), or doesn't accept within the assignment timeout, LiveKit will forward the request to another available agent server.
• LiveKit uses a single-assignment, retrying dispatch: a job is re-routed across the pool until an agent accepts or no agents remain available. There is no persistent queue that stores jobs indefinitely on a single server.
Recommended approach
• Rely on LiveKit’s redistribution behavior, but reduce rejections by:
◦ Implementing an accurate `load_fnc`/`loadFunc` so each agent reports realistic availability.
◦ Using autoscaling to add agents before you hit capacity (scale earlier than your load_threshold).
◦ Only calling req.reject() when the agent truly cannot handle the job (missing resources, incompatible environment).
• If you need guaranteed durable queuing or retries beyond the built-in redistribution, implement an external queue (e.g., Redis, SQS) that re-enqueues jobs and retries with backoff until assigned.
Code examples
1) Tighter load function — Python
def compute_load(agent_server):
# Report load as fraction: accept only if fewer than 5 active jobs
return len(agent_server.active_jobs) / 10.0
server = AgentServer(load_threshold=0.8)
server.load_fnc = compute_load
2) Tighter load function — Node.js/TypeScript
const computeLoad = (agentServer: AgentServer): number => {
return agentServer.activeJobs.length / 10.0; // load = 0.5 at 5 jobs
};
const server = new AgentServer({
loadFunc: computeLoad,
loadThreshold: 0.8,
});
3) Pattern for using an external queue (conceptual)
• Submit job to your durable queue.
• Worker pool pulls a job from the queue and attempts to dispatch to LiveKit agents.
• If LiveKit rejects/unavailable, return job to queue with a retry/backoff policy.
• Mark job complete only after LiveKit agent accepts and finishes processing.
Next step
• Do you want a concrete example showing how to implement the external queue retry loop in your preferred language, or help tuning a load_fnc for your current metrics (CPU, sessions, etc.)? Sources: Deploying to custom environments | LiveKit Docs | Agent server options | LiveKit docs