what are some possible reasons why in the livekit ...
# ask-ai
l
what are some possible reasons why in the livekit worker, the job request is accepted, but the entrypoint function does not run
t
Thanks for reaching out, Daniel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — regarding why a job is accepted by the LiveKit worker but the entrypoint never appears to run, here are the most common causes and quick checks you can do. What I’m addressing: reasons the worker accepts the job but the entrypoint function doesn’t execute. Possible causes and what to check • Entrypoint not registered correctly ◦ Python: ensure the function is decorated with
@server.rtc_session()
and the server registers it. ◦ Node: ensure the entry function is exported as the
entry
property in
defineAgent()
. • AgentServer request handler not wiring the entrypoint ◦ Confirm your
requestFunc
/
on_request
correctly passes or references the entrypoint when accepting the job. • Process initialization failure ◦ Check worker process startup logs for dependency errors, import failures, wrong file paths, or failures in
setup_fnc
/
prewarm
. • Entrypoint throws immediately ◦ Look for immediate exceptions (import errors, misconfigured resources). Check stderr/worker logs for tracebacks. • Blocking or hanging calls at start ◦ The entrypoint may reach a blocking
await
(e.g.,
ctx.connect()
) and hang due to network/permission/room access issues — enable timeouts or log before/after key awaits to verify progress. • CLI/startup not using framework runner ◦ Ensure the agent is started with
cli.run_app()
(Python) or
cli.runApp()
(Node) so the framework dispatches jobs correctly. Debugging steps (quick) 1. Set worker logging to DEBUG and watch lifecycle logs for process start, job accept, and dispatch messages. 2. Add early logs in your entrypoint (first line) and in
requestFunc
to confirm whether the function is invoked. 3. Check worker stderr/stdout for exceptions during process init or immediately after job accept. 4. Temporarily simplify the entrypoint to a no-op that logs and exits to confirm dispatch works. 5. Validate
prewarm
/
setup_fnc
completes and does not throw or block. If you want, tell me: • which language (Python or Node) and • a minimal snippet of your
requestFunc
/ entrypoint registration and startup command —I can point to the exact lines to inspect or suggest a minimal repro to run. Sources: Agent server options | LiveKit docs | Job lifecycle | LiveKit docs
l
if we have overriden the request function to always accept the job, if the workers are above capacity will the entrypoint not run?
t
You're asking whether an overridden request handler that always calls accept() guarantees the entrypoint will run when workers are over capacity. Short answer: No — accepting a request does not guarantee the entrypoint will run if the agent server is over capacity. Why: • Accepting a job signals intent to handle it, but the entrypoint runs in a new process spawned by the agent server. If the agent cannot spawn that process (resource limits, max concurrent jobs, or load above
load_threshold
), the job will not start. • Forcing acceptance while overloaded risks process startup failures, resource exhaustion, or degraded/unresponsive agents. • In LiveKit Cloud, `load_fnc`/`load_threshold` behavior is enforced and cannot be changed, so you can’t bypass capacity checks there. What to do: • Monitor agent logs and DEBUG-level lifecycle messages to see whether process spawn fails. • Track agent load and concurrent process counts; add safeguards in
requestFunc
(e.g., check current load) instead of unconditionally accepting. • As a quick test, make
requestFunc
accept and use a minimal entrypoint that logs immediately and exits to confirm dispatch behavior under different load levels. If you share which language (Python or Node) and your
requestFunc
snippet, I can point to exactly where to add a safe capacity check and diagnostic logs. Sources: Agent server options | LiveKit docs | Deploying to custom environments | LiveKit docs
l
how can i check the current load in the request function
t
You're asking how to check current agent load inside your request handler so you can accept/reject jobs based on capacity. Python (server has
load_fnc
and accessible properties) 1. Define a
load_fnc
that computes load (0..1) and/or expose whatever metric you need (active jobs, CPU, memory). 2. In
request_fnc
, call that same function or read the server state to decide. Example:
Copy code
from livekit.agents import AgentServer

def compute_load(server) -> float:
    # example: scale active jobs to 0..1
    return min(len(server.active_jobs) / 10, 1.0)

async def request_fnc(req):
    current_load = compute_load(server)
    if current_load < 0.7:
        await req.accept()
    else:
        await req.reject()

server = AgentServer(load_fnc=lambda: compute_load(server), load_threshold=0.7)
Node.js (similar pattern) 1. Provide a
loadFunc
to the AgentServer and call it from your request handler. Example:
Copy code
const computeLoad = (server: AgentServer): number => {
  return Math.min(server.activeJobs.length / 10, 1.0);
};

const requestFunc = async (req: JobRequest) => {
  const currentLoad = computeLoad(server);
  if (currentLoad < 0.7) {
    await req.accept();
  } else {
    await req.reject();
  }
};

const server = new AgentServer({
  loadFunc: () => computeLoad(server),
  loadThreshold: 0.7,
  requestFunc,
});
Notes and quick tips • The framework’s default
load_fnc
uses CPU, but you can use active job count, memory, or any metric. • Keep
load_fnc
cheap and deterministic; call it in the request handler rather than running expensive checks. • Use conservative thresholds and add early logging in
request_fnc
to observe decisions at runtime. If you share your language and your current
request_fnc
snippet, I’ll point to where to read the server state or add a lightweight load check. Sources: Agent server options | LiveKit docs
l
if the worker is unavailable, does the request function still run
t
You're asking whether the request function runs when a worker is unavailable. No — the request function is only invoked on agent servers that are considered available. Availability is determined by the agent's current load (via
load_fnc
) and
load_threshold
. If the agent's load exceeds the threshold (or the agent is otherwise unavailable), the LiveKit server will skip that agent and send the job request to another available agent, so your
on_request
/
requestFunc
will not be called on the unavailable worker. Sources: Agent server options | LiveKit docs
l
what happens to the job request if no workers are available
t
If no workers are available when a job is dispatched, the job will not be processed and no agent will be assigned. Behavior depends on how dispatch is performed: • Automatic dispatch: the LiveKit server will try other available agents and respect timeouts; if no agents are available, the request remains unhandled until an agent becomes available or it times out per dispatch policy. • Explicit dispatch (e.g., API/token): if no workers are registered/available at dispatch time, no agent will join the room and the system does not automatically retry later. Practical guidance: • Run multiple workers (per agent_name) to ensure failover and availability. • Monitor agent load and health so dispatch finds available agents. • Implement client-side or orchestration retries if you need guaranteed later processing. Sources: Agent server options | LiveKit docs | Deploying to custom environments | LiveKit docs | Agent dispatch | LiveKit docs | Agents Framework | livekit/livekit_composite | DeepWiki