quaint-daybreak-28499
12/01/2025, 6:40 PMtall-airline-16756
12/01/2025, 6:40 PMtall-airline-16756
12/01/2025, 6:40 PMquaint-daybreak-28499
12/01/2025, 6:42 PMtall-airline-16756
12/01/2025, 6:42 PMsession.shutdown(drain=True) or await session.aclose()
◦ Node.js: ctx.shutdown('Session ended')
◦ Listen for the session close event to run cleanup.
• To end the call for all participants (ensures no lingering sessions): delete the room via the server API which triggers session close events for everyone.
◦ Use the Room service client to call deleteRoom(...) (Node/Python examples in the docs).
Which language or SDK are you using so I can provide a short code snippet you can drop into your hangup logic?
Sources: Job lifecycle | LiveKit docs | Events and error handling | LiveKit docsquaint-daybreak-28499
12/01/2025, 6:49 PMtall-airline-16756
12/01/2025, 6:49 PMoutbound-agent.ts and that your catch block shows no message.
Quick checklist to debug and fix (Node.js):
1. Log the raw error object
• Update your catch to log the full error and its properties:
catch (err) {
console.error('Agent entry error - raw:', err);
console.error('Error name:', err?.name, 'message:', err?.message, 'stack:', err?.stack);
await ctx?.shutdown?.('Agent error');
}
1. Handle non-Error throws and undefined
• Normalize thrown values so you always see text:
function formatErr(e: unknown) {
if (e instanceof Error) return e;
return new Error(typeof e === 'string' ? e : JSON.stringify(e));
}
catch (e) {
const err = formatErr(e);
console.error(err);
await ctx?.shutdown?.('Agent error');
}
1. Add global rejection handlers (temporary for debugging)
process.on('unhandledRejection', (reason) => {
console.error('unhandledRejection:', reason);
});
process.on('uncaughtException', (err) => {
console.error('uncaughtException:', err);
});
1. Inspect line 108 in outbound-agent.ts
• Look for any awaited call there (external API, delete_room, createSIPParticipant, hangup_call, etc.). Wrap it in try/catch and log inputs/outputs so you can reproduce the error.
1. Ensure you await shutdown/delete operations
• If closing the call, either:
◦ Gracefully end the agent session: await ctx.shutdown('reason') or await session.aclose() (depending on your code)
◦ Or delete the room to end call for all: call your RoomServiceClient deleteRoom(...) and then await ctx.shutdown(...)
• Always await these calls so the process doesn’t exit before cleanup.
1. If the error happens during cleanup (hangup)
• Wrap hangup logic separately and swallow only expected errors while logging unexpected ones:
try {
await deleteRoom(...);
} catch (e) {
console.error('deleteRoom failed:', e);
}
await ctx.shutdown('hangup');
If you’d like, paste the code around line 100–120 of outbound-agent.ts (the entry function) and I’ll point to the exact lines to change. Which LiveKit Agents SDK version and Node version are you running?
Sources: Job lifecycle | LiveKit docs | Streamline Troubleshooting with Agent Observability