From ba0d0b10c48d44bc404960d0b422a5b8c967aa9e Mon Sep 17 00:00:00 2001 From: CSantosM <4a.santos@gmail.com> Date: Wed, 4 Mar 2026 12:33:36 +0100 Subject: [PATCH] backend: Enhances LiveKit agent robustness LiveKit agent service calls now gracefully handle errors instead of throwing exceptions. `listAgents` and `getAgent` return sensible defaults (empty array, undefined) on failure, preventing disruption to calling services. `stopAgent` now logs errors during deletion without halting the process. An early exit condition is also added in the AI assistant service to prevent unnecessary processing if no agents are found, further improving resilience. --- meet-ce/backend/src/services/ai-assistant.service.ts | 7 ++++--- meet-ce/backend/src/services/livekit.service.ts | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/meet-ce/backend/src/services/ai-assistant.service.ts b/meet-ce/backend/src/services/ai-assistant.service.ts index 1a8aafe0..e4be37cf 100644 --- a/meet-ce/backend/src/services/ai-assistant.service.ts +++ b/meet-ce/backend/src/services/ai-assistant.service.ts @@ -238,13 +238,14 @@ export class AiAssistantService { protected async stopCaptionsAssistantIfRunning(roomId: string): Promise { const assistants = await this.livekitService.listAgents(roomId); + + if (assistants.length === 0) return; + const captionsAssistant = assistants.find( (assistant) => assistant.agentName === INTERNAL_CONFIG.CAPTIONS_AGENT_NAME ); - if (!captionsAssistant) { - return; - } + if (!captionsAssistant) return; await this.livekitService.stopAgent(captionsAssistant.id, roomId); } diff --git a/meet-ce/backend/src/services/livekit.service.ts b/meet-ce/backend/src/services/livekit.service.ts index 676d00a4..363ad9a1 100644 --- a/meet-ce/backend/src/services/livekit.service.ts +++ b/meet-ce/backend/src/services/livekit.service.ts @@ -305,7 +305,7 @@ export class LiveKitService { return await this.agentClient.listDispatch(roomName); } catch (error) { this.logger.error(`Error listing agents for room '${roomName}':`, error); - throw internalError(`listing agents for room '${roomName}'`); + return []; } } @@ -320,7 +320,7 @@ export class LiveKitService { return await this.agentClient.getDispatch(agentId, roomName); } catch (error) { this.logger.error(`Error getting agent dispatch '${agentId}' for room '${roomName}':`, error); - throw internalError(`getting agent dispatch '${agentId}' for room '${roomName}'`); + return undefined; } } @@ -334,7 +334,6 @@ export class LiveKitService { await this.agentClient.deleteDispatch(agentId, roomName); } catch (error) { this.logger.error(`Error deleting agent dispatch '${agentId}' for room '${roomName}':`, error); - throw internalError(`deleting agent dispatch '${agentId}' for room '${roomName}'`); } }