Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calls): leave call (#6286)

Will Hutchinson261326f31854
diff --git a/crates/call/src/outbound/livekit_rtc_client.rs b/crates/call/src/outbound/livekit_rtc_client.rs
index 8c544c7a3b..bccb72f227 100644
--- a/crates/call/src/outbound/livekit_rtc_client.rs
+++ b/crates/call/src/outbound/livekit_rtc_client.rs
@@ -11,6 +11,7 @@ use livekit_api::access_token::{AccessToken, TokenVerifier, VideoGrants};
use livekit_api::services::agent_dispatch::AgentDispatchClient;
use livekit_api::services::egress::{EgressClient, EgressOutput, RoomCompositeOptions, encoding};
use livekit_api::services::room::{CreateRoomOptions, RoomClient};
+use livekit_api::services::{ServiceError, TwirpError, TwirpErrorCode};
use livekit_api::webhooks::WebhookReceiver;
use livekit_protocol::{
AudioCodec, CreateAgentDispatchRequest, EncodedFileOutput, EncodedFileType, S3Upload,
@@ -227,10 +228,11 @@ impl CallRtcClient for LivekitRtcClient {
room_name: &str,
participant_identity: MacroUserIdStr<'_>,
) -> anyhow::Result<()> {
- self.room_client
- .remove_participant(room_name, participant_identity.as_ref())
- .await?;
- Ok(())
+ interpret_remove_participant_result(
+ self.room_client
+ .remove_participant(room_name, participant_identity.as_ref())
+ .await,
+ )
}
#[tracing::instrument(err, skip(self, s3_config))]
@@ -332,3 +334,18 @@ impl CallRtcClient for LivekitRtcClient {
})
}
}
+
+fn interpret_remove_participant_result(result: Result<(), ServiceError>) -> anyhow::Result<()> {
+ match result {
+ Ok(()) => Ok(()),
+ Err(error) if is_participant_already_absent(&error) => Ok(()),
+ Err(error) => Err(error.into()),
+ }
+}
+
+fn is_participant_already_absent(error: &ServiceError) -> bool {
+ matches!(
+ error,
+ ServiceError::Twirp(TwirpError::Twirp(code)) if code.code == TwirpErrorCode::NOT_FOUND
+ )
+}
diff --git a/crates/call/src/outbound/livekit_rtc_client/test.rs b/crates/call/src/outbound/livekit_rtc_client/test.rs
index 7ddc6f4080..d5aa13bb60 100644
--- a/crates/call/src/outbound/livekit_rtc_client/test.rs
+++ b/crates/call/src/outbound/livekit_rtc_client/test.rs
@@ -1,8 +1,16 @@
+use livekit_api::services::{ServiceError, TwirpError, TwirpErrorCode};
use macro_user_id::user_id::MacroUserIdStr;
use super::*;
use crate::domain::ports::CallRtcClient as _;
+fn twirp(code: &str, msg: &str) -> ServiceError {
+ ServiceError::Twirp(TwirpError::Twirp(TwirpErrorCode {
+ code: code.to_string(),
+ msg: msg.to_string(),
+ }))
+}
+
fn client() -> LivekitRtcClient {
LivekitRtcClient::new(
"wss://lk.example",
@@ -48,3 +56,26 @@ async fn verify_access_token_rejects_token_signed_with_a_different_secret() {
fn verify_access_token_rejects_garbage() {
assert!(client().verify_access_token("not-a-jwt").is_err());
}
+
+#[test]
+fn remove_participant_not_found_is_already_gone() {
+ let error = twirp(TwirpErrorCode::NOT_FOUND, "participant does not exist");
+ interpret_remove_participant_result(Err(error))
+ .expect("leave must succeed when LiveKit already dropped the participant");
+}
+
+#[test]
+fn remove_participant_room_not_found_is_already_gone() {
+ let error = twirp(TwirpErrorCode::NOT_FOUND, "requested room does not exist");
+ interpret_remove_participant_result(Err(error))
+ .expect("leave must succeed when the LiveKit room is already gone");
+}
+
+#[test]
+fn remove_participant_unavailable_still_fails() {
+ let error = twirp(TwirpErrorCode::UNAVAILABLE, "overloaded");
+ let message = interpret_remove_participant_result(Err(error))
+ .expect_err("transient LiveKit failures must still surface")
+ .to_string();
+ assert_eq!(message, "twirp error: twirp error: unavailable: overloaded");
+}