5-08-12 06:15:59,107 - ERROR livekit.agents - job ...
# ask-ai
m
2025-08-12 061559,107 - ERROR livekit.agents - job shutdown is taking too much time.. {"tid": 11824, "job_id": "AJ_FqY4e75Mb9nF"} 2025-08-12 061632,041 - DEBUG livekit.plugins.openai - reconnecting to OpenAI Realtime API {"max_session_duration": 1200} 2025-08-12 061632,091 - DEBUG livekit.plugins.openai - reconnected to OpenAI Realtime API 2025-08-12 063401,231 - DEBUG livekit.plugins.openai - reconnecting to OpenAI Realtime API {"max_session_duration": 1200} 2025-08-12 063401,259 - DEBUG livekit.plugins.openai - reconnected to OpenAI Realtime API 2025-08-12 063632,312 - DEBUG livekit.plugins.openai - reconnecting to OpenAI Realtime API {"max_session_duration": 1200} 2025-08-12 063632,340 - DEBUG livekit.plugins.openai - reconnected to OpenAI Realtime API
t
Thanks for reaching out, Usama. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! That error message "job shutdown is taking too much time" pops up when a job's shutdown process takes longer than the allowed timeout. This usually happens if the shutdown hooks or cleanup tasks are taking more time than expected. Here’s how you can fix it: 1. Increase the shutdown timeout: Try adjusting the
shutdown_process_timeout
in your worker configuration to give the shutdown process a bit more breathing room. For example: ◦ In Python:
WorkerOptions(shutdown_process_timeout=120.0)
◦ In JavaScript:
new Worker({ shutdownProcessTimeout: 120000 })
1. Optimize shutdown hooks: Double-check that any custom shutdown callbacks finish quickly and avoid heavy operations during shutdown. 2. Analyze shutdown behavior: Take a look at the logs leading up to shutdown to spot any slow spots and make sure all processes and connections are closing properly. If you want to dive deeper, check out the WorkerOptions documentation and the Job Shutdown Hooks documentation. Hope this helps!
m
async def write_transcript(): file_name = f"transcript.json" with open(file_name, "w") as f: json.dump(session.history.to_dict(), f, indent = 2) print(f"Transcript for {ctx.room.name} saved to {file_name}") # Save transcript to database against user phone number session_history = session.history.to_dict() # print(session_history) summary_prompt = """ Your task is to read the following call transcript and produce a short, scannable summary """ response = await openai_client.chat.completions.create( model="gpt-4.1-mini", messages=[ {"role": "system", "content": f"You are a summarizer agent. {summary_prompt}"}, {"role": "user", "content": f"Here is the call transcript: {json.dumps(session.history.to_dict())}"}, {"role": "user", "content": "Please summarize the call in few sentences."} ] ) summary = response.choices[0].message.content.strip() reply = await classify_intent(session_history) with open("intent.txt", 'w') as f: f.write(str(reply)) import ast reply = ast.literal_eval(reply) await save_transcript(session_history, metadata['phoneNumber'], tenant_id, participant.attributes["sip.twilio.callSid"], summary, list(reply.keys())[0], direction="outbound") body = { "leadId": metadata['leadId'], "response": list(reply.keys())[0], "data": { "transcriptId": participant.attributes["sip.twilio.callSid"], "days": float(list(reply.values())[0]) } } print("Temporal Payload: ", body) resp = requests.post("http://workflow/response", json=body, timeout=5) print("Response: ", resp) print("For participant: ", metadata['phoneNumber']) this is my shutdown callback why is taking so long?
t
Hey there! It looks like your shutdown callback is taking a bit longer because it’s handling tasks like saving transcripts, summarizing, and making HTTP requests. These can sometimes go over LiveKit’s default 60-second timeout. Let’s walk through some common reasons and how we can fix them: 1. Network Latency: Sometimes HTTP requests to outside services can slow down due to network hiccups or slower server responses. 2. Database Operations: Saving big transcripts or working with databases might take more time than expected. 3. Complex Computation: Summarizing with natural language processing can be pretty heavy on your system. 4. Timeout Constraints: The default 60-second timeout might just not be enough for all your tasks. Here are some friendly tips to help out: 1. Try using asynchronous operations for your HTTP requests and database work so the shutdown process doesn’t get held up. 2. See if you can optimize those heavier tasks to finish quicker within the timeout period. 3. If needed, you can bump up the
shutdown_process_timeout
in your worker settings. For example: ◦ In Python:
WorkerOptions(shutdown_process_timeout=120.0)
◦ In JavaScript:
new Worker({ shutdownProcessTimeout: 120000 })
If you want, I’m here to help you with any of these steps—just let me know! Sources: livekit-agents/livekit/agents/voice/agent_session.py | Tool definition and use | LiveKit Docs
m
how to manually shut it down
t
If you want to manually shut down a job or process in LiveKit, here are a couple of easy ways to do it: 1. Using JobContext's
shutdown()
method:
Inside your job's entrypoint function, just call
ctx.shutdown()
to gracefully stop the job. This makes sure all shutdown hooks run and the process exits nicely.
Copy code
async def entrypoint(ctx):
    # Take care of any cleanup
    await ctx.shutdown("User initiated shutdown")
2. Using Worker's
close()
method:
The Worker class has a handy
close()
method that stops all active jobs. It’s perfect if you need to shut down processes from outside.
Copy code
const worker = new Worker(workerOptions);
// When you want to shut down all jobs
await worker.close();
Feel free to reach out if you want a hand with setting these up or have any other questions! Sources: Inside a session | LiveKit Docs | Worker | LiveKit Agents | agents/src/worker.ts
m
shutdown is taking to long so i want it to shutdown in shutdown callback
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!