# LiveKit Support Ticket: Duplicate Agent Joins De...
# agents
s
# LiveKit Support Ticket: Duplicate Agent Joins Despite Configuration ## Issue Summary When dispatching a single agent to a room, ***two separate agent instances join*** with different Job IDs and Process IDs. This occurs despite multiple attempts to configure the worker to prevent multiprocessing. ## Expected Behavior - ONE agent dispatch → ONE agent joins the room -
request_fnc
custom handler should be called to control job acceptance ## Actual Behavior - ONE agent dispatch → TWO agents join the room - Two different Job IDs are assigned (e.g., AJ_FFenBnHQEnS4 and AJ_eBkx2FQFPUaP) - Two different Process IDs execute (e.g., PID 20031 and PID 20036) -
request_fnc
is ***NEVER called*** (no log messages from custom handler) - 11+ multiprocessing child processes spawn despite configuration ## Environment Details ***Platform:*** - OS: macOS 12.7.6 (Monterey) - Architecture: x86_64 - Python: 3.12.8 ***LiveKit Packages:*** - livekit-agents: 1.2.16 - livekit-api: 1.0.7 ***LiveKit Server:*** - URL: wss://aiagentmoderator-bzu1wgs1.livekit.cloud - Region: US West B ## Current Configuration ### Environment Variables (set before import)
Copy code
python
import os
os.environ[“LIVEKIT_AGENTS_NUM_IDLE_PROCESSES”] = “0"
### WorkerOptions
Copy code
python
from livekit.agents import JobExecutorType

worker_options = agents.WorkerOptions(
    entrypoint_fnc=entrypoint,
    request_fnc=request_handler,  # Custom handler - NEVER CALLED
    job_executor_type=JobExecutorType.THREAD,
    num_idle_processes=0,
    max_retry=0,
    agent_name=“”,  # Accept all rooms
)

agents.cli.run_app(worker_options)
### Custom Request Handler (Not Being Called)
Copy code
python
async def request_handler(job_request: agents.JobRequest):
    “”"This function is NEVER executed - no logs appear”“”
    <http://logger.info|logger.info>(f”:white_check_mark: ACCEPTING job {job_request.job.id}“)  # NEVER PRINTED
    await job_request.accept()
## Reproduction Steps 1. Start agent with configuration above:
Copy code
bash
   python3 agent.py dev
2. Dispatch ONE agent to a room:
Copy code
python
   agent_dispatch = await livekit_api.agent_dispatch.create_dispatch(
       api.CreateAgentDispatchRequest(room=room_name, agent_name=“”)
   )
3. Observe two agents join the room ## Log Evidence ***Terminal Output (truncated):***
Copy code
2025-12-10 14:19:49,074 - __mp_main__ - INFO - Agent starting
2025-12-10 14:19:49,074 - INFO __mp_main__ - ... {“pid”: 20031, “job_id”: “AJ_FFenBnHQEnS4"}

2025-12-10 14:19:49,074 - __mp_main__ - INFO - Agent starting
2025-12-10 14:19:49,074 - INFO __mp_main__ - ... {“pid”: 20036, “job_id”: “AJ_eBkx2FQFPUaP”}
***Key Observations:*** - Two different PIDs: 20031 and 20036 - Two different Job IDs: AJ_FFenBnHQEnS4 and AJ_eBkx2FQFPUaP - NO log messages from
request_handler
(should print “✅ ACCEPTING job”) ***Process Count:***
Copy code
bash
$ ps aux | grep -E “[a]gent.py|multiprocessing” | wc -l
11
Despite
num_idle_processes=0
and environment variable, 11 processes are spawned. ## What We’ve Tried ### Attempt 1: Thread Executor
Copy code
python
job_executor_type=JobExecutorType.THREAD
***Result:*** Still spawns multiple processes ### Attempt 2: File-based Locking
Copy code
python
async def request_handler(job_request: agents.JobRequest):
    lock_file = open(_lock_file_path, ‘w’)
    fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
    await job_request.accept()
***Result:*** Function never called ### Attempt 3: Environment Variables
Copy code
python
os.environ[“LIVEKIT_AGENTS_NUM_IDLE_PROCESSES”] = “0”
***Result:*** Still spawns 11 processes ### Attempt 4: Multiprocessing Start Method
Copy code
python
multiprocessing.set_start_method(‘forkserver’, force=True)
***Result:*** No effect on duplication ## Questions for Support 1. ***Why is
request_fnc
never called?* - We provide a custom
request_handler
but it never executes - Is there a different hook we should use to control job acceptance? 2. ***Why does
num_idle_processes=0
not prevent process spawning?* - 11 processes still spawn despite this setting - Is this setting ignored in certain configurations? 3. ***How can we ensure only ONE agent accepts a dispatched job?* - What is the correct configuration to prevent duplicate agents? - Is there a different API pattern we should use? 4. ***Does
agents.cli.run_app()
override WorkerOptions?* - Could the CLI be spawning its own worker pool? - Should we implement a custom worker instead of using the CLI? ## Additional Context We’ve spent significant time debugging this across multiple approaches (process management, locking mechanisms, configuration changes). The core issue appears to be that LiveKit’s worker/process management is bypassing our configuration and spawning multiple workers that all accept jobs independently. Any guidance on the correct configuration or architecture pattern would be greatly appreciated.
l
Your project ID is
p_fowfce0gzp1
, correct? I do not see any agents shown in your agents view (not sure why), but my guess is that you have one agent dispatched automatically because it has no name, and the second one you are explicitly dispatching: https://docs.livekit.io/agents/server/agent-dispatch/? Looking more closely, I also see a lot of 'worker not available' errors around the time of dispatch, I can see these are self-hosted agents but do you have sufficient memory etc. on the machine where they are being hosted.