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): store an Outlook organizer as holding their meeting (#8860)
gbirmana987bb62a82a
diff --git a/crates/calendar_events/src/outbound/pg/test/outlook.rs b/crates/calendar_events/src/outbound/pg/test/outlook.rsindex 8b3b2118dc..99ae0c0619 100644--- a/crates/calendar_events/src/outbound/pg/test/outlook.rs+++ b/crates/calendar_events/src/outbound/pg/test/outlook.rs@@ -1215,3 +1215,160 @@ async fn automatic_decline_candidates_are_fair_bounded_and_respect_disabled_occu.all(|r| first.iter().all(|f| f.invitation_id != r.invitation_id)));}++/// The migration that stores Outlook organizers, whom Graph lists as not+/// having answered, as holding their meetings.+const OUTLOOK_ORGANIZERS_HOLD_THEIR_MEETINGS: &str = include_str!(+ "../../../../../macro_db_client/migrations/20261026191007_outlook_organizers_hold_their_meetings.sql"+);++fn unanswered(email: &str, is_organizer: bool) -> CalendarAttendee {+ CalendarAttendee {+ email: email.into(),+ display_name: None,+ response_status: AttendeeResponseStatus::NeedsAction,+ is_organizer,+ is_optional: false,+ is_self: false,+ comment: None,+ }+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn the_organizer_repair_stores_outlook_organizers_as_holding_their_meetings(pool: PgPool) {+ let (repo, link, _) = mailbox(&pool).await;+ let lease = calendar(&repo).await;+ // How sync stored a series Macro created before October 2026: the+ // organizer unanswered on the series and on its one exception.+ let mut stored = upsert(&lease, "[email protected]");+ stored.event.organizer_email = Some("[email protected]".into());+ let guests = vec![+ unanswered("[email protected]", true),+ unanswered("[email protected]", false),+ ];+ stored.event.attendees = guests.clone();+ let moved = stored.occurrences[1].clone();+ let EventTime::Timed {+ starts_at: moved_start,+ ..+ } = moved.time+ else {+ panic!("the fixture's occurrences are timed");+ };+ stored.overrides = vec![CalendarEventOverride {+ reminders: None,+ automatic_decline: None,+ sequence: None,+ source_updated_at: None,+ recurrence_id: moved.occurrence_key.clone(),+ original_time: EventStart::Timed(moved_start),+ time: moved.time.clone(),+ title: Some("Moved".into()),+ description: None,+ location: None,+ status: None,+ visibility: None,+ transparency: None,+ attendees: Some(guests),+ }];+ let event_id = repo+ .upsert_event(CalendarEventWrite::OutlookSync {+ lease: Box::new(lease.clone()),+ upsert: stored,+ })+ .await+ .unwrap()+ .event_id;+ let counter = || async {+ sqlx::query_scalar!(+ "SELECT seq FROM calendar_change_counters WHERE link_id = $1",+ link,+ )+ .fetch_one(&pool)+ .await+ .unwrap()+ };+ let before = counter().await;++ sqlx::raw_sql(OUTLOOK_ORGANIZERS_HOLD_THEIR_MEETINGS)+ .execute(&pool)+ .await+ .unwrap();++ let rows = sqlx::query!(+ r#"+ SELECT email, response_status, 'series' AS "scope!"+ FROM calendar_event_attendees WHERE event_id = $1+ UNION ALL+ SELECT email, response_status, 'exception'+ FROM calendar_event_override_attendees WHERE event_id = $1+ ORDER BY 3 DESC, 1+ "#,+ event_id,+ )+ .fetch_all(&pool)+ .await+ .unwrap()+ .into_iter()+ .map(|row| (row.scope, row.email.unwrap(), row.response_status.unwrap()))+ .collect::<Vec<_>>();+ let expected = |scope: &str| {+ [+ (+ scope.to_string(),+ "[email protected]".to_string(),+ "needs_action".to_string(),+ ),+ (+ scope.to_string(),+ "[email protected]".to_string(),+ "accepted".to_string(),+ ),+ ]+ };+ assert_eq!(rows, [expected("series"), expected("exception")].concat());+ let payload = sqlx::query_scalar!(+ "SELECT normalized_payload FROM calendar_event_sources WHERE event_id = $1",+ event_id,+ )+ .fetch_one(&pool)+ .await+ .unwrap();+ for attendees in [+ &payload["event"]["attendees"],+ &payload["overrides"][0]["attendees"],+ ] {+ assert_eq!(+ attendees+ .as_array()+ .unwrap()+ .iter()+ .map(|attendee| attendee["responseStatus"].as_str().unwrap())+ .collect::<Vec<_>>(),+ ["accepted", "needs_action"],+ "the projection a restore would replay agrees: {attendees}"+ );+ }+ let logged = sqlx::query!(+ "SELECT seq, kind, event_id FROM calendar_change_log WHERE link_id = $1 AND seq > $2",+ link,+ before,+ )+ .fetch_all(&pool)+ .await+ .unwrap()+ .into_iter()+ .map(|row| (row.seq, row.kind, row.event_id))+ .collect::<Vec<_>>();+ assert_eq!(logged, [(before + 1, 1, Some(event_id))]);++ sqlx::raw_sql(OUTLOOK_ORGANIZERS_HOLD_THEIR_MEETINGS)+ .execute(&pool)+ .await+ .unwrap();+ assert_eq!(+ counter().await,+ before + 1,+ "a rerun finds nothing left to fix"+ );+}diff --git a/crates/email_api_client/src/outbound/outlook/calendar/normalize.rs b/crates/email_api_client/src/outbound/outlook/calendar/normalize.rsindex 56e5221650..d755cb119f 100644--- a/crates/email_api_client/src/outbound/outlook/calendar/normalize.rs+++ b/crates/email_api_client/src/outbound/outlook/calendar/normalize.rs@@ -102,11 +102,22 @@ fn attendees(value: &Value) -> Vec<CalendarAttendee> {.flatten().filter_map(|v| {let address = v["emailAddress"]["address"].as_str()?;+ let is_organizer = organizer.is_some_and(|o| o.eq_ignore_ascii_case(address));+ // Graph lists a meeting's organizer as an attendee who has not+ // answered ("none"), as when Macro creates the event. They hold+ // the meeting, as the row added below for an unlisted organizer+ // and Google's organizer row say.+ let response_status = match v["status"]["response"].as_str() {+ None | Some("none" | "notResponded") if is_organizer => {+ AttendeeResponseStatus::Accepted+ }+ status => response(status),+ };Some(CalendarAttendee {email: address.to_ascii_lowercase(),display_name: v["emailAddress"]["name"].as_str().map(str::to_owned),- response_status: response(v["status"]["response"].as_str()),- is_organizer: organizer.is_some_and(|o| o.eq_ignore_ascii_case(address)),+ response_status,+ is_organizer,is_optional: v["type"].as_str() == Some("optional"),is_self: false,comment: None,diff --git a/crates/email_api_client/src/outbound/outlook/calendar/test.rs b/crates/email_api_client/src/outbound/outlook/calendar/test.rsindex 1b09ad901b..ee058a1197 100644--- a/crates/email_api_client/src/outbound/outlook/calendar/test.rs+++ b/crates/email_api_client/src/outbound/outlook/calendar/test.rs@@ -416,6 +416,47 @@ fn custom_zones_do_not_poison_timed_calendar_pages_and_sequence_tracks_invitatio);}+#[test]+fn the_organizer_of_a_created_event_holds_it_while_guests_have_not_answered() {+ let mut value = event("created");+ value["organizer"] = json!({"emailAddress":{"address":"[email protected]","name":"Owner"}});+ value["attendees"] = json!([+ {+ "emailAddress":{"address":"[email protected]","name":"Owner"},+ "type":"required",+ "status":{"response":"none","time":"0001-01-01T00:00:00Z"}+ },+ {+ "emailAddress":{"address":"[email protected]","name":"Ada"},+ "type":"required",+ "status":{"response":"none","time":"0001-01-01T00:00:00Z"}+ }+ ]);++ let projection = normalize::projection(&target(), value, vec![]).unwrap();++ assert_eq!(+ projection+ .event+ .attendees+ .iter()+ .map(|attendee| (+ attendee.email.as_str(),+ attendee.is_organizer,+ attendee.response_status+ ))+ .collect::<Vec<_>>(),+ [+ ("[email protected]", true, AttendeeResponseStatus::Accepted),+ (+ "[email protected]",+ false,+ AttendeeResponseStatus::NeedsAction+ ),+ ]+ );+}+#[test]fn until_before_the_daily_start_excludes_that_whole_date() {let time = EventTime::Timed {diff --git a/crates/macro_db_client/migrations/20261026191007_outlook_organizers_hold_their_meetings.sql b/crates/macro_db_client/migrations/20261026191007_outlook_organizers_hold_their_meetings.sqlnew file mode 100644index 0000000000..1a876d6aed--- /dev/null+++ b/crates/macro_db_client/migrations/20261026191007_outlook_organizers_hold_their_meetings.sql@@ -0,0 +1,149 @@+-- no-transaction++-- Microsoft Graph lists a meeting's organizer as an attendee who has not+-- answered, so every Outlook event stored before October 2026 holds its+-- organizer's row as needs_action, and Macro asked the organizer whether they+-- were going to their own meeting. Sync now stores that row as accepted, but+-- Graph's delta resends only events that changed, so rewrite the stored rows+-- the same way: the entity's and its occurrences' attendees, and every Outlook+-- copy's stored projection a restore would replay. Each event's inbox logs an+-- upsert so calendar caches refetch it. One read finds the events, then each+-- event commits on its own, locking what a calendar write to it locks: its+-- rows, then its inbox's change counter last. A rerun rewrites nothing twice+-- and logs only events still to fix.+-- Keep this file a single statement: COMMIT inside DO needs a top-level call.+DO $$+DECLARE+ link_ids uuid[];+ event_ids uuid[];+ fixing uuid;+ last_seq bigint;+BEGIN+ SELECT COALESCE(array_agg(event.source_link_id ORDER BY event.source_link_id, event.id), '{}'),+ COALESCE(array_agg(event.id ORDER BY event.source_link_id, event.id), '{}')+ INTO link_ids, event_ids+ FROM calendar_events event+ WHERE event.canonical_source_kind = 'outlook'+ AND (+ EXISTS (+ SELECT 1 FROM calendar_event_attendees attendee+ WHERE attendee.event_id = event.id+ AND attendee.is_organizer+ AND attendee.response_status = 'needs_action'+ )+ OR EXISTS (+ SELECT 1 FROM calendar_event_override_attendees attendee+ WHERE attendee.event_id = event.id+ AND attendee.is_organizer+ AND attendee.response_status = 'needs_action'+ )+ OR EXISTS (+ SELECT 1 FROM calendar_event_sources source+ WHERE source.event_id = event.id+ AND source.source_kind = 'outlook'+ AND source.normalized_payload -> 'event' -> 'attendees'+ @> '[{"isOrganizer": true, "responseStatus": "needs_action"}]'+ )+ OR EXISTS (+ SELECT 1 FROM calendar_event_sources source+ WHERE source.event_id = event.id+ AND source.source_kind = 'outlook'+ AND jsonb_typeof(source.normalized_payload -> 'overrides') = 'array'+ AND jsonb_path_exists(+ source.normalized_payload,+ '$.overrides[*].attendees[*] ? (@.isOrganizer == true && @.responseStatus == "needs_action")'+ )+ )+ );+ COMMIT;++ FOR nth IN 1 .. cardinality(event_ids) LOOP+ fixing := event_ids[nth];++ UPDATE calendar_event_attendees attendee+ SET response_status = 'accepted'+ WHERE attendee.event_id = fixing+ AND attendee.is_organizer+ AND attendee.response_status = 'needs_action';+ UPDATE calendar_event_override_attendees attendee+ SET response_status = 'accepted'+ WHERE attendee.event_id = fixing+ AND attendee.is_organizer+ AND attendee.response_status = 'needs_action';+ UPDATE calendar_event_sources source+ SET normalized_payload = jsonb_set(+ source.normalized_payload,+ '{event,attendees}',+ (+ SELECT jsonb_agg(+ CASE+ WHEN listed.attendee @> '{"isOrganizer": true, "responseStatus": "needs_action"}'+ THEN listed.attendee || '{"responseStatus": "accepted"}'+ ELSE listed.attendee+ END+ ORDER BY listed.position+ )+ FROM jsonb_array_elements(source.normalized_payload -> 'event' -> 'attendees')+ WITH ORDINALITY AS listed(attendee, position)+ )+ )+ WHERE source.event_id = fixing+ AND source.source_kind = 'outlook'+ AND source.normalized_payload -> 'event' -> 'attendees'+ @> '[{"isOrganizer": true, "responseStatus": "needs_action"}]';+ UPDATE calendar_event_sources source+ SET normalized_payload = jsonb_set(+ source.normalized_payload,+ '{overrides}',+ (+ SELECT jsonb_agg(+ CASE+ WHEN jsonb_typeof(exception.body -> 'attendees') = 'array' THEN jsonb_set(+ exception.body,+ '{attendees}',+ (+ SELECT COALESCE(+ jsonb_agg(+ CASE+ WHEN listed.attendee @> '{"isOrganizer": true, "responseStatus": "needs_action"}'+ THEN listed.attendee || '{"responseStatus": "accepted"}'+ ELSE listed.attendee+ END+ ORDER BY listed.position+ ),+ '[]'::jsonb+ )+ FROM jsonb_array_elements(exception.body -> 'attendees')+ WITH ORDINALITY AS listed(attendee, position)+ )+ )+ ELSE exception.body+ END+ ORDER BY exception.position+ )+ FROM jsonb_array_elements(source.normalized_payload -> 'overrides')+ WITH ORDINALITY AS exception(body, position)+ )+ )+ WHERE source.event_id = fixing+ AND source.source_kind = 'outlook'+ AND jsonb_typeof(source.normalized_payload -> 'overrides') = 'array'+ AND jsonb_path_exists(+ source.normalized_payload,+ '$.overrides[*].attendees[*] ? (@.isOrganizer == true && @.responseStatus == "needs_action")'+ );++ INSERT INTO calendar_change_counters (link_id, seq)+ VALUES (link_ids[nth], 1)+ ON CONFLICT (link_id) DO UPDATE+ SET seq = calendar_change_counters.seq + 1,+ updated_at = now()+ RETURNING seq INTO last_seq;+ INSERT INTO calendar_change_log (link_id, seq, kind, event_id)+ VALUES (link_ids[nth], last_seq, 1, fixing);+ COMMIT;+ END LOOP;++ RAISE NOTICE 'marked the organizers of % Outlook events as holding them',+ cardinality(event_ids);+END $$;diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex 96779a7845..3cce03e2bc 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -580,7 +580,9 @@ tell them apart by calendar color), and each copy answers only for its own inboxguest copy stays a guest copy, marked `(you)` on that inbox's row alone, even whenanother connected inbox organizes the event. An Outlook guest copy never offers `Addguests` (Outlook lets only the organizer change a meeting) and shows the same-explanation; an Outlook organizer adds guests like a Google one.+explanation; an Outlook organizer adds guests like a Google one. The organizer's row on an+Outlook event shows `Accepted` and `Going?` has `Yes` pressed, as on Google, although+Microsoft lists the organizer as not having answered.A guest the organizer does not let modify the event (`viewerCan.editDetails` false while`viewerCan.rsvp` is true) opens an editor whose date/time, all-day, title, description,repeat, conferencing and location controls are disabled, each with the tooltip `Only the