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
feat(notif): check typename ignore before publishing digest (#2411)
Sean Aye4b30d75c5b5a
diff --git a/.env-local.enc b/.env-local.encindex 667103bc03..320bcf564e 100644--- a/.env-local.enc+++ b/.env-local.enc@@ -128,7 +128,7 @@ LIVEKIT_API_KEY=ENC[AES256_GCM,data:qhLZaV4ww9UxE03tj91qx2Y=,iv:QJVCtekxlAe0fZLHLIVEKIT_API_SECRET=ENC[AES256_GCM,data:GLdp8wpK4kpbGPmR5aaWzZ4ns8jzTkRuFfroG8PUeG8ChFJONtoCFx1VjlxUfQ==,iv:YcaFnOZG8lA9kMxM8C4WD+DXqHRhprburLqIzDWI7Zc=,tag:Ro55kVfVytCWdfCT/GERCA==,type:str]LIVEKIT_TRANSCRIPTION_AGENT_NAME=ENC[AES256_GCM,data:RgXJ+WNruFiyg1Pjjzo++SDOLg==,iv:r7XZRhIJg+4qiEBBG6Pbvj+maiUh/jrO5lnwNkUXgxM=,tag:yVVoGBzz1Bl0lY1KqH4G3Q==,type:str]INTERNAL_CALL_SECRET=ENC[AES256_GCM,data:66UR3BO7Ddg5bQ0xmLNeY5EGb65L4tiXcsDNpTE=,iv:ovuMlw/k257Oh1CkosXjOXDWycQ4AoA9s+hhfHpeOvs=,tag:qXXYEFhSaM0Q4ffRdGtMRg==,type:str]-UNSUBSCRIBE_HMAC_SECRET=ENC[AES256_GCM,data:N5twF18QdQpAcMb7RxFR6l2DQ6t8c3bjl2FxMoJT3AkHkLZNSmCibhsfoMx12w==,iv:nbo2PYRG9AxWC2JwTEIk84M7KhO27tyMtH1BaqIPDT8=,tag:BCDWa/lataRL33lAw2HPCQ==,type:str]+URL_SIGNING_HMAC=ENC[AES256_GCM,data:2PtDBCM6BARI7Fl5MSCVbOzGsXvgR8eFghJPfTvUFP31YRnFHpF5CBIsSlOhGUJihSoq6Ydfr9L4+LKv1EXT9g8S,iv:7ZmNUdsYr3ujUZiPVStz5ymrtYBfhsmDeyISzGX+1h0=,tag:snvxFxHfT7NyXpKF4Onu6A==,type:str]sops_age__list_0__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHBpdi1wMjU2IEUzMVUyZyBBM1lmcDc3\nUENpRVorSGVGa3R2NFlrdkx1Mm43aEcyR1ZtbEswL2RnWHlqMwpVMnY4ck5makNC\nZzVZc3JrZ3NKV2x3RTY0TFovRXJtVzEyeFZOZWRheHBNCi0tLSBobjhCbHpJa25s\nZDhyQjhCaEYrOWNiWHZkRWpnRlkwTnNEbjMwYzdxcTUwCqxxxmXy3mFUAbAy29y8\n2DFYDATdVvmplHpDTvgrNyY+lAL/3Jp9vtIs5DGXW/r73Nv3AhISmuCid18qhpAY\nUqE=\n-----END AGE ENCRYPTED FILE-----\nsops_age__list_0__map_recipient=age1yubikey1qw64ag5lzvn9ekrflu5ruj4a6ucycscl6ctk39fjzf76jptsay39z442pxvsops_kms__list_0__map_arn=arn:aws:kms:us-east-1:569036502058:key/mrk-cab29bf948044eb79005a81f48d40e93@@ -139,7 +139,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480sops_kms__list_1__map_aws_profile=sops_kms__list_1__map_created_at=2026-03-03T19:32:07Zsops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wFUqf7u/HEfCUGv7j69Mb6YAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMpcJQR1XeIAFFE7ebAgEQgDvYRYIWelwN8TuwA+6fZVaB34yKo9EQ5xPLr/3BU+ro1Mn2eBPCg3q8ie2LuE/3voim1X35P/cdtDqTZg==-sops_lastmodified=2026-04-06T21:16:16Z-sops_mac=ENC[AES256_GCM,data:I6LHAjz+DXfvYxsRl8IsqFDPf/Uap3WC+zvV1Wp47SqsUx3QDwKMJELT9NEE8Jmf3mZTQucZSBgXvFiLRSrGY5Ult/300WWaUjsyHyf1hdT9vvzIis0r7iSFEl2xCg0eVUcIWJ1DLKGLDKg+S/YziggOx0rsniXewAdYdIqofeQ=,iv:cM+kjTmNku5r9ia6gy52D+SfauJgNINeM1+ocfLhLY0=,tag:ENXb7WC1x7Nwqld+6nN+jQ==,type:str]+sops_lastmodified=2026-04-07T15:42:26Z+sops_mac=ENC[AES256_GCM,data:xtZ2KnO66PdYX0CH6ZaQ7rGrgTQHL3wrzClBUtAfgbjQlGVn28XvH6eBuNreIgvaDL02NRYb1fPE7tvBNLdea4pLbL7hyR1188ErxouuifKY+oWArXxZU03IQ/zyXTaRKupTKjT/JvR2lrkz6ksy6KxDqoOKq+UEmDsifG/3Cvw=,iv:FBHOX35jhuUtEDH2WCOQZHRJSvWtt6gUfUA4BaEK9Mg=,tag:ssDHMj08cQI1zvYgJ9S+9A==,type:str]sops_unencrypted_suffix=_unencryptedsops_version=3.12.2diff --git a/.env-localdev.enc b/.env-localdev.encindex bf5185b105..fed9265ba1 100644--- a/.env-localdev.enc+++ b/.env-localdev.enc@@ -134,7 +134,7 @@ LIVEKIT_API_KEY=ENC[AES256_GCM,data:aKkhucWrN/FNaYmbloWdxm0=,iv:RmykULpzwZ9lftkFLIVEKIT_API_SECRET=ENC[AES256_GCM,data:VrLzVGpQG7ML+TZcopCsEkyj/mXiTm+9BsqWE3nGdIozRf6PIyUwHlyErGoFCQ==,iv:na9JIyCdt94SFnPLh9l+33c8lZRW+uR8WYw+Ju8zdYw=,tag:cLL0wJz4jzpAIRysbt4tSQ==,type:str]LIVEKIT_TRANSCRIPTION_AGENT_NAME=ENC[AES256_GCM,data:kPe4llQDxy8gkYjNH6bIe3W6Sg==,iv:8j7ryXT1MTiSoGz14jifVSH/FYlHRRY1DwCqdIqwenw=,tag:3GCNvV7rL2uIKj2sPw0LxQ==,type:str]INTERNAL_CALL_SECRET=ENC[AES256_GCM,data:ZRHFdPR0Rrq01RiNYDECflGVdG+xdHr0qrpR9xY=,iv:DNGhICcPs2zKFpxqSAdgezeT9F8L/r/JO0hT3tJN2Rg=,tag:Rg3YlrSIhtpwI70ifErOTw==,type:str]-UNSUBSCRIBE_HMAC_SECRET=ENC[AES256_GCM,data:qY1UwSmYGhkB0fi7k7FUia9Cfbyi4THRAvyB9VnmuZel4gqRACXcRI08OBfEbg==,iv:WdBWZC+yzLlJGqmMxeQzZBZA8zsLNuH3y0OfbOxGp4o=,tag:muNfHVbAQwMcqonfZk7Clg==,type:str]+URL_SIGNING_HMAC=ENC[AES256_GCM,data:3+bLcbaRe0WnF941D7K39JxKwJ9422cryG8eLjpUormPm3b2jv+RZY17J+Boud3jxnHg+jwgtFBuLL4GQSedz/e9,iv:UP8KKht51fOVwP9Cvsf4GSdZg9RXQ7DTrRt6vL0LOcA=,tag:VdHNzkLRPU6owznQOjX+jg==,type:str]sops_age__list_0__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHBpdi1wMjU2IEUzMVUyZyBBNDlKWUVt\nbUpscDEzSE9IZTNvdkd6VUFpWWhQM1ZWcndzL0srVXE4SW5GUQpHR2xNR3lIUnBV\nY3BqbmRadVVPMUdkeUluR0RycDJsWWt1V2Z0T1hqbG1JCi0tLSA5cVZQSGtNNmgr\nVXdyWGZsLzg2N0lyakxuVDZuNEFDUlUrNXJIMHE3UmRRClCd0JD9Q51ZLVKv73Px\nebG4SM/4o73tU3IHJu4tyQUrFM+we+JEDvsYKHBuUgTGC+2yQRPmHV+HObTqqRnu\nzGg=\n-----END AGE ENCRYPTED FILE-----\nsops_age__list_0__map_recipient=age1yubikey1qw64ag5lzvn9ekrflu5ruj4a6ucycscl6ctk39fjzf76jptsay39z442pxvsops_kms__list_0__map_arn=arn:aws:kms:us-east-1:569036502058:key/mrk-cab29bf948044eb79005a81f48d40e93@@ -145,7 +145,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480sops_kms__list_1__map_aws_profile=sops_kms__list_1__map_created_at=2026-03-03T19:32:17Zsops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wHtcTS4UVhM79Eansn1/OmrAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMRrFwSp99ZM2mPtJzAgEQgDvsIaiNifNz0/18C9OH77AG/LQLpmDiXiJYV46yLDv9vdyPL3PaLMvkAqgL3Xb2F4RcZOIUxkTS3u92xQ==-sops_lastmodified=2026-04-06T21:15:53Z-sops_mac=ENC[AES256_GCM,data:00qJ9YQlQvu/nDwMJFup2PUf4CceElV9cepklC7Mn7L1Z93KTIpsq1Hg9erI7cePxHD+Fbd8mhlZNZpL5IYb5wVRNlPQ6qlCgdCdkAsvJyEiR4xiio4HVNXm7JDYVjpoZgjma+CooDrZwoEVFIfG1mTjVSdrNvvxpJ0xju1cYwE=,iv:G7rSoIcJFJS4zxaFcJlPkO3TqoteizUliNKpyHDgyeo=,tag:++pji9aEIz/BPjsxmdKJqw==,type:str]+sops_lastmodified=2026-04-07T15:42:38Z+sops_mac=ENC[AES256_GCM,data:CNE5K7Bv2wHHgqnndbnJLx4/OEWQF3XCe2YJy7ddVQyIhiDWDBKG57OJwsquAJLNmpWzOTt1YC2v/hSIidQeUz136uCYtOXLZAnhxdy7xh92SSkAGXjaWq9Q9+WjUosQt8ATWgvmysSONoQ0XA5ODLYuZmiZ0DKFbok8H+2Ha3M=,iv:MzQJPgB/QoYTN8MpocacYx33h8eEp/lVsllONbhSRcA=,tag:8a3Dr+DCZ1EHkhZcVoYbbg==,type:str]sops_unencrypted_suffix=_unencryptedsops_version=3.12.2diff --git a/rust/cloud-storage/notification/src/domain/service/egress.rs b/rust/cloud-storage/notification/src/domain/service/egress.rsindex fb42cc0901..794e246bf5 100644--- a/rust/cloud-storage/notification/src/domain/service/egress.rs+++ b/rust/cloud-storage/notification/src/domain/service/egress.rs@@ -20,9 +20,9 @@ use crate::domain::ports::{EmailSender, NotificationEgress, NotificationQueue, NotificationRepository, NotificationSender,RateLimitService, WebSocketSender,};+use cowlike::CowLike;use either::Either;use futures::stream::{FuturesUnordered, StreamExt};-use macro_user_id::email::ReadEmailParts;use macro_user_id::user_id::MacroUserIdStr;use rootcause::prelude::ResultExt;use rootcause::{Report, report};@@ -356,18 +356,28 @@ wherev @ ClaimResult::Empty | v @ ClaimResult::Wait(_) => return Ok(v.map(|_| ())),};- if batch.user_id.email_part().domain_part() != "macro.com" {- return Err(report!(- "Sending digest for non-macro user is currently disabled"- ));- }-let recipient: MacroUserIdStr<'static> = batch.user_id.clone();let email_notif = f(batch)?;- let email_content = EmailCreateBundle::new(&email_notif).with_recipient(recipient);let typename = NotificationTypeName::new_from_notif(&email_notif);+ // Check if the user has disabled this notification type+ let type_disabled_users = self+ .repository+ .get_users_with_type_disabled(typename.as_ref(), &[recipient.copied()])+ .await?;++ if type_disabled_users.contains(&recipient) {+ tracing::info!(+ user_id = %recipient,+ notification_type = %typename.as_ref(),+ "Skipping email digest publish — user has disabled this notification type"+ );+ return Ok(ClaimResult::Ready(()));+ }++ let email_content = EmailCreateBundle::new(&email_notif).with_recipient(recipient);+let message: QueueMessage<'static, T, ()> =QueueMessage::new_from_email(email_content, &typename);diff --git a/rust/cloud-storage/notification/src/domain/service/test.rs b/rust/cloud-storage/notification/src/domain/service/test.rsindex a1f05daaec..2cdbf39bcf 100644--- a/rust/cloud-storage/notification/src/domain/service/test.rs+++ b/rust/cloud-storage/notification/src/domain/service/test.rs@@ -1865,64 +1865,6 @@ async fn test_poll_email_digests_sends_email_for_ready_batch() {assert!(published[0]["content"]["Email"].is_object());}-/// temporary test which asserts we can't send to external users-/// This test should be removed in the future-#[tokio::test]-async fn it_fails_to_send_to_non_macro_users() {- use std::sync::Arc;-- let user = test_user_id("[email protected]");- let notif = UserNotificationRow {- owner_id: user.clone(),- notification_id: Uuid::nil(),- notification_event_type: "test_notification".to_string(),- entity: EntityType::Document.with_entity_str("doc-1"),- sent: false,- done: false,- created_at: None,- viewed_at: None,- updated_at: None,- deleted_at: None,- notification_metadata: serde_json::to_value(TestNotification {- message: "hello from digest".to_string(),- })- .unwrap(),- sender_id: None,- };-- let batch = DigestBatch {- user_id: user.clone(),- notifications: vec![notif.into_tagged()],- };-- let batcher = ReadyDigestBatcher {- batch: Mutex::new(Some(batch)),- };-- let queue = Arc::new(MockQueue::new());- let service = NotificationEgressService {- queue: queue.clone(),- repository: MockRepository::new(),- websocket: MockWebSocketSender,- mobile: MockMobileSender,- email: MockEmailSender,- rate_limiter: allowing_rate_limiter(),- state_machine: MockEgressStateMachine,- digest_batcher: batcher,- };-- fn digest_to_notif(batch: DigestBatch) -> Result<TestNotification, Report> {- Ok(TestNotification {- message: format!("You have {} notification(s)", batch.notifications.len()),- })- }-- service- .poll_email_digests(&digest_to_notif)- .await- .unwrap_err();-}-#[tokio::test]async fn test_poll_email_digests_noop_when_empty() {let service = create_egress_service(allowing_rate_limiter());@@ -2294,3 +2236,131 @@ impl NotificationSender for std::sync::Arc<TrackingMobileSender> {.await}}++// ============================================================================+// Egress Type-Disabled Digest Guard Tests+// ============================================================================++#[tokio::test]+async fn test_poll_email_digests_skips_publish_when_user_disabled_type() {+ use std::sync::Arc;++ let user = test_user_id("[email protected]");+ let notif = UserNotificationRow {+ owner_id: user.clone(),+ notification_id: Uuid::nil(),+ notification_event_type: "test_notification".to_string(),+ entity: EntityType::Document.with_entity_str("doc-1"),+ sent: false,+ done: false,+ created_at: None,+ viewed_at: None,+ updated_at: None,+ deleted_at: None,+ notification_metadata: serde_json::to_value(TestNotification {+ message: "hello from digest".to_string(),+ })+ .unwrap(),+ sender_id: None,+ };++ let batch = DigestBatch {+ user_id: user.clone(),+ notifications: vec![notif.into_tagged()],+ };++ let batcher = ReadyDigestBatcher {+ batch: Mutex::new(Some(batch)),+ };++ let queue = Arc::new(MockQueue::new());+ let service = NotificationEgressService {+ queue: queue.clone(),+ repository: MockRepository::new().with_type_disabled_user(user),+ websocket: MockWebSocketSender,+ mobile: MockMobileSender,+ email: MockEmailSender,+ rate_limiter: allowing_rate_limiter(),+ state_machine: MockEgressStateMachine,+ digest_batcher: batcher,+ };++ fn digest_to_notif(batch: DigestBatch) -> Result<TestNotification, Report> {+ Ok(TestNotification {+ message: format!("You have {} notification(s)", batch.notifications.len()),+ })+ }++ let result = service.poll_email_digests(&digest_to_notif).await.unwrap();++ // Should still return Ready (batch was consumed) but nothing published+ assert!(matches!(result, ClaimResult::Ready(())));+ assert!(+ queue.get_published().is_empty(),+ "No message should be published when user has disabled the notification type"+ );+}++#[tokio::test]+async fn test_poll_email_digests_publishes_when_user_has_not_disabled_type() {+ use std::sync::Arc;++ let user = test_user_id("[email protected]");+ let other_user = test_user_id("[email protected]");+ let notif = UserNotificationRow {+ owner_id: user.clone(),+ notification_id: Uuid::nil(),+ notification_event_type: "test_notification".to_string(),+ entity: EntityType::Document.with_entity_str("doc-1"),+ sent: false,+ done: false,+ created_at: None,+ viewed_at: None,+ updated_at: None,+ deleted_at: None,+ notification_metadata: serde_json::to_value(TestNotification {+ message: "hello from digest".to_string(),+ })+ .unwrap(),+ sender_id: None,+ };++ let batch = DigestBatch {+ user_id: user.clone(),+ notifications: vec![notif.into_tagged()],+ };++ let batcher = ReadyDigestBatcher {+ batch: Mutex::new(Some(batch)),+ };++ let queue = Arc::new(MockQueue::new());+ // A different user has the type disabled, not the digest recipient+ let service = NotificationEgressService {+ queue: queue.clone(),+ repository: MockRepository::new().with_type_disabled_user(other_user),+ websocket: MockWebSocketSender,+ mobile: MockMobileSender,+ email: MockEmailSender,+ rate_limiter: allowing_rate_limiter(),+ state_machine: MockEgressStateMachine,+ digest_batcher: batcher,+ };++ fn digest_to_notif(batch: DigestBatch) -> Result<TestNotification, Report> {+ Ok(TestNotification {+ message: format!("You have {} notification(s)", batch.notifications.len()),+ })+ }++ let result = service.poll_email_digests(&digest_to_notif).await.unwrap();++ assert!(matches!(result, ClaimResult::Ready(())));+ let published = queue.get_published();+ assert_eq!(+ published.len(),+ 1,+ "Message should be published when user has not disabled the type"+ );+ assert!(published[0]["content"]["Email"].is_object());+}diff --git a/rust/cloud-storage/notification/src/outbound/digest_batcher.rs b/rust/cloud-storage/notification/src/outbound/digest_batcher.rsindex b8b578bf49..87d7001208 100644--- a/rust/cloud-storage/notification/src/outbound/digest_batcher.rs+++ b/rust/cloud-storage/notification/src/outbound/digest_batcher.rs@@ -133,6 +133,21 @@ impl DigestBatcher for RedisDigestBatcher {return Ok(ClaimResult::Wait(Duration::from_secs(wait_secs as u64)));}+ // Discard stale digests older than 48 hours to avoid sending a backlog+ // of accumulated notifications (e.g. after removing the macro.com domain gate)+ const STALENESS_THRESHOLD: Duration = Duration::from_hours(48);+ let age_secs = now - score as i64;+ if age_secs > STALENESS_THRESHOLD.as_secs() as i64 {+ let digest_key = self.digest_key(&user_id_str);+ conn.del::<_, ()>(&digest_key).await?;+ tracing::warn!(+ user_id = %user_id_str,+ age_hours = age_secs / 3600,+ "Discarding stale email digest older than 48 hours"+ );+ return Ok(ClaimResult::Empty);+ }+let digest_key = self.digest_key(&user_id_str);let processing_key = self.processing_key(&user_id_str);diff --git a/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs b/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rsindex b53f020146..5bd9388994 100644--- a/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs+++ b/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs@@ -15,7 +15,7 @@ pub struct SandboxNotification {}impl Notification for SandboxNotification {- const TYPE_NAME: &'static str = "sandbox_notification";+ const TYPE_NAME: &'static str = "email-digest-notification";}impl NotificationExtIos for SandboxNotification {