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(calendar): retire join-request notifications with their event (#9252)
gbirman2aec9e449a1c
diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.mdindex cd8c013894..cf981179e8 100644--- a/crates/calendar_events/AGENTS.md+++ b/crates/calendar_events/AGENTS.md@@ -185,7 +185,18 @@ reminder dispatch, team availability, and provider/Postgres persistence.sharer twice. While the requester's request is pending or accepted,`copy_shared_event` refuses with `JoinRequestOpen`: the answer is aninvitation under the meeting's UID, which a snapshot imported meanwhile- would take in. A declined requester may still add a copy.+ would take in. A declined requester may still add a copy. Nothing in the+ domain retires the sharer's notification: opening the event marks it seen,+ and two triggers on `calendar_events` running+ `delete_calendar_event_join_request_notifications` delete it with the event+ row, or when the row turns `cancelled` (Outlook can keep a cancelled+ meeting). That covers the ways a copy goes away listed for channel grants+ above, and the delete reaches open clients through+ `trg_notify_user_notification_deletes`. The notifier only queues, so a backlog+ can deliver a notification after that cleanup; a `notification` insert trigger+ skips it while the event is gone or cancelled, locking the row to decide in+ order with a change in flight. The cancelled row keeps its requests, as it+ keeps its grants, and a cancelled occurrence changes neither.- Calendar mentions reach the agent as document mentions (`blockName``calendar`), but `ReadContent` and `ReadMetadata` need document access, whicha channel-shared event never grants. The agent reads a mentioned event withdiff --git a/crates/calendar_events/src/outbound/pg/test/join_requests.rs b/crates/calendar_events/src/outbound/pg/test/join_requests.rsindex 94408ad44f..4f5a9a21d8 100644--- a/crates/calendar_events/src/outbound/pg/test/join_requests.rs+++ b/crates/calendar_events/src/outbound/pg/test/join_requests.rs@@ -1,5 +1,6 @@use super::*;use crate::domain::join_requests::CalendarJoinRequestStatus;+use sqlx::postgres::PgListener;#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]async fn join_requests_open_once_and_resolve_once(pool: PgPool) {@@ -125,3 +126,437 @@ async fn join_requests_open_once_and_resolve_once(pool: PgPool) {.unwrap();assert_eq!(repo.get_join_request(first.id).await.unwrap(), None);}++pub(super) const JOIN_REQUEST_NOTIFICATION: &str = "calendar_event_join_request";++/// Store an unseen notification about `event_id`, as notification ingress does.+pub(super) async fn insert_notification(+ pool: &PgPool,+ notification_event_type: &str,+ event_id: Uuid,+ user_id: &str,+) -> Uuid {+ let id = Uuid::now_v7();+ let event_item_id = event_id.to_string();+ sqlx::query!(+ r#"+ INSERT INTO notification (+ id, notification_event_type, event_item_id, event_item_type, service_sender+ )+ VALUES ($1, $2, $3, 'calendar_event', 'document_storage_service')+ "#,+ id,+ notification_event_type,+ event_item_id,+ )+ .execute(pool)+ .await+ .unwrap();+ sqlx::query!(+ r#"+ INSERT INTO user_notification (+ user_id, notification_id, event_item_type, event_item_id, notification_event_type+ )+ VALUES ($1, $2, 'calendar_event', $3, $4)+ "#,+ user_id,+ id,+ event_item_id,+ notification_event_type,+ )+ .execute(pool)+ .await+ .unwrap();+ id+}++/// Whether the notification's recipient still has it.+pub(super) async fn recipient_holds(pool: &PgPool, notification_id: Uuid) -> bool {+ sqlx::query_scalar!(+ r#"SELECT EXISTS(SELECT 1 FROM user_notification WHERE notification_id = $1) AS "held!""#,+ notification_id,+ )+ .fetch_one(pool)+ .await+ .unwrap()+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_join_request_notification_goes_with_the_last_copy_of_its_event(pool: PgPool) {+ let sharer_id = "macro|[email protected]";+ let member_id = "macro|[email protected]";+ insert_user(&pool, member_id).await;+ let sharer_link = insert_link(&pool, sharer_id).await;+ let repo = PgCalendarRepository::new(pool.clone());+ let (account_id, primary_id) = provider_ids(&repo, sharer_link).await;+ let second_id = insert_shared_calendar(&repo, account_id, "writer", &[]).await;+ let uid = "[email protected]";+ let provider_event_id = format!("provider-{uid}");+ let event_id = repo+ .upsert_event_fixture(timed_upsert(+ sharer_id,+ sharer_link,+ (account_id, primary_id),+ uid,+ "Offsite",+ 1,+ ))+ .await+ .unwrap();+ repo.upsert_event_fixture(timed_upsert(+ sharer_id,+ sharer_link,+ (account_id, second_id),+ uid,+ "Offsite",+ 1,+ ))+ .await+ .unwrap();+ let other_event_id = repo+ .upsert_event_fixture(timed_upsert(+ sharer_id,+ sharer_link,+ (account_id, primary_id),+ "[email protected]",+ "Review",+ 1,+ ))+ .await+ .unwrap();+ repo.open_join_request(event_id, member_id, "[email protected]")+ .await+ .unwrap();+ let asked = insert_notification(&pool, JOIN_REQUEST_NOTIFICATION, event_id, sharer_id).await;+ let reminder = insert_notification(&pool, "calendar_event_reminder", event_id, sharer_id).await;+ let asked_elsewhere =+ insert_notification(&pool, JOIN_REQUEST_NOTIFICATION, other_event_id, sharer_id).await;+ let mut listener = PgListener::connect_with(&pool).await.unwrap();+ listener.listen("notification_events").await.unwrap();++ // The other copy keeps the event, so the sharer can still answer.+ repo.remove_provider_source(account_id, primary_id, &provider_event_id)+ .await+ .unwrap();+ assert!(recipient_holds(&pool, asked).await);++ // A delete through Macro retires the last copy, and open clients hear of it.+ repo.remove_provider_source(account_id, second_id, &provider_event_id)+ .await+ .unwrap();+ assert!(!recipient_holds(&pool, asked).await);+ let delivered = tokio::time::timeout(std::time::Duration::from_secs(5), listener.recv())+ .await+ .expect("the notification's delete should be published")+ .unwrap();+ assert_eq!(+ serde_json::from_str::<serde_json::Value>(delivered.payload()).unwrap(),+ serde_json::json!({+ "type": "user_notification_deletes",+ "notificationId": asked,+ "userIds": [sharer_id],+ })+ );++ assert!(recipient_holds(&pool, reminder).await);+ assert!(recipient_holds(&pool, asked_elsewhere).await);+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_cancelled_occurrence_keeps_the_join_request_notification_and_a_cancelled_series_drops_it(+ pool: PgPool,+) {+ let sharer_id = "macro|[email protected]";+ let member_id = "macro|[email protected]";+ insert_user(&pool, member_id).await;+ let sharer_link = insert_link(&pool, sharer_id).await;+ let repo = PgCalendarRepository::new(pool.clone());+ let enabled = repo+ .apply_google_grant(+ sharer_link,+ complete_grant(),+ CalendarGrantIntent::CalendarRequested,+ )+ .await+ .unwrap();+ let provider = provider_ids(&repo, sharer_link).await;+ let series = timed_upsert(+ sharer_id,+ sharer_link,+ provider,+ "[email protected]",+ "Standup",+ 1,+ );+ let event_id = repo.upsert_event_fixture(series.clone()).await.unwrap();+ let (request, _) = repo+ .open_join_request(event_id, member_id, "[email protected]")+ .await+ .unwrap();+ let asked = insert_notification(&pool, JOIN_REQUEST_NOTIFICATION, event_id, sharer_id).await;++ // Deleting one occurrence refreshes the series without it: the sharer can+ // still add the guest to the rest.+ let mut one_cancelled = series;+ one_cancelled.event.sequence = 2;+ one_cancelled.event.updated_at += Duration::minutes(1);+ one_cancelled.occurrences[1].is_cancelled = true;+ repo.upsert_event_fixture(one_cancelled).await.unwrap();+ assert!(recipient_holds(&pool, asked).await);+ assert_eq!(+ repo.get_join_request(request.id).await.unwrap(),+ Some(request)+ );++ // A tombstone for the series retires it.+ let google_job = enabled+ .jobs+ .into_iter()+ .find(|job| job.kind == CalendarBackfillKind::GoogleCalendar)+ .unwrap();+ let key = CalendarBackfillJobKey {+ job_id: google_job.id,+ email_link_id: sharer_link,+ };+ let CalendarBackfillClaim::Claimed { lease_token, .. } =+ repo.claim_google_backfill(key).await.unwrap()+ else {+ panic!("Google job should be claimable");+ };+ repo.commit_google_calendar_sync(+ key,+ lease_token,+ provider.0,+ GoogleCalendarSyncSnapshot {+ calendar_id: provider.1,+ next_sync_token: "after-tombstone".to_string(),+ observed_provider_event_ids: None,+ materialized_range: None,+ cancelled_provider_event_ids: vec!["[email protected]".to_string()],+ },+ 0,+ )+ .await+ .unwrap();+ assert!(!recipient_holds(&pool, asked).await);+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn removing_the_calendar_or_the_inbox_removes_join_request_notifications(pool: PgPool) {+ let sharer_id = "macro|[email protected]";+ let member_id = "macro|[email protected]";+ insert_user(&pool, member_id).await;+ let disconnected_link = insert_link(&pool, sharer_id).await;+ let removed_link = insert_link(&pool, sharer_id).await;+ let repo = PgCalendarRepository::new(pool.clone());+ let (_, _, disconnected_event_id, _) =+ connected_calendar(&pool, &repo, sharer_id, disconnected_link).await;+ let removed_provider = provider_ids(&repo, removed_link).await;+ let removed_event_id = repo+ .upsert_event_fixture(timed_upsert(+ sharer_id,+ removed_link,+ removed_provider,+ "[email protected]",+ "Review",+ 1,+ ))+ .await+ .unwrap();+ let on_disconnected_calendar = insert_notification(+ &pool,+ JOIN_REQUEST_NOTIFICATION,+ disconnected_event_id,+ sharer_id,+ )+ .await;+ let on_removed_inbox = insert_notification(+ &pool,+ JOIN_REQUEST_NOTIFICATION,+ removed_event_id,+ sharer_id,+ )+ .await;++ repo.disconnect_provider_calendar(sharer_id, disconnected_link)+ .await+ .unwrap()+ .expect("the owner's inbox is disconnectable");+ assert!(!recipient_holds(&pool, on_disconnected_calendar).await);+ assert!(recipient_holds(&pool, on_removed_inbox).await);++ sqlx::query!("DELETE FROM email_links WHERE id = $1", removed_link)+ .execute(&pool)+ .await+ .unwrap();+ assert!(!recipient_holds(&pool, on_removed_inbox).await);+}++/// Notification ingress's insert, reporting whether the row was stored.+async fn ingress_insert(+ executor: impl sqlx::PgExecutor<'_>,+ event_id: Uuid,+) -> Result<bool, sqlx::Error> {+ sqlx::query!(+ r#"+ INSERT INTO notification (+ id, notification_event_type, event_item_id, event_item_type, service_sender+ )+ VALUES (+ $1, 'calendar_event_join_request', $2, 'calendar_event', 'notification_service'+ )+ ON CONFLICT (id) DO NOTHING+ "#,+ Uuid::now_v7(),+ event_id.to_string(),+ )+ .execute(executor)+ .await+ .map(|result| result.rows_affected() == 1)+}++/// An event a sharer could be asked to join.+async fn shared_event(pool: &PgPool) -> Uuid {+ let sharer_id = "macro|[email protected]";+ let sharer_link = insert_link(pool, sharer_id).await;+ let repo = PgCalendarRepository::new(pool.clone());+ let provider = provider_ids(&repo, sharer_link).await;+ repo.upsert_event_fixture(timed_upsert(+ sharer_id,+ sharer_link,+ provider,+ "[email protected]",+ "Offsite",+ 1,+ ))+ .await+ .unwrap()+}++async fn backend_pid(transaction: &mut Transaction<'_, Postgres>) -> i32 {+ sqlx::query_scalar!(r#"SELECT pg_backend_pid() AS "pid!""#)+ .fetch_one(&mut **transaction)+ .await+ .unwrap()+}++/// Only Postgres can tell that a statement is waiting on `blocker`'s row lock.+async fn wait_for_blocked_transaction(pool: &PgPool, blocker: i32) {+ tokio::time::timeout(std::time::Duration::from_secs(10), async {+ loop {+ let waiting = sqlx::query_scalar!(+ r#"SELECT EXISTS (+ SELECT 1 FROM pg_stat_activity+ WHERE datname = current_database()+ AND $1 = ANY(pg_blocking_pids(pid))+ ) AS "waiting!""#,+ blocker,+ )+ .fetch_one(pool)+ .await+ .unwrap();+ if waiting {+ return;+ }+ tokio::time::sleep(std::time::Duration::from_millis(10)).await;+ }+ })+ .await+ .expect("the statement should wait on the row lock");+}++async fn stored_notifications(pool: &PgPool) -> i64 {+ sqlx::query_scalar!(r#"SELECT count(*) AS "count!" FROM notification"#)+ .fetch_one(pool)+ .await+ .unwrap()+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_queued_join_request_notification_is_not_stored_after_its_event_went(pool: PgPool) {+ let event_id = shared_event(&pool).await;+ assert!(ingress_insert(&pool, event_id).await.unwrap());++ sqlx::query!(+ "UPDATE calendar_events SET status = 'cancelled' WHERE id = $1",+ event_id,+ )+ .execute(&pool)+ .await+ .unwrap();+ assert!(!ingress_insert(&pool, event_id).await.unwrap());++ sqlx::query!("DELETE FROM calendar_events WHERE id = $1", event_id)+ .execute(&pool)+ .await+ .unwrap();+ assert!(!ingress_insert(&pool, event_id).await.unwrap());+ assert_eq!(stored_notifications(&pool).await, 0);+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_queued_insert_waits_for_a_cancellation_then_stores_nothing(pool: PgPool) {+ let event_id = shared_event(&pool).await;+ let mut cancelling = pool.begin().await.unwrap();+ let blocker = backend_pid(&mut cancelling).await;+ sqlx::query!(+ "UPDATE calendar_events SET status = 'cancelled' WHERE id = $1",+ event_id,+ )+ .execute(&mut *cancelling)+ .await+ .unwrap();++ let arriving = tokio::spawn({+ let pool = pool.clone();+ async move { ingress_insert(&pool, event_id).await }+ });+ wait_for_blocked_transaction(&pool, blocker).await;+ cancelling.commit().await.unwrap();++ assert!(!arriving.await.unwrap().unwrap());+ assert_eq!(stored_notifications(&pool).await, 0);+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_queued_insert_waits_for_a_delete_then_stores_nothing(pool: PgPool) {+ let event_id = shared_event(&pool).await;+ let mut deleting = pool.begin().await.unwrap();+ let blocker = backend_pid(&mut deleting).await;+ sqlx::query!("DELETE FROM calendar_events WHERE id = $1", event_id)+ .execute(&mut *deleting)+ .await+ .unwrap();++ let arriving = tokio::spawn({+ let pool = pool.clone();+ async move { ingress_insert(&pool, event_id).await }+ });+ wait_for_blocked_transaction(&pool, blocker).await;+ deleting.commit().await.unwrap();++ assert!(!arriving.await.unwrap().unwrap());+ assert_eq!(stored_notifications(&pool).await, 0);+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_delete_waits_for_a_queued_insert_then_retires_it(pool: PgPool) {+ let event_id = shared_event(&pool).await;+ let mut arriving = pool.begin().await.unwrap();+ let blocker = backend_pid(&mut arriving).await;+ assert!(ingress_insert(&mut *arriving, event_id).await.unwrap());++ let deleting = tokio::spawn({+ let pool = pool.clone();+ async move {+ sqlx::query!("DELETE FROM calendar_events WHERE id = $1", event_id)+ .execute(&pool)+ .await+ }+ });+ wait_for_blocked_transaction(&pool, blocker).await;+ arriving.commit().await.unwrap();++ deleting.await.unwrap().unwrap();+ assert_eq!(stored_notifications(&pool).await, 0);+}diff --git a/crates/calendar_events/src/outbound/pg/test/outlook.rs b/crates/calendar_events/src/outbound/pg/test/outlook.rsindex a3927dc058..21fd92d72c 100644--- a/crates/calendar_events/src/outbound/pg/test/outlook.rs+++ b/crates/calendar_events/src/outbound/pg/test/outlook.rs@@ -1,3 +1,4 @@+use super::join_requests::{JOIN_REQUEST_NOTIFICATION, insert_notification, recipient_holds};use super::*;use crate::domain::models::{AutomaticDeclinePolicy, OutOfOfficeAutoDeclineMode, OutOfOfficeProperties,@@ -1397,3 +1398,62 @@ async fn the_organizer_repair_stores_outlook_organizers_as_holding_their_meeting"a rerun finds nothing left to fix");}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn an_outlook_cancellation_or_removal_retires_join_request_notifications(pool: PgPool) {+ let (repo, _, owner) = mailbox(&pool).await;+ let member = "macro|[email protected]";+ insert_user(&pool, member).await;+ let lease = calendar(&repo).await;+ repo.checkpoint_outlook_calendar(+ &lease,+ OutlookCalendarProgress::Page(OutlookCalendarPage {+ members: vec![("provider-removed".into(), "provider-removed".into())],+ removed: vec![],+ next: None,+ delta: Some("baseline".into()),+ }),+ )+ .await+ .unwrap();+ let event = claim(&repo).await.unwrap();+ let cancelled_id = store(&repo, &event, "cancelled").await;+ let removed_id = store(&repo, &event, "removed").await;+ let (request, _) = repo+ .open_join_request(cancelled_id, member, "[email protected]")+ .await+ .unwrap();+ let on_cancelled =+ insert_notification(&pool, JOIN_REQUEST_NOTIFICATION, cancelled_id, &owner).await;+ let on_removed =+ insert_notification(&pool, JOIN_REQUEST_NOTIFICATION, removed_id, &owner).await;++ // Outlook can keep a cancelled meeting: the row stays, with its request.+ let mut cancelled = upsert(&event, "cancelled");+ cancelled.event.status = EventStatus::Cancelled;+ cancelled.event.sequence = 1;+ cancelled.event.updated_at += Duration::minutes(1);+ repo.upsert_event(CalendarEventWrite::OutlookSync {+ lease: Box::new(event.clone()),+ upsert: cancelled,+ })+ .await+ .unwrap();+ assert!(!recipient_holds(&pool, on_cancelled).await);+ assert_eq!(+ repo.get_join_request(request.id).await.unwrap(),+ Some(request)+ );+ assert!(recipient_holds(&pool, on_removed).await);++ repo.checkpoint_outlook_calendar(+ &event,+ OutlookCalendarProgress::Event {+ id: "provider-removed".into(),+ exists: false,+ },+ )+ .await+ .unwrap();+ assert!(!recipient_holds(&pool, on_removed).await);+}diff --git a/crates/macro_db_client/migrations/20261030230443_calendar_event_join_request_notification_cleanup.sql b/crates/macro_db_client/migrations/20261030230443_calendar_event_join_request_notification_cleanup.sqlnew file mode 100644index 0000000000..13eafb59ed--- /dev/null+++ b/crates/macro_db_client/migrations/20261030230443_calendar_event_join_request_notification_cleanup.sql@@ -0,0 +1,73 @@+-- A calendar event's join-request notifications go when the event does.+--+-- A notification about a request to join an event that has gone leads nowhere,+-- and nothing else clears it: only opening the event marks it seen. The event+-- row is deleted by sync once its last source is gone (a delete through Macro,+-- a cancellation or removal synced from Google or Outlook, a disabled calendar)+-- and by the email_links cascade when the inbox is removed, so, as with+-- calendar_event_entity_access_cleanup, the cleanup lives on the row rather+-- than on each of those paths. Outlook can also keep a cancelled meeting as a+-- row with status 'cancelled'. Calendars, previews and exports skip that row,+-- so the sharer has nowhere left to answer and the notification goes then too.+-- The row keeps its requests, as it keeps its grants, because it can come back.+-- A cancelled occurrence changes neither, so its series' requests stand.+--+-- Deleting the notification, rather than marking it, is what reaches open+-- clients (trg_notify_user_notification_deletes) and takes it out of a pending+-- digest email.+--+-- These notifications are queued, and a backlog can deliver one minutes after+-- its event went, past the cleanup above, so the insert checks the event too.+-- The lookup locks the row FOR SHARE, which also conflicts with a status+-- update, so it waits for a delete or cancellation in flight: whichever commits+-- first, the notification does not outlive the event. Returning NULL skips the+-- insert, which notification ingress reads as nothing to deliver.++SET LOCAL lock_timeout = '5s';++CREATE FUNCTION delete_calendar_event_join_request_notifications()+ RETURNS TRIGGER+ LANGUAGE PLPGSQL+ AS+$$+ BEGIN+ DELETE FROM notification+ WHERE event_item_type = 'calendar_event'+ AND event_item_id = OLD.id::text+ AND notification_event_type = 'calendar_event_join_request';+ RETURN NULL;+ END;+$$;++CREATE TRIGGER calendar_event_join_request_notification_cleanup+ AFTER DELETE ON calendar_events+ FOR EACH ROW EXECUTE FUNCTION delete_calendar_event_join_request_notifications();++CREATE TRIGGER calendar_event_cancelled_join_request_notification_cleanup+ AFTER UPDATE OF status ON calendar_events+ FOR EACH ROW+ WHEN (NEW.status = 'cancelled' AND OLD.status <> 'cancelled')+ EXECUTE FUNCTION delete_calendar_event_join_request_notifications();++CREATE FUNCTION skip_join_request_notification_without_live_event()+ RETURNS TRIGGER+ LANGUAGE PLPGSQL+ AS+$$+ BEGIN+ PERFORM 1 FROM calendar_events+ WHERE id = NEW.event_item_id::uuid+ AND status <> 'cancelled'+ FOR SHARE;+ IF FOUND THEN+ RETURN NEW;+ END IF;+ RETURN NULL;+ END;+$$;++CREATE TRIGGER calendar_event_join_request_notification_guard+ BEFORE INSERT ON notification+ FOR EACH ROW+ WHEN (NEW.notification_event_type = 'calendar_event_join_request')+ EXECUTE FUNCTION skip_join_request_notification_without_live_event();diff --git a/crates/notification/AGENTS.md b/crates/notification/AGENTS.mdindex 9f1155d3c7..7692249fd1 100644--- a/crates/notification/AGENTS.md+++ b/crates/notification/AGENTS.md@@ -82,6 +82,10 @@ through the same service.notification. Retries preserve original IDs, recipients, and lifecycle state.- Access-request withdrawals suppress delayed ingress and queued push/realtimedelivery; keep tombstone checks when changing either delivery boundary.+- A `calendar_event_join_request` insert is skipped by a `notification` trigger+ when its event has gone or been cancelled, since queued ingress can run after+ the event's cleanup. `create_notification` reads the skipped insert as nothing+ to deliver, so keep that `rows_affected` check.- Crates on `macrod`'s dependency path (`teams`, `model_notifications`,`invite_email`) take this crate with `default-features = false`, which keepslibrdkafka out of the self-hosted daemon; keep it that way.diff --git a/crates/notification/src/outbound/repository/test.rs b/crates/notification/src/outbound/repository/test.rsindex c2bde35078..15b3abb1d7 100644--- a/crates/notification/src/outbound/repository/test.rs+++ b/crates/notification/src/outbound/repository/test.rs@@ -30,6 +30,13 @@ impl Notification for TestMessageNotification {const TYPE_NAME: &'static str = "test_message_notification";}+#[derive(Debug, Clone, Serialize, Deserialize)]+struct TestCalendarJoinRequest;++impl Notification for TestCalendarJoinRequest {+ const TYPE_NAME: &'static str = "calendar_event_join_request";+}+#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]struct TestTaskNotification {@@ -218,6 +225,25 @@ async fn test_create_notification(pool: Pool<Postgres>) {assert_eq!(user_row.user_id, recipient.to_string());}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn a_join_request_for_an_event_that_has_gone_is_nothing_to_deliver(pool: Pool<Postgres>) {+ let request = SendNotificationRequestBuilder {+ notification_entity: EntityType::CalendarEvent+ .with_entity_string(Uuid::now_v7().to_string()),+ secondary_notification_entity: None,+ notification: TaggedContent::new(TestCalendarJoinRequest),+ sender_id: None,+ recipient_ids: std::collections::HashSet::from([test_user("[email protected]")]),+ };++ assert!(+ pool.create_notification(request, Uuid::now_v7(), "test_service", None)+ .await+ .unwrap()+ .is_none()+ );+}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]async fn test_create_notification_stores_secondary_entity(pool: Pool<Postgres>) {let recipient = test_user("[email protected]");diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex 27e4fc0f11..a239ba6d40 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -885,7 +885,9 @@ Outlook sends the invitation and the mention then opens the viewer's own copy. Dthe requester nothing, but their card then reads `Declined` and `The person who shared this eventdeclined your request to join.` with no `Ask to join`, and offers `Add to calendar` again. Adeclined request stands: the server refuses another ask with 409 `request_declined`, so the-sharer is asked only once. A classic `@Macro` reply that+sharer is asked only once. The notification goes when the event does (deleted in Macro, deleted+or cancelled in Google or Outlook, its calendar or inbox removed); deleting one occurrence of a+series leaves it, since the sharer can still add the guest. A classic `@Macro` reply thatmentions an event does not shareit by posting the chip. It asks whether to share with the channel, and a yes in that threadwrites the same channel grant. Private and confidential events are never shared this way.