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(call): delete recording from s3 (#2627)

Will Hutchinson22286f867161
diff --git a/rust/cloud-storage/call/.sqlx/query-b977844d337884ba073f0e79bdb5c07193441de40e9097a4d52140a48ddab8c4.json b/rust/cloud-storage/call/.sqlx/query-b977844d337884ba073f0e79bdb5c07193441de40e9097a4d52140a48ddab8c4.json
new file mode 100644
index 0000000000..e1bff89819
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-b977844d337884ba073f0e79bdb5c07193441de40e9097a4d52140a48ddab8c4.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM call_records WHERE id = $1 RETURNING recording_key\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "recording_key",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "b977844d337884ba073f0e79bdb5c07193441de40e9097a4d52140a48ddab8c4"
+}
diff --git a/rust/cloud-storage/call/src/domain/ports.rs b/rust/cloud-storage/call/src/domain/ports.rs
index aab8b12ef5..e122e25236 100644
--- a/rust/cloud-storage/call/src/domain/ports.rs
+++ b/rust/cloud-storage/call/src/domain/ports.rs
@@ -166,10 +166,12 @@ pub trait CallRepository: Send + Sync + 'static {
/// Delete a row from `call_records` by id. Participants and transcript
/// segments are removed via `ON DELETE CASCADE`. No-op if no row matches.
+ /// Returns the deleted row's `recording_key` (if any) so the caller can
+ /// clean up the associated recording object in storage.
fn delete_call_record(
&self,
call_record_id: &Uuid,
- ) -> impl Future<Output = Result<(), Self::Err>> + Send;
+ ) -> impl Future<Output = Result<Option<String>, Self::Err>> + Send;
}
/// Storage port for generating presigned recording URLs.
@@ -183,6 +185,16 @@ pub trait RecordingStorage: Send + Sync + 'static {
&self,
recording_key: &str,
) -> impl Future<Output = anyhow::Result<String>> + Send;
+
+ /// Delete the recording object identified by `recording_key`.
+ ///
+ /// Implementations must apply the same prefix as
+ /// [`presign_recording_url`](Self::presign_recording_url). Should be
+ /// idempotent — succeed if the key no longer exists.
+ fn delete_recording(
+ &self,
+ recording_key: &str,
+ ) -> impl Future<Output = anyhow::Result<()>> + Send;
}
impl<T: RecordingStorage> RecordingStorage for Option<T> {
@@ -192,6 +204,13 @@ impl<T: RecordingStorage> RecordingStorage for Option<T> {
None => anyhow::bail!("recording storage not configured"),
}
}
+
+ async fn delete_recording(&self, recording_key: &str) -> anyhow::Result<()> {
+ match self {
+ Some(inner) => inner.delete_recording(recording_key).await,
+ None => anyhow::bail!("recording storage not configured"),
+ }
+ }
}
/// RTC client port for interacting with the real-time communication service (e.g., LiveKit).
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index 61f1e48084..6378aff543 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -661,11 +661,22 @@ impl<
let call_id = Uuid::parse_str(&entity.entity_id)
.map_err(|_| CallError::Internal(anyhow::anyhow!("invalid call_id in receipt")))?;
- self.repo
+ let recording_key = self
+ .repo
.delete_call_record(&call_id)
.await
.map_err(|e| CallError::Internal(e.into()))?;
+ if let Some(key) = recording_key {
+ self.recording_storage
+ .delete_recording(&key)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(error=?e, recording_key=%key, "failed to delete call recording from storage");
+ })
+ .ok();
+ }
+
Ok(())
}
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
index 5f390bdde4..d337cf3256 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
@@ -1008,15 +1008,15 @@ impl CallRepository for PgCallRepo {
}
#[tracing::instrument(err, skip(self))]
- async fn delete_call_record(&self, call_record_id: &Uuid) -> Result<(), Self::Err> {
- sqlx::query!(
+ async fn delete_call_record(&self, call_record_id: &Uuid) -> Result<Option<String>, Self::Err> {
+ let row = sqlx::query!(
r#"
- DELETE FROM call_records WHERE id = $1
+ DELETE FROM call_records WHERE id = $1 RETURNING recording_key
"#,
call_record_id,
)
- .execute(&self.pool)
+ .fetch_optional(&self.pool)
.await?;
- Ok(())
+ Ok(row.and_then(|r| r.recording_key))
}
}
diff --git a/rust/cloud-storage/call/src/outbound/s3_recording_storage.rs b/rust/cloud-storage/call/src/outbound/s3_recording_storage.rs
index 1e4f989963..7b3945db3b 100644
--- a/rust/cloud-storage/call/src/outbound/s3_recording_storage.rs
+++ b/rust/cloud-storage/call/src/outbound/s3_recording_storage.rs
@@ -35,4 +35,15 @@ impl RecordingStorage for S3RecordingStorage {
Ok(macro_aws_config::transform_aws_url(presigned.uri()))
}
+
+ async fn delete_recording(&self, recording_key: &str) -> anyhow::Result<()> {
+ let full_key = format!("calls/{recording_key}");
+ self.client
+ .delete_object()
+ .bucket(&self.bucket)
+ .key(&full_key)
+ .send()
+ .await?;
+ Ok(())
+ }
}