Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): keep an edit through the organizer's copy until Google carries it to the invitation (#8854)

gbirman3570dad048b1
diff --git a/.sqlx/query-1f31de67de85f367d32a920725f87d7fd989f758e63107b4aafd9a2bcc97a87c.json b/.sqlx/query-1f31de67de85f367d32a920725f87d7fd989f758e63107b4aafd9a2bcc97a87c.json
new file mode 100644
index 0000000000..0ac3a275be
--- /dev/null
+++ b/.sqlx/query-1f31de67de85f367d32a920725f87d7fd989f758e63107b4aafd9a2bcc97a87c.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "SELECT content_updated_at FROM calendar_events WHERE id = $1",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "content_updated_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ true
+ ]
+ },
+ "hash": "1f31de67de85f367d32a920725f87d7fd989f758e63107b4aafd9a2bcc97a87c"
+}
diff --git a/.sqlx/query-9cf4fa61648a752ae37a6efbc6ded75464d023236f4eb55d658a1c910e98f467.json b/.sqlx/query-8f9c0f8f96a13eb9359f3d138afff1d55b4ade3672cd91c6cf915fba01351aa8.json
similarity index 53%
rename from .sqlx/query-9cf4fa61648a752ae37a6efbc6ded75464d023236f4eb55d658a1c910e98f467.json
rename to .sqlx/query-8f9c0f8f96a13eb9359f3d138afff1d55b4ade3672cd91c6cf915fba01351aa8.json
index 19be140c5b..8e01b337f9 100644
--- a/.sqlx/query-9cf4fa61648a752ae37a6efbc6ded75464d023236f4eb55d658a1c910e98f467.json
+++ b/.sqlx/query-8f9c0f8f96a13eb9359f3d138afff1d55b4ade3672cd91c6cf915fba01351aa8.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT source.id, source.calendar_id AS \"calendar_id!\"\n FROM calendar_event_sources source\n WHERE source.id = calendar_event_canonical_source_id($1)\n ",
+ "query": "\n SELECT source.id, source.calendar_id AS \"calendar_id!\", source.source_updated_at\n FROM calendar_event_sources source\n WHERE source.id = calendar_event_canonical_source_id($1)\n ",
"describe": {
"columns": [
{
@@ -12,6 +12,11 @@
"ordinal": 1,
"name": "calendar_id!",
"type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "source_updated_at",
+ "type_info": "Timestamptz"
}
],
"parameters": {
@@ -21,8 +26,9 @@
},
"nullable": [
false,
- true
+ true,
+ false
]
},
- "hash": "9cf4fa61648a752ae37a6efbc6ded75464d023236f4eb55d658a1c910e98f467"
+ "hash": "8f9c0f8f96a13eb9359f3d138afff1d55b4ade3672cd91c6cf915fba01351aa8"
}
diff --git a/.sqlx/query-9ec1148c97987fb75e99f5b987f2c91ed108eed79d4941673cf04ee314b7a393.json b/.sqlx/query-9ec1148c97987fb75e99f5b987f2c91ed108eed79d4941673cf04ee314b7a393.json
new file mode 100644
index 0000000000..b8a7bc0612
--- /dev/null
+++ b/.sqlx/query-9ec1148c97987fb75e99f5b987f2c91ed108eed79d4941673cf04ee314b7a393.json
@@ -0,0 +1,19 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE calendar_events\n SET title = $2,\n description = $3,\n location = $4,\n visibility = $5,\n content_updated_at = $6,\n updated_at = GREATEST(calendar_events.updated_at, $6)\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Timestamptz"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "9ec1148c97987fb75e99f5b987f2c91ed108eed79d4941673cf04ee314b7a393"
+}
diff --git a/.sqlx/query-b36c119013aeae33ffcc6a71d8900b07604ade59b1f59fc8d5c30b1ef5fd25a3.json b/.sqlx/query-b36c119013aeae33ffcc6a71d8900b07604ade59b1f59fc8d5c30b1ef5fd25a3.json
deleted file mode 100644
index 96e89cad0a..0000000000
--- a/.sqlx/query-b36c119013aeae33ffcc6a71d8900b07604ade59b1f59fc8d5c30b1ef5fd25a3.json
+++ /dev/null
@@ -1,94 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n source.event_id,\n source.calendar_id AS \"calendar_id!\",\n source.title,\n source.description,\n source.location,\n source.event_type,\n source.visibility,\n source.transparency,\n source.is_read_only,\n source.reminders_use_default,\n source.reminder_overrides,\n source.creator_email,\n source.creator_name\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 = ANY($1)\n AND NOT calendar.is_deleted\n AND account.sync_status <> 'disabled'\n ORDER BY\n source.event_id,\n calendar.is_primary DESC,\n (calendar.access_role IN ('owner', 'writer')) DESC NULLS LAST,\n source.source_sequence DESC,\n source.source_updated_at DESC,\n source.id DESC\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "event_id",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "calendar_id!",
- "type_info": "Uuid"
- },
- {
- "ordinal": 2,
- "name": "title",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "description",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "location",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "event_type",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "visibility",
- "type_info": "Text"
- },
- {
- "ordinal": 7,
- "name": "transparency",
- "type_info": "Text"
- },
- {
- "ordinal": 8,
- "name": "is_read_only",
- "type_info": "Bool"
- },
- {
- "ordinal": 9,
- "name": "reminders_use_default",
- "type_info": "Bool"
- },
- {
- "ordinal": 10,
- "name": "reminder_overrides",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 11,
- "name": "creator_email",
- "type_info": "Text"
- },
- {
- "ordinal": 12,
- "name": "creator_name",
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Left": [
- "UuidArray"
- ]
- },
- "nullable": [
- false,
- true,
- false,
- true,
- true,
- false,
- false,
- false,
- false,
- false,
- false,
- true,
- true
- ]
- },
- "hash": "b36c119013aeae33ffcc6a71d8900b07604ade59b1f59fc8d5c30b1ef5fd25a3"
-}
diff --git a/.sqlx/query-bcf6ec578621b7502055b023c6312a4073c30a4a4e91bc050dc46d2bd47a2c87.json b/.sqlx/query-bcf6ec578621b7502055b023c6312a4073c30a4a4e91bc050dc46d2bd47a2c87.json
new file mode 100644
index 0000000000..37c39424a4
--- /dev/null
+++ b/.sqlx/query-bcf6ec578621b7502055b023c6312a4073c30a4a4e91bc050dc46d2bd47a2c87.json
@@ -0,0 +1,23 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT EXISTS (\n SELECT 1\n FROM calendar_event_sources source\n JOIN calendars calendar\n ON calendar.id = source.calendar_id AND calendar.account_id = source.account_id\n WHERE source.id = $1\n AND source.source_kind = 'google'\n AND NOT calendar.is_deleted\n AND calendar.access_role IN ('owner', 'writer')\n AND lower(calendar.provider_calendar_id) = lower($2)\n ) AS \"organizes!\"\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "organizes!",
+ "type_info": "Bool"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text"
+ ]
+ },
+ "nullable": [
+ null
+ ]
+ },
+ "hash": "bcf6ec578621b7502055b023c6312a4073c30a4a4e91bc050dc46d2bd47a2c87"
+}
diff --git a/.sqlx/query-cf092844dd9549bef761a4e47609b3cd5b166047fd7cab43dcad0cc9b536097e.json b/.sqlx/query-cf092844dd9549bef761a4e47609b3cd5b166047fd7cab43dcad0cc9b536097e.json
new file mode 100644
index 0000000000..6a14288741
--- /dev/null
+++ b/.sqlx/query-cf092844dd9549bef761a4e47609b3cd5b166047fd7cab43dcad0cc9b536097e.json
@@ -0,0 +1,35 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE calendar_events\n SET content_source_id = $17,\n title = CASE WHEN $22 THEN $2 ELSE title END,\n description = CASE WHEN $22 THEN $3 ELSE description END,\n location = CASE WHEN $22 THEN $4 ELSE location END,\n visibility = CASE WHEN $22 THEN $5 ELSE visibility END,\n content_updated_at = CASE WHEN $22 THEN NULL ELSE content_updated_at END,\n transparency = $6,\n event_type = $7,\n creator_email = $8,\n creator_name = $9,\n sequence = $10,\n is_read_only = $11,\n canonical_source_kind = $12,\n reminders_use_default = $13,\n reminder_overrides = $14,\n guests_can_modify = $18,\n guests_can_invite_others = $19,\n guests_can_see_other_guests = $20,\n is_snapshot = $21,\n created_at = $15,\n updated_at = GREATEST(calendar_events.updated_at, $16)\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Text",
+ "Int4",
+ "Bool",
+ "Text",
+ "Bool",
+ "Jsonb",
+ "Timestamptz",
+ "Timestamptz",
+ "Uuid",
+ "Bool",
+ "Bool",
+ "Bool",
+ "Bool",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "cf092844dd9549bef761a4e47609b3cd5b166047fd7cab43dcad0cc9b536097e"
+}
diff --git a/.sqlx/query-d6628ccd51d8ea650b8236fde30efc7ded53259dc388232b83a12150cdf7b819.json b/.sqlx/query-d6628ccd51d8ea650b8236fde30efc7ded53259dc388232b83a12150cdf7b819.json
deleted file mode 100644
index 38bd623f67..0000000000
--- a/.sqlx/query-d6628ccd51d8ea650b8236fde30efc7ded53259dc388232b83a12150cdf7b819.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n UPDATE calendar_events\n SET content_source_id = $17,\n title = $2,\n description = $3,\n location = $4,\n visibility = $5,\n transparency = $6,\n event_type = $7,\n creator_email = $8,\n creator_name = $9,\n sequence = $10,\n is_read_only = $11,\n canonical_source_kind = $12,\n reminders_use_default = $13,\n reminder_overrides = $14,\n guests_can_modify = $18,\n guests_can_invite_others = $19,\n guests_can_see_other_guests = $20,\n is_snapshot = $21,\n created_at = $15,\n updated_at = GREATEST(calendar_events.updated_at, $16)\n WHERE id = $1\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- "Text",
- "Text",
- "Text",
- "Text",
- "Text",
- "Text",
- "Text",
- "Text",
- "Int4",
- "Bool",
- "Text",
- "Bool",
- "Jsonb",
- "Timestamptz",
- "Timestamptz",
- "Uuid",
- "Bool",
- "Bool",
- "Bool",
- "Bool"
- ]
- },
- "nullable": []
- },
- "hash": "d6628ccd51d8ea650b8236fde30efc7ded53259dc388232b83a12150cdf7b819"
-}
diff --git a/.sqlx/query-ef042963b65b41dcbca15877481f372288c733fde78133298dcf5030a49771a5.json b/.sqlx/query-ef042963b65b41dcbca15877481f372288c733fde78133298dcf5030a49771a5.json
new file mode 100644
index 0000000000..12d7119912
--- /dev/null
+++ b/.sqlx/query-ef042963b65b41dcbca15877481f372288c733fde78133298dcf5030a49771a5.json
@@ -0,0 +1,94 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n source.event_id,\n source.calendar_id AS \"calendar_id!\",\n CASE WHEN ahead.id IS NULL THEN source.title ELSE ahead.title END AS \"title!\",\n CASE WHEN ahead.id IS NULL THEN source.description ELSE ahead.description END\n AS description,\n CASE WHEN ahead.id IS NULL THEN source.location ELSE ahead.location END\n AS location,\n source.event_type,\n CASE WHEN ahead.id IS NULL THEN source.visibility ELSE ahead.visibility END\n AS \"visibility!\",\n source.transparency,\n source.is_read_only,\n source.reminders_use_default,\n source.reminder_overrides,\n source.creator_email,\n source.creator_name\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 LEFT JOIN calendar_events ahead\n ON ahead.id = source.event_id\n AND source.source_updated_at < ahead.content_updated_at\n WHERE source.event_id = ANY($1)\n AND NOT calendar.is_deleted\n AND account.sync_status <> 'disabled'\n ORDER BY\n source.event_id,\n calendar.is_primary DESC,\n (calendar.access_role IN ('owner', 'writer')) DESC NULLS LAST,\n source.source_sequence DESC,\n source.source_updated_at DESC,\n source.id DESC\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "event_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "calendar_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "title!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "description",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "location",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "event_type",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "visibility!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "transparency",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "is_read_only",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 9,
+ "name": "reminders_use_default",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 10,
+ "name": "reminder_overrides",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 11,
+ "name": "creator_email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 12,
+ "name": "creator_name",
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ false,
+ true,
+ null,
+ null,
+ null,
+ false,
+ null,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true
+ ]
+ },
+ "hash": "ef042963b65b41dcbca15877481f372288c733fde78133298dcf5030a49771a5"
+}
diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.md
index 7c9ab3dcc7..33f162d3e5 100644
--- a/crates/calendar_events/AGENTS.md
+++ b/crates/calendar_events/AGENTS.md
@@ -177,11 +177,21 @@ reminder dispatch, team availability, and provider/Postgres persistence.
through the copy on the organizer's calendar
(`CalendarEventMutationTarget::organizer_copy_calendar_id`,
`src/domain/mutations/organizer_copy.rs`), then the addressed copy is read
- back (`CalendarMutationProvider::refresh_event`) so the entity shows the
- change before sync; reminders, availability and answers stay on the
- addressed copy. A new event lists the inbox as an accepted guest on its
- primary calendar and on Outlook, but on another Google calendar only when it
- has other guests, as Google's own client does, so a solo event is one block.
+ back (`CalendarMutationProvider::refresh_event`); reminders, availability
+ and answers stay on the addressed copy, written before the organizer's
+ copy. Google carries the change to the invitation 15 to 30 seconds later,
+ so the read-back is usually stale: the response takes the meeting from the
+ organizer copy's echo, and the Postgres upsert lets a user edit through the
+ organizer's copy write the meeting's title, description, location and
+ visibility (stamped in `calendar_events.content_updated_at`) and its whole
+ schedule, guests included. The canonical copy retakes that content only
+ once it is at least as fresh, and until then `fetch_source_contents` serves
+ every older copy with it, since the web shows a copy's own title. Only a
+ user edit starts this; a sync of the organizer's copy leaves content to the
+ canonical copy as before. A new event lists the inbox as an accepted guest
+ on its primary calendar and on Outlook, but on another Google calendar only
+ when it has other guests, as Google's own client does, so a solo event is
+ one block.
- `viewer_can` is viewer-relative, like an attendee's `is_self`: resolve it with
`ActorInboxes::mark_event` and the copy's source link wherever a read path
marks the viewer, and never store it. Calendar caches refresh only the
diff --git a/crates/calendar_events/src/domain/mutations/organizer_copy.rs b/crates/calendar_events/src/domain/mutations/organizer_copy.rs
index 37631c3215..f9365ce3a1 100644
--- a/crates/calendar_events/src/domain/mutations/organizer_copy.rs
+++ b/crates/calendar_events/src/domain/mutations/organizer_copy.rs
@@ -5,7 +5,10 @@
//! primary calendar, one entity whose canonical copy is the invitation. Only
//! the organizer's copy takes the organizer's changes, as in Google's own
//! client, so those changes go through it, and the addressed copy is then
-//! read back so the entity shows them without waiting for sync.
+//! read back so the entity shows them without waiting for sync. Google
+//! carries them to the addressed copy some seconds later, so until then the
+//! response shows the meeting as the organizer's copy has it, as the stored
+//! entity does.
use super::*;
impl<R, G, T, B, N> CalendarMutationServiceImpl<R, G, T, B, N>
@@ -16,9 +19,11 @@ where
B: MacroEventBroker,
N: CalendarRefreshNotifier,
{
- /// Apply the meeting's changes through the organizer's copy, then what
- /// the provider keeps on each copy (reminders, availability) to the
- /// addressed copy, whose echo also brings the meeting's changes back.
+ /// Apply what the provider keeps on each copy (reminders, availability)
+ /// to the addressed copy, then the meeting's changes through the
+ /// organizer's copy. In that order the organizer's write is the fresher
+ /// one, so the addressed copy's echo, which Google has yet to update,
+ /// cannot take the meeting's content back.
#[tracing::instrument(
name = "calendar.update_through_organizer_copy",
skip(self, requester_id, target, patch, scope),
@@ -46,14 +51,20 @@ where
let organizer_copy = self
.resolve_mutation_target(requester_id, target.event_id, Some(organizer_calendar_id))
.await?;
- let organized = self
- .update_copy(requester_id, organizer_copy, patch, scope.clone())
- .await?;
if own.is_empty() {
+ let organized = self
+ .update_copy(requester_id, organizer_copy, patch, scope.clone())
+ .await?;
return Ok(self.read_back(&target, &scope, organized).await);
}
+ let addressed = self
+ .update_copy(requester_id, target.clone(), own, scope.clone())
+ .await?;
+ let organized = self
+ .update_copy(requester_id, organizer_copy, patch, scope)
+ .await?;
tracing::Span::current().record("read_back", "own_fields");
- self.update_copy(requester_id, target, own, scope).await
+ Ok(with_meeting_of(&target, addressed, &organized))
}
/// Add guests through the organizer's copy, then read the addressed
@@ -161,7 +172,7 @@ where
match refreshed {
Ok(event) => {
tracing::Span::current().record("read_back", "refreshed");
- event
+ with_meeting_of(target, event, &written)
}
Err(error) => {
tracing::warn!(error = ?error, "failed to read the copy back after a write");
@@ -186,3 +197,36 @@ where
.map_err(provider_error)
}
}
+
+/// The addressed copy's echo as Google will show it once it carries the
+/// organizer's write: a copy older than that write takes the meeting's
+/// content, schedule, and guests from the organizer copy's echo and keeps its
+/// own reminders, availability, and access, then the viewer is marked again
+/// against the guests it now lists.
+fn with_meeting_of(
+ target: &CalendarEventMutationTarget,
+ mut addressed: CalendarEvent,
+ organized: &CalendarEvent,
+) -> CalendarEvent {
+ if addressed.updated_at >= organized.updated_at {
+ return addressed;
+ }
+ addressed.title = organized.title.clone();
+ addressed.description = organized.description.clone();
+ addressed.location = organized.location.clone();
+ addressed.visibility = organized.visibility;
+ addressed.status = organized.status;
+ addressed.time = organized.time.clone();
+ addressed.recurrence_lines = organized.recurrence_lines.clone();
+ addressed.organizer_email = organized.organizer_email.clone();
+ addressed.organizer_name = organized.organizer_name.clone();
+ addressed.conference_url = organized.conference_url.clone();
+ addressed.conference_provider = organized.conference_provider;
+ addressed.attendees = organized.attendees.clone();
+ addressed.guest_policy = organized.guest_policy;
+ addressed.updated_at = organized.updated_at;
+ if let Some(viewer) = &target.actor {
+ viewer.mark_event(&mut addressed, target.email_link_id);
+ }
+ addressed
+}
diff --git a/crates/calendar_events/src/domain/mutations/test.rs b/crates/calendar_events/src/domain/mutations/test.rs
index ac0fe37791..c374bec2e2 100644
--- a/crates/calendar_events/src/domain/mutations/test.rs
+++ b/crates/calendar_events/src/domain/mutations/test.rs
@@ -638,6 +638,9 @@ struct FakeProvider {
invited_as: Arc<Mutex<Vec<Vec<String>>>>,
/// Whether reading a copy back finds it gone.
refresh_gone: bool,
+ /// The title a copy read back still has because Google has yet to carry
+ /// the write to it, with a provider stamp older than the write's.
+ refresh_stale: Option<&'static str>,
}
impl FakeProvider {
@@ -655,6 +658,7 @@ impl FakeProvider {
imported: Arc::new(Mutex::new(Vec::new())),
invited_as: Arc::new(Mutex::new(Vec::new())),
refresh_gone: false,
+ refresh_stale: None,
}
}
@@ -756,7 +760,13 @@ impl CalendarMutationProvider for FakeProvider {
if self.refresh_gone {
return Ok(None);
}
- Ok(Some(self.echo(target)))
+ let mut copy = self.echo(target);
+ if let Some(title) = self.refresh_stale {
+ copy.event.title = title.to_string();
+ copy.event.attendees = Vec::new();
+ copy.event.updated_at -= Duration::hours(1);
+ }
+ Ok(Some(copy))
}
async fn delete_event(
diff --git a/crates/calendar_events/src/domain/mutations/test/organizer_copy.rs b/crates/calendar_events/src/domain/mutations/test/organizer_copy.rs
index 48c92d5010..f032ae1a4e 100644
--- a/crates/calendar_events/src/domain/mutations/test/organizer_copy.rs
+++ b/crates/calendar_events/src/domain/mutations/test/organizer_copy.rs
@@ -101,6 +101,45 @@ async fn a_title_change_goes_through_the_organizer_copy_and_reads_the_invitation
);
}
+#[tokio::test]
+async fn a_title_change_shows_before_google_carries_it_to_the_invitation() {
+ let repo = repo();
+ let mut provider = FakeProvider::new(FakeProviderBehavior::Echo);
+ provider.echo_attendees = vec![
+ echo_attendee("[email protected]", false),
+ echo_attendee("[email protected]", false),
+ ];
+ provider.refresh_stale = Some("Before");
+
+ let event = service(repo, provider, FakeTokens::ok())
+ .update_event(
+ "macro|user",
+ Uuid::now_v7(),
+ Some(INVITATION_CALENDAR),
+ CalendarEventPatch {
+ title: Some("Echo".to_string()),
+ ..CalendarEventPatch::default()
+ },
+ CalendarUpdateScope::All,
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(
+ event.title, "Echo",
+ "the organizer copy's title, not the stale invitation's"
+ );
+ assert_eq!(
+ event
+ .attendees
+ .iter()
+ .map(|attendee| (attendee.email.as_str(), attendee.is_self))
+ .collect::<Vec<_>>(),
+ [("[email protected]", true), ("[email protected]", false)],
+ "the organizer copy's guests, with the viewer marked again"
+ );
+}
+
#[tokio::test]
async fn reminders_saved_with_a_title_stay_on_the_invitation() {
let repo = repo();
@@ -128,22 +167,24 @@ async fn reminders_saved_with_a_title_stay_on_the_invitation() {
calls.lock().unwrap().as_slice(),
["update:master-id", "update:master-id"]
);
+ // The invitation is written first, so the organizer's write is the
+ // fresher one and the invitation's echo cannot take the title back.
assert_eq!(
patches.lock().unwrap().as_slice(),
[
CalendarEventPatch {
- title: Some("Renamed".to_string()),
+ reminders: Some(reminders()),
..CalendarEventPatch::default()
},
CalendarEventPatch {
- reminders: Some(reminders()),
+ title: Some("Renamed".to_string()),
..CalendarEventPatch::default()
},
]
);
assert_eq!(
written_calendars(&upserts),
- [ORGANIZER_CALENDAR, INVITATION_CALENDAR]
+ [INVITATION_CALENDAR, ORGANIZER_CALENDAR]
);
}
@@ -204,6 +245,40 @@ async fn guests_are_added_through_the_organizer_copy() {
);
}
+#[tokio::test]
+async fn added_guests_show_before_google_carries_them_to_the_invitation() {
+ let repo = repo();
+ let mut provider = FakeProvider::new(FakeProviderBehavior::Echo);
+ provider.echo_attendees = vec![
+ echo_attendee("[email protected]", false),
+ echo_attendee("[email protected]", false),
+ ];
+ provider.refresh_stale = Some("Echo");
+
+ let event = service(repo, provider, FakeTokens::ok())
+ .invite_guests(
+ "macro|user",
+ Uuid::now_v7(),
+ Some(INVITATION_CALENDAR),
+ vec![CalendarAttendeeInput {
+ email: "[email protected]".to_string(),
+ is_optional: false,
+ response_status: None,
+ }],
+ CalendarUpdateScope::All,
+ )
+ .await
+ .unwrap();
+
+ assert!(
+ event
+ .attendees
+ .iter()
+ .any(|attendee| attendee.email == "[email protected]"),
+ "the new guest shows although the invitation read back lacks them"
+ );
+}
+
#[tokio::test]
async fn deleting_cancels_through_the_organizer_copy_and_retires_the_invitation() {
let repo = repo();
diff --git a/crates/calendar_events/src/outbound/pg.rs b/crates/calendar_events/src/outbound/pg.rs
index 1667c2cd05..943f7e9a7f 100644
--- a/crates/calendar_events/src/outbound/pg.rs
+++ b/crates/calendar_events/src/outbound/pg.rs
@@ -798,7 +798,7 @@ impl CalendarRepository for PgCalendarRepository {
}))
}
- #[tracing::instrument(skip(self, write), err)]
+ #[tracing::instrument(skip(self, write), fields(meeting_content = tracing::field::Empty), err)]
async fn upsert_event(
&self,
write: CalendarEventWrite,
@@ -1051,31 +1051,80 @@ impl CalendarRepository for PgCalendarRepository {
source_access::invalidate_account_freshness(&mut tx, source.account_id).await?;
}
- // Content always follows the canonical copy. The schedule follows
- // whichever copy last wrote it: the canonical copy takes it when that
- // copy is new to Macro, advanced its own sequence, or is at least as
- // fresh as the write it replaces, a user edit through another copy
- // lands when it is at least that fresh, and the copy that wrote the
- // schedule keeps writing it until then.
+ // Content follows the canonical copy. The schedule follows whichever
+ // copy last wrote it: the canonical copy takes it when that copy is
+ // new to Macro, advanced its own sequence, or is at least as fresh as
+ // the write it replaces, a user edit through another copy lands when
+ // it is at least that fresh, and the copy that wrote the schedule
+ // keeps writing it until then. The meeting's content (title,
+ // description, location, visibility) follows the same rule for the
+ // organizer's copy: Google applies the organizer's changes to the
+ // invitation on the primary calendar, the usual canonical copy, some
+ // seconds later, so a user edit through the organizer's copy lands at
+ // once, the canonical copy retakes the content once it is at least
+ // that fresh, and the organizer's copy keeps writing it until then.
+ // The organizer's copy holds the meeting's own guests, organizer, and
+ // conference, so the schedule it writes includes them.
let canonical = canonical_source(&mut tx, event_id).await?;
let schedule = schedule_owner(&mut tx, event_id).await?;
let projection = StoredSourceProjection::from(&upsert);
let is_canonical =
canonical.as_ref().map(|canonical| canonical.source_id) == Some(source_id);
+ let is_organizer_copy = !is_canonical
+ && organizes_meeting(&mut tx, source_id, upsert.event.organizer_email.as_deref())
+ .await?;
+ let content_ahead = if is_canonical || is_organizer_copy {
+ content_ahead(&mut tx, event_id).await?
+ } else {
+ None
+ };
+ let takes_meeting_content = if is_canonical {
+ content_ahead.is_none_or(|ahead| upsert.event.updated_at >= ahead)
+ } else if is_organizer_copy && (user_mutation || content_ahead.is_some()) {
+ content_ahead
+ .or(canonical.as_ref().map(|canonical| canonical.updated_at))
+ .is_some_and(|fresh| upsert.event.updated_at >= fresh)
+ } else {
+ false
+ };
+ let meeting_content = match (takes_meeting_content, is_canonical) {
+ (true, false) => Some("organizer_copy"),
+ (true, true) if content_ahead.is_some() => Some("canonical_retook"),
+ (false, _) if content_ahead.is_some() => Some("kept_pending_edit"),
+ _ => None,
+ };
+ if let Some(meeting_content) = meeting_content {
+ tracing::Span::current().record("meeting_content", meeting_content);
+ }
+ // A canonical copy older than a pending edit through the organizer's
+ // copy leaves the schedule to it too, even when new to Macro or
+ // advanced: that edit's guests and time are the newer ones.
let owns_schedule = schedule.source_id == Some(source_id);
let writes_schedule = if is_canonical {
- owns_schedule || copy_advanced || upsert.event.updated_at >= schedule.updated_at
+ takes_meeting_content
+ && (owns_schedule
+ || copy_advanced
+ || upsert.event.updated_at >= schedule.updated_at)
} else if user_mutation {
upsert.event.updated_at >= schedule.updated_at
} else {
owns_schedule
};
if is_canonical {
- apply_content_projection(&mut tx, event_id, source_id, &projection, source_kind)
- .await?;
+ apply_content_projection(
+ &mut tx,
+ event_id,
+ source_id,
+ &projection,
+ source_kind,
+ takes_meeting_content,
+ )
+ .await?;
+ } else if takes_meeting_content {
+ apply_meeting_content(&mut tx, event_id, &projection).await?;
}
if writes_schedule {
- if is_canonical {
+ if is_canonical || is_organizer_copy {
apply_schedule_projection(&mut tx, event_id, source_id, &projection).await?;
} else {
apply_time_projection(&mut tx, event_id, source_id, &projection).await?;
@@ -3664,10 +3713,11 @@ async fn persist_source(
.map_err(report)
}
-/// The copy whose content the entity carries.
+/// The copy whose content the entity carries, and its provider stamp.
struct CanonicalSource {
source_id: Uuid,
calendar_id: Uuid,
+ updated_at: DateTime<Utc>,
}
/// The source whose content the entity carries, ranked by
@@ -3681,7 +3731,7 @@ async fn canonical_source(
) -> Result<Option<CanonicalSource>, Report> {
let row = sqlx::query!(
r#"
- SELECT source.id, source.calendar_id AS "calendar_id!"
+ SELECT source.id, source.calendar_id AS "calendar_id!", source.source_updated_at
FROM calendar_event_sources source
WHERE source.id = calendar_event_canonical_source_id($1)
"#,
@@ -3693,9 +3743,60 @@ async fn canonical_source(
Ok(row.map(|row| CanonicalSource {
source_id: row.id,
calendar_id: row.calendar_id,
+ updated_at: row.source_updated_at,
}))
}
+/// Whether a copy is the organizer's: the Google source on the calendar
+/// Google names as the meeting's organizer (the address for a primary
+/// calendar, the calendar id for a secondary one) that its inbox can write,
+/// as `guest_policy::align_with_organizer` and the mutation target's
+/// `organizer_copy_calendar_id` find it.
+async fn organizes_meeting(
+ tx: &mut Transaction<'_, Postgres>,
+ source_id: Uuid,
+ organizer_email: Option<&str>,
+) -> Result<bool, Report> {
+ let Some(organizer_email) = organizer_email else {
+ return Ok(false);
+ };
+ sqlx::query_scalar!(
+ r#"
+ SELECT EXISTS (
+ SELECT 1
+ FROM calendar_event_sources source
+ JOIN calendars calendar
+ ON calendar.id = source.calendar_id AND calendar.account_id = source.account_id
+ WHERE source.id = $1
+ AND source.source_kind = 'google'
+ AND NOT calendar.is_deleted
+ AND calendar.access_role IN ('owner', 'writer')
+ AND lower(calendar.provider_calendar_id) = lower($2)
+ ) AS "organizes!"
+ "#,
+ source_id,
+ organizer_email,
+ )
+ .fetch_one(&mut **tx)
+ .await
+ .map_err(report)
+}
+
+/// The provider stamp of the user edit through the organizer's copy whose
+/// content the entity carries ahead of its canonical copy, if any.
+async fn content_ahead(
+ tx: &mut Transaction<'_, Postgres>,
+ event_id: Uuid,
+) -> Result<Option<DateTime<Utc>>, Report> {
+ sqlx::query_scalar!(
+ r#"SELECT content_updated_at FROM calendar_events WHERE id = $1"#,
+ event_id,
+ )
+ .fetch_one(&mut **tx)
+ .await
+ .map_err(report)
+}
+
/// The copy that last wrote the entity's schedule and that write's provider
/// stamp. The copy is absent when it has since been retired.
struct ScheduleOwner {
@@ -3721,22 +3822,26 @@ async fn schedule_owner(
}
/// Rewrite the entity's copy-specific content from its canonical copy and
-/// record which copy it now mirrors.
+/// record which copy it now mirrors. The meeting's content (title,
+/// description, location, visibility) comes along only when `meeting` is
+/// set, which hands it back from a fresher edit through the organizer's copy.
async fn apply_content_projection(
tx: &mut Transaction<'_, Postgres>,
event_id: Uuid,
source_id: Uuid,
projection: &StoredSourceProjection,
source_kind: &str,
+ meeting: bool,
) -> Result<(), Report> {
sqlx::query!(
r#"
UPDATE calendar_events
SET content_source_id = $17,
- title = $2,
- description = $3,
- location = $4,
- visibility = $5,
+ title = CASE WHEN $22 THEN $2 ELSE title END,
+ description = CASE WHEN $22 THEN $3 ELSE description END,
+ location = CASE WHEN $22 THEN $4 ELSE location END,
+ visibility = CASE WHEN $22 THEN $5 ELSE visibility END,
+ content_updated_at = CASE WHEN $22 THEN NULL ELSE content_updated_at END,
transparency = $6,
event_type = $7,
creator_email = $8,
@@ -3775,6 +3880,40 @@ async fn apply_content_projection(
projection.event.guest_policy.can_invite_others,
projection.event.guest_policy.can_see_other_guests,
projection.event.is_snapshot,
+ meeting,
+ )
+ .execute(&mut **tx)
+ .await
+ .map_err(report)?;
+ Ok(())
+}
+
+/// Write the meeting's content (title, description, location, visibility)
+/// from a user edit through the organizer's copy, ahead of the canonical copy
+/// Google updates later, and record the edit's provider stamp so only a copy
+/// at least that fresh replaces it.
+async fn apply_meeting_content(
+ tx: &mut Transaction<'_, Postgres>,
+ event_id: Uuid,
+ projection: &StoredSourceProjection,
+) -> Result<(), Report> {
+ sqlx::query!(
+ r#"
+ UPDATE calendar_events
+ SET title = $2,
+ description = $3,
+ location = $4,
+ visibility = $5,
+ content_updated_at = $6,
+ updated_at = GREATEST(calendar_events.updated_at, $6)
+ WHERE id = $1
+ "#,
+ event_id,
+ &projection.event.title,
+ projection.event.description.as_deref(),
+ projection.event.location.as_deref(),
+ projection.event.visibility.as_str(),
+ projection.event.updated_at,
)
.execute(&mut **tx)
.await
@@ -3782,8 +3921,9 @@ async fn apply_content_projection(
Ok(())
}
-/// Rewrite the whole schedule the canonical copy owns: status, time,
-/// recurrence, organizer, conference, attendees, overrides, and occurrences.
+/// Rewrite the whole schedule the canonical copy, or the organizer's copy
+/// after a user edit through it, owns: status, time, recurrence, organizer,
+/// conference, attendees, overrides, and occurrences.
/// Records the copy as the schedule's writer with its provider stamp.
async fn apply_schedule_projection(
tx: &mut Transaction<'_, Postgres>,
@@ -3934,7 +4074,8 @@ async fn rebuild_entity_reminder_firings(
}
/// Rewrite the entity from the copy that inherits it after a retirement.
-/// Content always follows it. The schedule follows it unless another
+/// Content follows it, except the meeting's content from a fresher edit
+/// through the organizer's copy. The schedule follows it unless another
/// surviving copy wrote a fresher one, which is how a user's edit made
/// through a copy outlives the retirement of an unrelated third copy.
async fn apply_canonical_projection(
@@ -3945,7 +4086,10 @@ async fn apply_canonical_projection(
source_kind: &str,
calendar_id: Option<Uuid>,
) -> Result<(), Report> {
- apply_content_projection(tx, event_id, source_id, projection, source_kind).await?;
+ let meeting = content_ahead(tx, event_id)
+ .await?
+ .is_none_or(|ahead| projection.event.updated_at >= ahead);
+ apply_content_projection(tx, event_id, source_id, projection, source_kind, meeting).await?;
let schedule = schedule_owner(tx, event_id).await?;
if schedule.source_id.is_none_or(|owner| owner == source_id)
|| projection.event.updated_at >= schedule.updated_at
@@ -4464,6 +4608,9 @@ async fn rebuild_calendar_reminder_firings(
/// `calendar_event_canonical_source_id` ranks by: the primary calendar's
/// copy, then writable copies, then the freshest. Copies on deleted calendars
/// or disabled accounts are omitted, mirroring what the calendar list shows.
+/// A copy older than a user edit through the organizer's copy that Google has
+/// yet to carry to it reads with the meeting content the entity took from
+/// that edit, as Google will show it.
async fn fetch_source_contents(
pool: &PgPool,
event_ids: &[Uuid],
@@ -4476,11 +4623,14 @@ async fn fetch_source_contents(
SELECT
source.event_id,
source.calendar_id AS "calendar_id!",
- source.title,
- source.description,
- source.location,
+ CASE WHEN ahead.id IS NULL THEN source.title ELSE ahead.title END AS "title!",
+ CASE WHEN ahead.id IS NULL THEN source.description ELSE ahead.description END
+ AS description,
+ CASE WHEN ahead.id IS NULL THEN source.location ELSE ahead.location END
+ AS location,
source.event_type,
- source.visibility,
+ CASE WHEN ahead.id IS NULL THEN source.visibility ELSE ahead.visibility END
+ AS "visibility!",
source.transparency,
source.is_read_only,
source.reminders_use_default,
@@ -4490,6 +4640,9 @@ async fn fetch_source_contents(
FROM calendar_event_sources source
JOIN calendars calendar ON calendar.id = source.calendar_id
JOIN calendar_accounts account ON account.id = source.account_id
+ LEFT JOIN calendar_events ahead
+ ON ahead.id = source.event_id
+ AND source.source_updated_at < ahead.content_updated_at
WHERE source.event_id = ANY($1)
AND NOT calendar.is_deleted
AND account.sync_status <> 'disabled'
diff --git a/crates/calendar_events/src/outbound/pg/test/organizer_calendar.rs b/crates/calendar_events/src/outbound/pg/test/organizer_calendar.rs
index 9a6c8659f7..04d0f8aed3 100644
--- a/crates/calendar_events/src/outbound/pg/test/organizer_calendar.rs
+++ b/crates/calendar_events/src/outbound/pg/test/organizer_calendar.rs
@@ -209,6 +209,242 @@ async fn a_calendar_the_inbox_only_reads_lends_its_copy_nothing(pool: PgPool) {
);
}
+/// An event made on the inbox's secondary calendar: the organizer's copy
+/// there and the invitation Google sends the inbox's primary calendar, one
+/// entity whose canonical copy is the invitation.
+struct SecondaryMeeting {
+ owner_id: &'static str,
+ event_id: Uuid,
+ link_id: Uuid,
+ account_id: Uuid,
+ primary_id: Uuid,
+ secondary_id: Uuid,
+ inbox_email: String,
+}
+
+impl SecondaryMeeting {
+ async fn new(pool: &PgPool, repo: &PgCalendarRepository, owner_id: &'static str) -> Self {
+ let link_id = insert_link(pool, owner_id).await;
+ let inbox_email = link_email(pool, link_id).await;
+ let (account_id, primary_id) = grant_and_provider_ids(repo, link_id).await;
+ let secondary_id = repo
+ .upsert_calendar_fixture(account_id, secondary_calendar(SECONDARY, "owner"))
+ .await
+ .unwrap();
+ let meeting = Self {
+ owner_id,
+ event_id: Uuid::nil(),
+ link_id,
+ account_id,
+ primary_id,
+ secondary_id,
+ inbox_email,
+ };
+ let event_id = repo
+ .upsert_event(CalendarEventWrite::UserMutation(
+ meeting.copy(meeting.secondary_id),
+ ))
+ .await
+ .unwrap()
+ .event_id;
+ repo.upsert_event_fixture(meeting.copy(meeting.primary_id))
+ .await
+ .unwrap();
+ Self {
+ event_id,
+ ..meeting
+ }
+ }
+
+ /// The meeting as the copy on `calendar_id` holds it before any edit.
+ fn copy(&self, calendar_id: Uuid) -> CalendarEventUpsert {
+ copy_of(
+ self.owner_id,
+ self.link_id,
+ (self.account_id, calendar_id),
+ SECONDARY,
+ &self.inbox_email,
+ )
+ }
+
+ /// The copy on `calendar_id` after the organizer renamed the meeting,
+ /// added a guest and wrote an agenda, as Google stamps it `minutes`
+ /// after the meeting was made.
+ fn edited(&self, calendar_id: Uuid, minutes: i64) -> CalendarEventUpsert {
+ let mut copy = self.copy(calendar_id);
+ copy.event.title = "Renamed".to_string();
+ copy.event.description = Some("Agenda".to_string());
+ copy.event.attendees.push(CalendarAttendee {
+ email: "[email protected]".to_string(),
+ display_name: None,
+ response_status: AttendeeResponseStatus::NeedsAction,
+ is_organizer: false,
+ is_optional: false,
+ is_self: false,
+ comment: None,
+ });
+ copy.event.updated_at = copy.event.created_at + Duration::minutes(minutes);
+ copy
+ }
+}
+
+struct MeetingContent {
+ title: String,
+ description: Option<String>,
+ content_updated_at: Option<DateTime<Utc>>,
+ guests: Vec<String>,
+}
+
+async fn meeting_content(pool: &PgPool, event_id: Uuid) -> MeetingContent {
+ sqlx::query_as!(
+ MeetingContent,
+ r#"
+ SELECT event.title, event.description, event.content_updated_at,
+ ARRAY(
+ SELECT attendee.email FROM calendar_event_attendees attendee
+ WHERE attendee.event_id = event.id ORDER BY attendee.email
+ ) AS "guests!"
+ FROM calendar_events event WHERE event.id = $1
+ "#,
+ event_id,
+ )
+ .fetch_one(pool)
+ .await
+ .unwrap()
+}
+
+/// The title each listed copy of the meeting shows, canonical copy first.
+async fn copy_titles(repo: &PgCalendarRepository, meeting: &SecondaryMeeting) -> Vec<String> {
+ let starts_at = Utc.with_ymd_and_hms(2026, 7, 24, 14, 0, 0).unwrap();
+ let range = OccurrenceRange {
+ starts_at: starts_at - Duration::hours(1),
+ ends_at: starts_at + Duration::hours(2),
+ start_date: starts_at.date_naive(),
+ end_date: starts_at.date_naive(),
+ };
+ let rows = repo
+ .list_occurrences(meeting.owner_id, range, None, 10)
+ .await
+ .unwrap();
+ let (event, _) = rows
+ .into_iter()
+ .map(OccurrenceListing::into_occurrence_event)
+ .find(|(event, _)| event.id == meeting.event_id)
+ .expect("the meeting lists");
+ event.sources.into_iter().map(|copy| copy.title).collect()
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn an_edit_through_the_organizers_copy_shows_until_the_invitation_catches_up(pool: PgPool) {
+ let repo = PgCalendarRepository::new(pool.clone());
+ let meeting =
+ SecondaryMeeting::new(&pool, &repo, "macro|[email protected]").await;
+ let edit_stamp = meeting.edited(meeting.secondary_id, 10).event.updated_at;
+
+ repo.upsert_event(CalendarEventWrite::UserMutation(
+ meeting.edited(meeting.secondary_id, 10),
+ ))
+ .await
+ .unwrap();
+
+ let content = meeting_content(&pool, meeting.event_id).await;
+ assert_eq!(content.title, "Renamed");
+ assert_eq!(content.description.as_deref(), Some("Agenda"));
+ assert_eq!(content.content_updated_at, Some(edit_stamp));
+ assert!(content.guests.contains(&"[email protected]".to_string()));
+ assert_eq!(
+ copy_titles(&repo, &meeting).await,
+ ["Renamed", "Renamed"],
+ "the invitation Google has yet to update reads as the organizer's copy"
+ );
+
+ // Before Google carries the edit over, the invitation changes for another
+ // reason, as when its reminders are saved, and still holds the old title
+ // and guests, even with an advanced sequence.
+ let mut stale = meeting.copy(meeting.primary_id);
+ stale.event.sequence += 1;
+ stale.event.reminders = EventReminders {
+ use_default: false,
+ overrides: Vec::new(),
+ };
+ stale.event.updated_at = stale.event.created_at + Duration::minutes(5);
+ repo.upsert_event(CalendarEventWrite::UserMutation(stale))
+ .await
+ .unwrap();
+
+ let content = meeting_content(&pool, meeting.event_id).await;
+ assert_eq!(
+ content.title, "Renamed",
+ "an older invitation cannot take the title back"
+ );
+ assert!(content.guests.contains(&"[email protected]".to_string()));
+ let reminders_use_default = sqlx::query_scalar!(
+ "SELECT reminders_use_default FROM calendar_events WHERE id = $1",
+ meeting.event_id,
+ )
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert!(
+ !reminders_use_default,
+ "the invitation's own reminders still reach the entity"
+ );
+
+ // Google carries the edit to the invitation.
+ let mut caught_up = meeting.edited(meeting.primary_id, 12);
+ caught_up.event.sequence += 1;
+ repo.upsert_event_fixture(caught_up).await.unwrap();
+
+ let content = meeting_content(&pool, meeting.event_id).await;
+ assert_eq!(content.title, "Renamed");
+ assert_eq!(
+ content.content_updated_at, None,
+ "the invitation holds the content again"
+ );
+ assert_eq!(copy_titles(&repo, &meeting).await, ["Renamed", "Renamed"]);
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn the_invitation_retakes_content_a_later_change_reached_first(pool: PgPool) {
+ let repo = PgCalendarRepository::new(pool.clone());
+ let meeting =
+ SecondaryMeeting::new(&pool, &repo, "macro|[email protected]").await;
+ repo.upsert_event(CalendarEventWrite::UserMutation(
+ meeting.edited(meeting.secondary_id, 10),
+ ))
+ .await
+ .unwrap();
+
+ // Someone else's later change reaches the invitation first.
+ let mut later = meeting.edited(meeting.primary_id, 20);
+ later.event.title = "Moved to Thursday".to_string();
+ repo.upsert_event_fixture(later).await.unwrap();
+
+ let content = meeting_content(&pool, meeting.event_id).await;
+ assert_eq!(content.title, "Moved to Thursday");
+ assert_eq!(content.content_updated_at, None);
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn a_sync_of_the_organizers_copy_leaves_content_to_the_invitation(pool: PgPool) {
+ let repo = PgCalendarRepository::new(pool.clone());
+ let meeting =
+ SecondaryMeeting::new(&pool, &repo, "macro|[email protected]").await;
+
+ // A change made outside Macro reaches the organizer's copy by sync.
+ repo.upsert_event_fixture(meeting.edited(meeting.secondary_id, 10))
+ .await
+ .unwrap();
+
+ let content = meeting_content(&pool, meeting.event_id).await;
+ assert_eq!(content.title, "Focus time");
+ assert_eq!(content.content_updated_at, None);
+ assert_eq!(
+ copy_titles(&repo, &meeting).await,
+ ["Focus time", "Renamed"]
+ );
+}
+
/// The migration that logs events organized by a calendar their inbox
/// writes, so caches holding their pre-October-2026 capabilities refetch them.
const LOG_ORGANIZED_EVENTS: &str = include_str!(
diff --git a/crates/macro_db_client/migrations/20261026194846_calendar_events_content_updated_at.sql b/crates/macro_db_client/migrations/20261026194846_calendar_events_content_updated_at.sql
new file mode 100644
index 0000000000..94ab11d28e
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261026194846_calendar_events_content_updated_at.sql
@@ -0,0 +1,9 @@
+-- The provider stamp of a user edit written through the organizer's copy whose
+-- title, description, location, and visibility the entity carries ahead of its
+-- canonical copy, which Google updates some seconds later. The canonical copy
+-- retakes that content once it is at least this fresh, which clears the stamp.
+-- NULL while the entity's content is its canonical copy's. Nullable, so code
+-- deployed before this change keeps working.
+SET LOCAL lock_timeout = '5s';
+
+ALTER TABLE calendar_events ADD COLUMN content_updated_at timestamptz;
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index 3cce03e2bc..890974a2fb 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -635,10 +635,13 @@ every copy. A new event on a calendar other than the primary lists its creator a
when it has other guests, as Google's own client does, so an event of one's own shows as one
block in Google. With guests, Google also invites the creator's primary calendar; Macro shows
both copies as one event, sends the organizer's changes and Delete through the copy on the
-secondary calendar, and keeps reminders and answers on the invitation. To verify, create an
-event on a secondary calendar with no guests and another with a guest, open each (no `Only the
-organizer can change this event.`), change the title, add a guest, then delete it, and check
-Google: the first shows once, and both disappear from every calendar after the delete.
+secondary calendar, and keeps reminders and answers on the invitation. Google takes 15 to 30
+seconds to carry the organizer's changes to that invitation; Macro shows them at once and never
+falls back to the old title, description or guests meanwhile. To verify, create an event on a
+secondary calendar with no guests and another with a guest, open each (no `Only the organizer
+can change this event.`), change the title, add a guest, and watch the chip and details for 40
+seconds (the new values must stay), then delete it, and check Google: the first shows once, and
+both disappear from every calendar after the delete.
The details header's `Download .ics` icon button, beside `Copy event`, saves the event as an
iCalendar file named after its title, so it can be passed on or added to another calendar. The
file holds the series (its repeat rule, in the event's original time zone), title, description