Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(stream): stream subscription logic (#1976)
Eric Hayesa470d58eb87b
diff --git a/rust/cloud-storage/connection_gateway/src/service/tracker.rs b/rust/cloud-storage/connection_gateway/src/service/tracker.rsindex ecf57484ec..f7a6451f1d 100644--- a/rust/cloud-storage/connection_gateway/src/service/tracker.rs+++ b/rust/cloud-storage/connection_gateway/src/service/tracker.rs@@ -84,7 +84,10 @@ pub async fn track_entity(ctx.api_context.stream_manager- .unsubscribe(ctx.connection_id.to_owned())+ .unsubscribe(+ ctx.connection_id.to_owned(),+ data.entity.extra.extra.entity_id.to_string(),+ ).await?;}TrackAction::Ping => {diff --git a/rust/cloud-storage/stream/src/domain/traits.rs b/rust/cloud-storage/stream/src/domain/traits.rsindex 96a77ef68e..97b5a6acbb 100644--- a/rust/cloud-storage/stream/src/domain/traits.rs+++ b/rust/cloud-storage/stream/src/domain/traits.rs@@ -43,7 +43,7 @@ pub trait StreamManager: Send + Sync + 'static {/// `sender_id` uniquely identifies the subscriber (e.g. a connection, not a user).async fn subscribe(&self, sender_id: String, entity_id: String) -> Result<ItemStream>;/// Cancel the subscription for the given sender, stopping its stream.- async fn unsubscribe(&self, sender_id: String) -> Result<()>;+ async fn unsubscribe(&self, sender_id: String, entity_id: String) -> Result<()>;/// access to the lower-level repo apifn repo(&self) -> Arc<dyn StreamRepo>;}diff --git a/rust/cloud-storage/stream/src/outbound/redis_pg/manager.rs b/rust/cloud-storage/stream/src/outbound/redis_pg/manager.rsindex 3a53de9226..61b3476893 100644--- a/rust/cloud-storage/stream/src/outbound/redis_pg/manager.rs+++ b/rust/cloud-storage/stream/src/outbound/redis_pg/manager.rs@@ -9,7 +9,13 @@ use tokio::sync::oneshot;/// Manages stream subscriptions backed by Redis and PostgreSQL.pub struct RedisPostgresStreamManager {repo: Arc<dyn StreamRepo>,- subscriptions: DashMap<String, oneshot::Sender<()>>,+ subscriptions: DashMap<SubscriptionKey, oneshot::Sender<()>>,+}++#[derive(Debug, Clone, Eq, PartialEq, Hash)]+struct SubscriptionKey {+ sender_id: String,+ entity_id: String,}impl RedisPostgresStreamManager {@@ -42,7 +48,11 @@ impl StreamManager for RedisPostgresStreamManager {}let (cancel_tx, mut cancel_rx) = oneshot::channel::<()>();- self.subscriptions.insert(sender_id, cancel_tx);+ let key = SubscriptionKey {+ sender_id,+ entity_id: entity_id.clone(),+ };+ self.subscriptions.insert(key, cancel_tx);let out = stream! {loop {@@ -76,8 +86,11 @@ impl StreamManager for RedisPostgresStreamManager {}#[tracing::instrument(err, skip(self))]- async fn unsubscribe(&self, sender_id: String) -> Result<()> {- if let Some((_, cancel_tx)) = self.subscriptions.remove(&sender_id) {+ async fn unsubscribe(&self, sender_id: String, entity_id: String) -> Result<()> {+ if let Some((_, cancel_tx)) = self.subscriptions.remove(&SubscriptionKey {+ sender_id,+ entity_id,+ }) {let _ = cancel_tx.send(());}Ok(())diff --git a/rust/cloud-storage/stream/src/outbound/redis_pg/test/manager.rs b/rust/cloud-storage/stream/src/outbound/redis_pg/test/manager.rsindex 2c684b1972..00874bf83d 100644--- a/rust/cloud-storage/stream/src/outbound/redis_pg/test/manager.rs+++ b/rust/cloud-storage/stream/src/outbound/redis_pg/test/manager.rs@@ -310,7 +310,7 @@ async fn test_unsub_during_stream() {// Unsubscribe via the managermanager- .unsubscribe(sender_id.into())+ .unsubscribe(sender_id.into(), entity_id.into()).await.expect("unsubscribe should succeed");@@ -356,7 +356,7 @@ async fn test_unsub_no_items_after() {// Unsubscribemanager- .unsubscribe(sender_id.into())+ .unsubscribe(sender_id.into(), entity_id.into()).await.expect("unsubscribe should succeed");@@ -402,7 +402,7 @@ async fn test_connection_closed() {.await.expect("subscribe should succeed");manager- .unsubscribe("sender_1".into())+ .unsubscribe("sender_1".into(), entity_id.into()).await.expect("unsubscribe should succeed");