Skip to content

[Bug] Async prewarm function not awaited in job_proc_lazy_main.ts #908

@golergka

Description

@golergka

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:

  1. Async prewarm functions start but don't complete
  2. The process immediately sends initializeResponse
  3. Jobs can be assigned before prewarm finishes
  4. 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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions