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.

feat(calls): add in safety methods to stop calls properly to avoid billing mistakes (#2577)

Will Hutchinsond6b2cf5d7e0e
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index 32aca17bec..498bc67986 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -512,11 +512,26 @@ impl<
if remaining == 0 {
tracing::info!(call_id = %call.id, room_name, "last participant left, archiving call");
let channel_id = call.channel_id;
+ let egress_id = call.egress_id.clone();
self.repo
.archive_call(&call.id)
.await
.map_err(|e| CallError::Internal(e.into()))?;
+ // Stop egress explicitly before deleting the room. DeleteRoom
+ // is expected to cascade-stop egress, but a failed or slow
+ // DeleteRoom can leave egress running and billing. Doing it
+ // first makes the runaway-billing case impossible.
+ if let Some(egress_id) = egress_id {
+ self.rtc_client
+ .stop_egress(&egress_id)
+ .await
+ .inspect_err(
+ |e| tracing::error!(error=?e, egress_id, "failed to stop egress"),
+ )
+ .ok();
+ }
+
self.rtc_client
.delete_room(room_name)
.await
diff --git a/rust/cloud-storage/call/src/outbound/livekit_rtc_client.rs b/rust/cloud-storage/call/src/outbound/livekit_rtc_client.rs
index 6f4c29dcd7..a1b6c0b477 100644
--- a/rust/cloud-storage/call/src/outbound/livekit_rtc_client.rs
+++ b/rust/cloud-storage/call/src/outbound/livekit_rtc_client.rs
@@ -73,7 +73,13 @@ impl CallRtcClient for LivekitRtcClient {
#[tracing::instrument(err, skip(self))]
async fn create_room(&self, room_name: &str) -> anyhow::Result<()> {
self.room_client
- .create_room(room_name, CreateRoomOptions::default())
+ .create_room(
+ room_name,
+ CreateRoomOptions {
+ empty_timeout: 60,
+ ..Default::default()
+ },
+ )
.await?;
Ok(())
}