Bug Description
The prewarm function in job_proc_lazy_main.ts is not awaited, causing async prewarm functions to not complete before job entry runs.
Current Behavior
In agents/src/ipc/job_proc_lazy_main.ts around line 131:
logger.debug("initializing job runner");
agent.prewarm(proc); // NOT AWAITED!
logger.debug("job runner initialized");
process.send({ case: "initializeResponse" });
The prewarm function is called synchronously without await. This means:
- Async prewarm functions start but don't complete
- The process immediately sends
initializeResponse
- Jobs can be assigned before prewarm finishes
- Entry runs with incomplete
proc.userData
Expected Behavior
The prewarm function should be awaited:
logger.debug("initializing job runner");
await agent.prewarm(proc); // Should await!
logger.debug("job runner initialized");
process.send({ case: "initializeResponse" });
Evidence
Our logs show prewarm starting at 17:00:40.490 and completing at 17:00:41.181, but entry ran at 17:00:40.771 - before prewarm finished.
| Time |
Event |
| 17:00:40.490 |
"prewarming runtime resources" - Prewarm STARTED |
| 17:00:40.771 |
Entry function called (before prewarm done!) |
| 17:00:40.963 |
Error: userData missing expected values |
| 17:00:41.181 |
"prewarm completed" - 691ms too late |
Documentation vs Implementation
The LiveKit docs show async prewarm examples for Node.js:
prewarm: async (proc: JobProcess) => {
proc.userData.vad = await silero.VAD.load();
}
And state "The framework handles the awaiting" - but the current implementation doesn't await.
Environment
- @livekit/agents version: 1.0.19
- Also verified on current main branch - bug still exists
Workaround
We're using a pnpm patch to add the await:
- agent.prewarm(proc);
+ await agent.prewarm(proc);
Bug Description
The
prewarmfunction injob_proc_lazy_main.tsis not awaited, causing async prewarm functions to not complete before job entry runs.Current Behavior
In
agents/src/ipc/job_proc_lazy_main.tsaround line 131:The prewarm function is called synchronously without
await. This means:initializeResponseproc.userDataExpected Behavior
The prewarm function should be awaited:
Evidence
Our logs show prewarm starting at 17:00:40.490 and completing at 17:00:41.181, but entry ran at 17:00:40.771 - before prewarm finished.
Documentation vs Implementation
The LiveKit docs show async prewarm examples for Node.js:
And state "The framework handles the awaiting" - but the current implementation doesn't await.
Environment
Workaround
We're using a pnpm patch to add the
await: