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): normalize imported all-day date ranges (#8917)
gbirman2bbfaa759d17
diff --git a/Cargo.lock b/Cargo.lockindex 8e3021b6d2..cc30803203 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3814,6 +3814,7 @@ dependencies = ["urlencoding","utoipa","uuid",+ "wiremock","workspace-hack",]diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.mdindex ffa6b881d0..3c6a5718cb 100644--- a/crates/calendar_events/AGENTS.md+++ b/crates/calendar_events/AGENTS.md@@ -68,6 +68,9 @@ reminder dispatch, team availability, and provider/Postgres persistence.occurrence projections, not separate events — don't model them as new entities.- Imported point (non-recurring) events must survive sync and cache round-tripsunchanged (#7762) — a regression here silently drops user events.+- Normalize imported Google all-day events with matching start/end dates to one+ day in the adapter, including recurring instances and overrides; preserve the+ raw provider payload and keep reversed dates invalid.- Only an organizer (or a guest the organizer lets modify) may replace anevent's attendee list. Everyone else adds guests through `invite_guests`(`src/domain/mutations/invite.rs`); a guest's `update_event` attendees arediff --git a/crates/calendar_events/Cargo.toml b/crates/calendar_events/Cargo.tomlindex 79176a6ab1..9c9c3cff6f 100644--- a/crates/calendar_events/Cargo.toml+++ b/crates/calendar_events/Cargo.toml@@ -74,6 +74,7 @@ uuid = { workspace = true }workspace-hack = { version = "0.1", path = "../workspace-hack" }[dev-dependencies]+wiremock = { workspace = true }entity_access = { path = "../entity_access", default-features = false, features = ["outbound", "ports"] }macro_db_migrator = { path = "../macro_db_migrator" }macro_user_id = { path = "../macro_user_id" }diff --git a/crates/calendar_events/src/outbound/google.rs b/crates/calendar_events/src/outbound/google.rsindex f70eff84dd..53e8d81e82 100644--- a/crates/calendar_events/src/outbound/google.rs+++ b/crates/calendar_events/src/outbound/google.rs@@ -2492,10 +2492,26 @@ fn google_time(event: &GoogleEvent) -> Result<EventTime, Report> {.with_timezone(&Utc),time_zone: start.time_zone.clone(),},- (_, _, Some(start_value), Some(end_value)) => EventTime::AllDay {- start_date: NaiveDate::parse_from_str(start_value, "%Y-%m-%d").map_err(report)?,- end_date: NaiveDate::parse_from_str(end_value, "%Y-%m-%d").map_err(report)?,- },+ (_, _, Some(start_value), Some(end_value)) => {+ let start_date = NaiveDate::parse_from_str(start_value, "%Y-%m-%d").map_err(report)?;+ let mut end_date = NaiveDate::parse_from_str(end_value, "%Y-%m-%d").map_err(report)?;+ // Imported Google events can use the same date for both ends.+ // Represent that day with an exclusive end; retain Google's+ // original dates in the source payload without writing them back.+ if end_date == start_date {+ end_date = end_date.succ_opt().ok_or_else(|| {+ rootcause::report!("Google event {} has an out-of-range all-day end", event.id)+ })?;+ tracing::debug!(+ provider_event_id = %event.id,+ "normalized a Google all-day event with matching dates"+ );+ }+ EventTime::AllDay {+ start_date,+ end_date,+ }+ }_ => {return Err(rootcause::report!("Google event {} has mixed or missing time fields",diff --git a/crates/calendar_events/src/outbound/google/test.rs b/crates/calendar_events/src/outbound/google/test.rsindex cc029cca84..fcc372e2d7 100644--- a/crates/calendar_events/src/outbound/google/test.rs+++ b/crates/calendar_events/src/outbound/google/test.rs@@ -1,5 +1,6 @@use super::*;+mod all_day;mod import;mod points;diff --git a/crates/calendar_events/src/outbound/google/test/all_day.rs b/crates/calendar_events/src/outbound/google/test/all_day.rsnew file mode 100644index 0000000000..1206cf371e--- /dev/null+++ b/crates/calendar_events/src/outbound/google/test/all_day.rs@@ -0,0 +1,165 @@+use super::*;++fn target() -> ProviderCalendarTarget {+ ProviderCalendarTarget {+ binding: None,+ provider: crate::domain::models::CalendarProvider::Google,+ observed_access_role: Some("reader".to_owned()),+ owner_id: "macro|[email protected]".to_owned(),+ email_link_id: Uuid::now_v7(),+ account_id: Uuid::now_v7(),+ calendar_id: Uuid::now_v7(),+ provider_calendar_id: "primary".to_owned(),+ is_read_only: true,+ range: OccurrenceRange {+ starts_at: DateTime::parse_from_rfc3339("2026-07-01T00:00:00Z")+ .unwrap()+ .with_timezone(&Utc),+ ends_at: DateTime::parse_from_rfc3339("2026-08-01T00:00:00Z")+ .unwrap()+ .with_timezone(&Utc),+ start_date: NaiveDate::from_ymd_opt(2026, 7, 1).unwrap(),+ end_date: NaiveDate::from_ymd_opt(2026, 8, 1).unwrap(),+ },+ }+}++#[tokio::test]+async fn matching_all_day_dates_complete_snapshot_and_incremental_sync() {+ use wiremock::{+ Mock, MockServer, ResponseTemplate,+ matchers::{method, path},+ };++ let server = MockServer::start().await;+ Mock::given(method("GET"))+ .and(path("/calendars/primary/events"))+ .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({+ "items": [+ {+ "id": "same-day-all-day",+ "iCalUID": "[email protected]",+ "status": "confirmed",+ "start": {"date": "2026-07-24"},+ "end": {"date": "2026-07-24"}+ },+ {+ "id": "valid-timed",+ "iCalUID": "[email protected]",+ "status": "confirmed",+ "start": {"dateTime": "2026-07-24T14:00:00Z"},+ "end": {"dateTime": "2026-07-24T15:00:00Z"}+ }+ ],+ "nextSyncToken": "next-token"+ })))+ .expect(4)+ .mount(&server)+ .await;+ let client = GoogleCalendarClient {+ client: Client::new(),+ gate: UnmeteredGate,+ api_base: server.uri(),+ };+ let target = target();+ let expected = EventTime::AllDay {+ start_date: NaiveDate::from_ymd_opt(2026, 7, 24).unwrap(),+ end_date: NaiveDate::from_ymd_opt(2026, 7, 25).unwrap(),+ };++ for (plan, sync_token, materialized_range) in [+ (+ GoogleSyncPlan::FullSnapshot,+ None,+ Some(target.range.clone()),+ ),+ (+ GoogleSyncPlan::Incremental,+ Some("previous-token".to_owned()),+ None,+ ),+ ] {+ let batch = client+ .sync_events(+ "test-token",+ GoogleEventSyncContext {+ target: target.clone(),+ sync_token,+ plan,+ },+ )+ .await+ .unwrap();+ assert_eq!(batch.next_sync_token, "next-token");+ assert_eq!(batch.materialized_range, materialized_range);+ assert_eq!(batch.upserts.len(), 2, "both calendar events survive sync");+ let all_day = batch+ .upserts+ .iter()+ .find(|upsert| upsert.source.details().provider_event_id == "same-day-all-day")+ .unwrap();+ assert_eq!(all_day.event.time, expected);+ assert_eq!(all_day.occurrences.len(), 1);+ assert_eq!(all_day.occurrences[0].time, expected);+ assert_eq!(all_day.occurrences[0].occurrence_key, "2026-07-24");+ assert!(all_day.event.is_read_only);+ assert_eq!(+ all_day.source.details().raw_payload["end"]["date"],+ "2026-07-24"+ );+ }+}++#[test]+fn matching_all_day_dates_normalize_recurring_instances_and_overrides() {+ let master: GoogleEvent = serde_json::from_value(serde_json::json!({+ "id": "series", "iCalUID": "[email protected]",+ "start": {"date": "2026-07-24"}, "end": {"date": "2026-07-24"},+ "recurrence": ["RRULE:FREQ=DAILY;COUNT=2"]+ }))+ .unwrap();+ let moved: GoogleEvent = serde_json::from_value(serde_json::json!({+ "id": "moved-instance", "iCalUID": "[email protected]", "recurringEventId": "series",+ "originalStartTime": {"date": "2026-07-25"},+ "start": {"date": "2026-07-26"}, "end": {"date": "2026-07-26"}+ }))+ .unwrap();+ let upsert = map_upsert(&target(), master, vec![moved.clone()], vec![moved]).unwrap();+ assert_eq!(+ upsert.event.time,+ EventTime::AllDay {+ start_date: NaiveDate::from_ymd_opt(2026, 7, 24).unwrap(),+ end_date: NaiveDate::from_ymd_opt(2026, 7, 25).unwrap(),+ }+ );+ let expected = EventTime::AllDay {+ start_date: NaiveDate::from_ymd_opt(2026, 7, 26).unwrap(),+ end_date: NaiveDate::from_ymd_opt(2026, 7, 27).unwrap(),+ };+ assert_eq!(upsert.overrides[0].time, expected);+ assert_eq!(upsert.occurrences[0].time, expected);+ assert_eq!(upsert.occurrences[0].occurrence_key, "2026-07-25");+}++#[test]+fn matching_all_day_dates_handle_date_boundaries_without_overflow() {+ for (start, end) in [("2028-02-29", "2028-03-01"), ("2026-12-31", "2027-01-01")] {+ let event: GoogleEvent = serde_json::from_value(serde_json::json!({+ "id": "boundary", "start": {"date": start}, "end": {"date": start}+ }))+ .unwrap();+ assert_eq!(+ google_time(&event).unwrap(),+ EventTime::AllDay {+ start_date: NaiveDate::parse_from_str(start, "%Y-%m-%d").unwrap(),+ end_date: NaiveDate::parse_from_str(end, "%Y-%m-%d").unwrap(),+ }+ );+ }+ let max_date = NaiveDate::MAX.to_string();+ let event: GoogleEvent = serde_json::from_value(serde_json::json!({+ "id": "unrepresentable-end", "start": {"date": max_date}, "end": {"date": max_date}+ }))+ .unwrap();+ assert!(google_time(&event).is_err());+}diff --git a/crates/calendar_events/src/outbound/google/test/points.rs b/crates/calendar_events/src/outbound/google/test/points.rsindex b0666d3c52..6b4facc3b4 100644--- a/crates/calendar_events/src/outbound/google/test/points.rs+++ b/crates/calendar_events/src/outbound/google/test/points.rs@@ -207,7 +207,7 @@ async fn a_duration_becoming_a_point_is_an_upsert_with_the_same_provider_identit}#[tokio::test]-async fn reversed_timed_and_nonpositive_all_day_events_still_reject_whole_batches() {+async fn reversed_timed_and_all_day_events_still_reject_whole_batches() {let target = target();let client = GoogleCalendarClient::new(Client::new());let valid = timed_event(@@ -223,7 +223,7 @@ async fn reversed_timed_and_nonpositive_all_day_events_still_reject_whole_batche})).unwrap()};- for invalid in [reversed, all_day("2026-07-24"), all_day("2026-07-23")] {+ for invalid in [reversed, all_day("2026-07-23")] {assert!(google_time(&invalid).is_err());assert!(map_snapshot(diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex 0dcc01d8c4..4678dce186 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -167,6 +167,14 @@ Confirm mixed event shapes, stable positions, clean handoff, and an uncovered ReReduced-motion mode disables pulses and transitions. The page stays busy until thehandoff starts. Hidden pages do not animate. Resize to confirm skeleton alignment.+Imported Google all-day events whose start and end dates match display as one day.+This also applies to recurring instances and moved exceptions. Sync keeps the+original provider dates without editing the Google event; reversed dates remain+invalid. Verify that a calendar containing both such an all-day event and an+ordinary timed event completes sync and shows both.+The [calendar component fixture](media/calendar-import/one-day.png) shows a+normalized one-day occurrence beside a timed event on the same date.+Imported timed events with identical start and end are points: they show a compactchip with one time and `No duration` in details, and do not block availability.Future points also appear in Upcoming events, without becoming ongoing meetings.diff --git a/docs/agent-guide/media/calendar-import/one-day.png b/docs/agent-guide/media/calendar-import/one-day.pngnew file mode 100644index 0000000000..c8c15284cdBinary files /dev/null and b/docs/agent-guide/media/calendar-import/one-day.png differ