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): decline reminders from owner inboxes (#5967)
teo136b2f03de2e
diff --git a/.sqlx/query-3109aafbbfdabf1154df4ddd78b499bf363aa384b30e7a6d9f6a116690e1d4bc.json b/.sqlx/query-dd4f3ff26fd5c8c3f30f135559175d052a10ea7ef88c811c0dec8508bfc5d09a.jsonsimilarity index 78%rename from .sqlx/query-3109aafbbfdabf1154df4ddd78b499bf363aa384b30e7a6d9f6a116690e1d4bc.jsonrename to .sqlx/query-dd4f3ff26fd5c8c3f30f135559175d052a10ea7ef88c811c0dec8508bfc5d09a.jsonindex 735ead36a4..74443f25d7 100644--- a/.sqlx/query-3109aafbbfdabf1154df4ddd78b499bf363aa384b30e7a6d9f6a116690e1d4bc.json+++ b/.sqlx/query-dd4f3ff26fd5c8c3f30f135559175d052a10ea7ef88c811c0dec8508bfc5d09a.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n event.owner_id,\n event.title,\n event.time_zone AS \"event_time_zone?\",\n occurrence.starts_at,\n occurrence.ends_at,\n occurrence.start_date,\n occurrence.end_date,\n canonical_source.calendar_time_zone AS \"calendar_time_zone?\",\n CASE WHEN EXISTS (\n SELECT 1\n FROM calendar_event_overrides override\n WHERE override.event_id = event.id\n AND override.recurrence_id = occurrence.recurrence_id\n AND override.attendees_overridden\n )\n THEN EXISTS (\n SELECT 1\n FROM calendar_event_override_attendees attendee\n WHERE attendee.event_id = event.id\n AND attendee.recurrence_id = occurrence.recurrence_id\n AND attendee.is_self\n AND attendee.response_status = 'declined'\n )\n ELSE EXISTS (\n SELECT 1\n FROM calendar_event_attendees attendee\n WHERE attendee.event_id = event.id\n AND attendee.is_self\n AND attendee.response_status = 'declined'\n )\n END AS \"declined!\"\n FROM calendar_event_reminder_firings firing\n JOIN calendar_events event ON event.id = firing.event_id\n JOIN calendar_event_occurrences occurrence\n ON occurrence.event_id = firing.event_id\n AND occurrence.occurrence_key = firing.occurrence_key\n JOIN LATERAL (\n SELECT calendar.time_zone AS calendar_time_zone\n FROM calendar_event_sources source\n JOIN calendars calendar ON calendar.id = source.calendar_id\n JOIN calendar_accounts account ON account.id = source.account_id\n WHERE source.event_id = event.id\n AND NOT calendar.is_deleted\n AND account.sync_status <> 'disabled'\n ORDER BY\n source.source_sequence DESC,\n source.source_updated_at DESC,\n source.last_seen_at DESC,\n source.id DESC\n LIMIT 1\n ) canonical_source ON true\n WHERE firing.event_id = $1\n AND firing.occurrence_key = $2\n AND firing.minutes_before = $3\n AND firing.fire_at = $4\n AND firing.fire_at > $5\n AND event.status <> 'cancelled'\n AND NOT occurrence.is_cancelled\n ",+ "query": "\n SELECT\n event.owner_id,\n event.title,\n event.time_zone AS \"event_time_zone?\",\n occurrence.starts_at,\n occurrence.ends_at,\n occurrence.start_date,\n occurrence.end_date,\n canonical_source.calendar_time_zone AS \"calendar_time_zone?\",\n CASE WHEN EXISTS (\n SELECT 1\n FROM calendar_event_overrides override\n WHERE override.event_id = event.id\n AND override.recurrence_id = occurrence.recurrence_id\n AND override.attendees_overridden\n )\n THEN EXISTS (\n SELECT 1\n FROM calendar_event_override_attendees attendee\n JOIN email_links owner_inbox\n ON owner_inbox.macro_id = event.owner_id\n AND lower(owner_inbox.email_address::text) = attendee.email\n WHERE attendee.event_id = event.id\n AND attendee.recurrence_id = occurrence.recurrence_id\n AND attendee.response_status = 'declined'\n )\n ELSE EXISTS (\n SELECT 1\n FROM calendar_event_attendees attendee\n JOIN email_links owner_inbox\n ON owner_inbox.macro_id = event.owner_id\n AND lower(owner_inbox.email_address::text) = attendee.email\n WHERE attendee.event_id = event.id\n AND attendee.response_status = 'declined'\n )\n END AS \"declined!\"\n FROM calendar_event_reminder_firings firing\n JOIN calendar_events event ON event.id = firing.event_id\n JOIN calendar_event_occurrences occurrence\n ON occurrence.event_id = firing.event_id\n AND occurrence.occurrence_key = firing.occurrence_key\n JOIN LATERAL (\n SELECT calendar.time_zone AS calendar_time_zone\n FROM calendar_event_sources source\n JOIN calendars calendar ON calendar.id = source.calendar_id\n JOIN calendar_accounts account ON account.id = source.account_id\n WHERE source.event_id = event.id\n AND NOT calendar.is_deleted\n AND account.sync_status <> 'disabled'\n ORDER BY\n source.source_sequence DESC,\n source.source_updated_at DESC,\n source.last_seen_at DESC,\n source.id DESC\n LIMIT 1\n ) canonical_source ON true\n WHERE firing.event_id = $1\n AND firing.occurrence_key = $2\n AND firing.minutes_before = $3\n AND firing.fire_at = $4\n AND firing.fire_at > $5\n AND event.status <> 'cancelled'\n AND NOT occurrence.is_cancelled\n ","describe": {"columns": [{@@ -70,5 +70,5 @@null]},- "hash": "3109aafbbfdabf1154df4ddd78b499bf363aa384b30e7a6d9f6a116690e1d4bc"+ "hash": "dd4f3ff26fd5c8c3f30f135559175d052a10ea7ef88c811c0dec8508bfc5d09a"}diff --git a/apps/web/src/lib/service-clients/service-email/generated/schemas/calendarAttendee.ts b/apps/web/src/lib/service-clients/service-email/generated/schemas/calendarAttendee.tsindex d1170137d4..045a27614f 100644--- a/apps/web/src/lib/service-clients/service-email/generated/schemas/calendarAttendee.ts+++ b/apps/web/src/lib/service-clients/service-email/generated/schemas/calendarAttendee.ts@@ -23,10 +23,7 @@ export interface CalendarAttendee {isOptional: boolean;/** Whether this attendee is the organizer. */isOrganizer: boolean;- /** Whether this attendee is one of the viewing requester's inboxes.--Outbound projections use the requester's owned inboxes only.-Persisted rows keep the provider's flag, which reminder decline reads. */+ /** Whether this attendee is one of the viewing requester's inboxes. */isSelf: boolean;/** RSVP state. */responseStatus: AttendeeResponseStatus;diff --git a/apps/web/src/lib/service-clients/service-email/openapi.json b/apps/web/src/lib/service-clients/service-email/openapi.jsonindex 7d6f24d400..83623de36b 100644--- a/apps/web/src/lib/service-clients/service-email/openapi.json+++ b/apps/web/src/lib/service-clients/service-email/openapi.json@@ -4475,7 +4475,7 @@},"isSelf": {"type": "boolean",- "description": "Whether this attendee is one of the viewing requester's inboxes.\n\nOutbound projections use the requester's owned inboxes only.\nPersisted rows keep the provider's flag, which reminder decline reads."+ "description": "Whether this attendee is one of the viewing requester's inboxes."},"responseStatus": {"$ref": "#/components/schemas/AttendeeResponseStatus",diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarAttendee.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarAttendee.tsindex 44ada89450..cdf1b4afbd 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarAttendee.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/calendarAttendee.ts@@ -23,10 +23,7 @@ export interface CalendarAttendee {isOptional: boolean;/** Whether this attendee is the organizer. */isOrganizer: boolean;- /** Whether this attendee is one of the viewing requester's inboxes.--Outbound projections use the requester's owned inboxes only.-Persisted rows keep the provider's flag, which reminder decline reads. */+ /** Whether this attendee is one of the viewing requester's inboxes. */isSelf: boolean;/** RSVP state. */responseStatus: AttendeeResponseStatus;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts b/apps/web/src/lib/service-clients/service-storage/generated/zod.tsindex 4cf7e634f6..1068190c83 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts@@ -806,7 +806,7 @@ export const listOccurrencesResponse = zodisSelf: zod.boolean().describe(- "Whether this attendee is one of the viewing requester's inboxes.\n\nOutbound projections use the requester's owned inboxes only.\nPersisted rows keep the provider's flag, which reminder decline reads."+ "Whether this attendee is one of the viewing requester's inboxes."),responseStatus: zod.enum([diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.jsonindex 949d900e0b..812a595272 100644--- a/apps/web/src/lib/service-clients/service-storage/openapi.json+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json@@ -13271,7 +13271,7 @@},"isSelf": {"type": "boolean",- "description": "Whether this attendee is one of the viewing requester's inboxes.\n\nOutbound projections use the requester's owned inboxes only.\nPersisted rows keep the provider's flag, which reminder decline reads."+ "description": "Whether this attendee is one of the viewing requester's inboxes."},"responseStatus": {"$ref": "#/components/schemas/AttendeeResponseStatus",diff --git a/crates/calendar_events/src/domain/models.rs b/crates/calendar_events/src/domain/models.rsindex e225fa3a41..8f60a2e0c0 100644--- a/crates/calendar_events/src/domain/models.rs+++ b/crates/calendar_events/src/domain/models.rs@@ -322,9 +322,6 @@ pub struct CalendarAttendee {/// Whether attendance is optional.pub is_optional: bool,/// Whether this attendee is one of the viewing requester's inboxes.- ///- /// Outbound projections use the requester's owned inboxes only.- /// Persisted rows keep the provider's flag, which reminder decline reads.pub is_self: bool,/// Optional attendee comment.pub comment: Option<String>,diff --git a/crates/calendar_events/src/outbound/pg.rs b/crates/calendar_events/src/outbound/pg.rsindex 3ee308537a..99e5567b42 100644--- a/crates/calendar_events/src/outbound/pg.rs+++ b/crates/calendar_events/src/outbound/pg.rs@@ -3518,16 +3518,20 @@ impl CalendarReminderDispatchRepo for PgCalendarRepository {THEN EXISTS (SELECT 1FROM calendar_event_override_attendees attendee+ JOIN email_links owner_inbox+ ON owner_inbox.macro_id = event.owner_id+ AND lower(owner_inbox.email_address::text) = attendee.emailWHERE attendee.event_id = event.idAND attendee.recurrence_id = occurrence.recurrence_id- AND attendee.is_selfAND attendee.response_status = 'declined')ELSE EXISTS (SELECT 1FROM calendar_event_attendees attendee+ JOIN email_links owner_inbox+ ON owner_inbox.macro_id = event.owner_id+ AND lower(owner_inbox.email_address::text) = attendee.emailWHERE attendee.event_id = event.id- AND attendee.is_selfAND attendee.response_status = 'declined')END AS "declined!"diff --git a/crates/calendar_events/src/outbound/pg/test.rs b/crates/calendar_events/src/outbound/pg/test.rsindex 345ad3d14d..4fd84c5c6d 100644--- a/crates/calendar_events/src/outbound/pg/test.rs+++ b/crates/calendar_events/src/outbound/pg/test.rs@@ -2651,6 +2651,22 @@ fn reminder_upsert(}}+fn reminder_attendee(email: &str, declined: bool, is_self: bool) -> CalendarAttendee {+ CalendarAttendee {+ email: email.to_string(),+ display_name: None,+ response_status: if declined {+ AttendeeResponseStatus::Declined+ } else {+ AttendeeResponseStatus::Accepted+ },+ is_organizer: false,+ is_optional: false,+ is_self,+ comment: None,+ }+}+fn popup_reminders(minutes: &[u32]) -> EventReminders {EventReminders {use_default: false,@@ -2990,7 +3006,7 @@ async fn stale_and_declined_firings_resolve_safely(pool: PgPool) {popup_reminders(&[10]),);declined.event.attendees = vec![CalendarAttendee {- email: "[email protected]".to_string(),+ email: format!("calendar-{link_id}@example.com"),display_name: None,response_status: AttendeeResponseStatus::Declined,is_organizer: false,@@ -3023,6 +3039,75 @@ async fn stale_and_declined_firings_resolve_safely(pool: PgPool) {assert_eq!(past, Vec::new());}+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn reminder_decline_follows_owner_inbox_not_calendar_self(pool: PgPool) {+ let owner_id = "macro|[email protected]";+ let link_id = insert_link(&pool, owner_id).await;+ let owner_inbox = format!("calendar-{link_id}@example.com");+ let repo = PgCalendarRepository::new(pool.clone());+ let provider = provider_ids(&repo, link_id).await;+ let starts_at = (Utc::now() + Duration::minutes(10)).trunc_subsecs(0);++ let mut coworker_declined = reminder_upsert(+ owner_id,+ link_id,+ provider,+ "coworker-declined",+ starts_at,+ popup_reminders(&[10]),+ );+ coworker_declined.event.attendees = vec![+ reminder_attendee("[email protected]", true, true),+ reminder_attendee(&owner_inbox, false, false),+ ];+ let coworker_event_id = repo.upsert_event_fixture(coworker_declined).await.unwrap();++ let mut owner_declined = reminder_upsert(+ owner_id,+ link_id,+ provider,+ "owner-declined",+ starts_at,+ popup_reminders(&[10]),+ );+ owner_declined.event.attendees = vec![+ reminder_attendee("[email protected]", false, true),+ reminder_attendee(&owner_inbox, true, false),+ ];+ let owner_event_id = repo.upsert_event_fixture(owner_declined).await.unwrap();++ let due = repo+ .due_reminder_firings(Utc::now(), None, 100)+ .await+ .unwrap();+ let firing_for = |event_id| {+ due.iter()+ .find(|firing| firing.event_id == event_id)+ .expect("event has a due firing")+ .clone()+ };++ let coworker = repo+ .find_due_reminder(&firing_for(coworker_event_id))+ .await+ .unwrap()+ .unwrap();+ assert!(+ !coworker.declined,+ "a coworker's declined self row must not suppress the owner's reminder"+ );++ let owner = repo+ .find_due_reminder(&firing_for(owner_event_id))+ .await+ .unwrap()+ .unwrap();+ assert!(+ owner.declined,+ "the owner's own declined inbox must suppress the reminder even when is_self is on a coworker"+ );+}+/// The provider classification has to survive the write and come back on the/// read path: it is what tells the product a conference is one Macro may/// detach, so losing it in persistence would put a third-party conference atdiff --git a/packages/sdk/generated/email/types.gen.ts b/packages/sdk/generated/email/types.gen.tsindex fe9dda071c..6b6b556557 100644--- a/packages/sdk/generated/email/types.gen.ts+++ b/packages/sdk/generated/email/types.gen.ts@@ -560,9 +560,6 @@ export type CalendarAttendee = {isOrganizer: boolean;/*** Whether this attendee is one of the viewing requester's inboxes.- *- * Outbound projections use the requester's owned inboxes only.- * Persisted rows keep the provider's flag, which reminder decline reads.*/isSelf: boolean;/**diff --git a/packages/sdk/generated/storage/types.gen.ts b/packages/sdk/generated/storage/types.gen.tsindex d9301c7109..0d26974a5b 100644--- a/packages/sdk/generated/storage/types.gen.ts+++ b/packages/sdk/generated/storage/types.gen.ts@@ -1225,9 +1225,6 @@ export type CalendarAttendee = {isOrganizer: boolean;/*** Whether this attendee is one of the viewing requester's inboxes.- *- * Outbound projections use the requester's owned inboxes only.- * Persisted rows keep the provider's flag, which reminder decline reads.*/isSelf: boolean;/**diff --git a/packages/sdk/specs/email.json b/packages/sdk/specs/email.jsonindex 7d6f24d400..83623de36b 100644--- a/packages/sdk/specs/email.json+++ b/packages/sdk/specs/email.json@@ -4475,7 +4475,7 @@},"isSelf": {"type": "boolean",- "description": "Whether this attendee is one of the viewing requester's inboxes.\n\nOutbound projections use the requester's owned inboxes only.\nPersisted rows keep the provider's flag, which reminder decline reads."+ "description": "Whether this attendee is one of the viewing requester's inboxes."},"responseStatus": {"$ref": "#/components/schemas/AttendeeResponseStatus",diff --git a/packages/sdk/specs/storage.json b/packages/sdk/specs/storage.jsonindex 949d900e0b..812a595272 100644--- a/packages/sdk/specs/storage.json+++ b/packages/sdk/specs/storage.json@@ -13271,7 +13271,7 @@},"isSelf": {"type": "boolean",- "description": "Whether this attendee is one of the viewing requester's inboxes.\n\nOutbound projections use the requester's owned inboxes only.\nPersisted rows keep the provider's flag, which reminder decline reads."+ "description": "Whether this attendee is one of the viewing requester's inboxes."},"responseStatus": {"$ref": "#/components/schemas/AttendeeResponseStatus",