Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(calendar): backfill stripped Microsoft occurrences from series master (#1665)

Gabriel Stein187461421873
diff --git a/CLAUDE.md b/CLAUDE.md
index a54812a9a..29c729e8b 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -136,6 +136,7 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.
- Incremental sync via `syncToken`; full re-sync on 410 prunes stale events (note-linked rows retained)
- **microsoftCalendarManager.js**: Microsoft Calendar sync via Graph API (OAuth via `microsoftCalendarOAuth.js`)
- `calendarView/delta` incremental sync over a 14-day window; delta token discarded after 7 days (Graph delta links never roll their window forward)
+ - Delta can return recurring-series occurrences as bare stubs (no subject/attendees/meeting link); they're backfilled from their series master, one `GET /me/events/{id}` per series
- Full re-sync (410 or expired token) prunes stale events like Google
- **appleCalendarManager.js**: Apple Calendar (EventKit) via the `macos-calendar-listener` Swift helper — macOS only, snapshot-push over stdout, no tokens ("connected" = `apple_calendars` has rows)
- **calendarReminderScheduler.js**: Provider-agnostic meeting reminder scheduling over the shared `calendar_events` table (provider-scoped reset keys, so one provider's disconnect doesn't re-fire another's reminders)
diff --git a/src/helpers/microsoftCalendarManager.js b/src/helpers/microsoftCalendarManager.js
index f20e3dcf8..7f5eaeb43 100644
--- a/src/helpers/microsoftCalendarManager.js
+++ b/src/helpers/microsoftCalendarManager.js
@@ -7,6 +7,9 @@ const { broadcastToWindows } = require("./windowBroadcast");
const GRAPH_API_BASE = "https://graph.microsoft.com/v1.0";
+const SERIES_MASTER_FIELDS =
+ "subject,isAllDay,isCancelled,onlineMeeting,onlineMeetingUrl,location,bodyPreview,organizer,attendees";
+
// Graph's deltaLink permanently encodes the calendarView window it was created
// with — it never rolls forward. Sync a 14-day window and discard the token
// after 7 days so coverage never drops below the app's 7-day lookahead.
@@ -26,6 +29,13 @@ function normalizeGraphDateTime({ dateTime }) {
return `${dateTime.slice(0, 19)}Z`;
}
+// calendarView/delta can return recurring-series occurrences as bare
+// { id, type, seriesMasterId, start, end } stubs — no subject, attendees,
+// or meeting link. Those fields live on the series master.
+function isStrippedOccurrence(item) {
+ return item.subject === undefined && Boolean(item.seriesMasterId);
+}
+
class MicrosoftCalendarManager {
constructor(databaseManager, reminderScheduler) {
this.databaseManager = databaseManager;
@@ -169,9 +179,8 @@ class MicrosoftCalendarManager {
async _syncCalendar(calendar) {
const accountEmail = calendar.account_email;
- const toUpsert = [];
+ const items = [];
const toRemove = [];
- const contactsToUpsert = [];
let deltaLink = null;
const hasFreshToken = calendar.sync_token && calendar.sync_token_expires_at > Date.now();
@@ -197,25 +206,30 @@ class MicrosoftCalendarManager {
}
for (const item of data.value || []) {
- if (item["@removed"]) {
- toRemove.push(item.id);
- continue;
- }
- toUpsert.push(this._mapEvent(item, calendar));
- for (const a of item.attendees || []) {
- if (a.emailAddress?.address) {
- contactsToUpsert.push({
- email: a.emailAddress.address,
- displayName: a.emailAddress.name || null,
- });
- }
- }
+ if (item["@removed"]) toRemove.push(item.id);
+ else items.push(item);
}
deltaLink = data["@odata.deltaLink"] || deltaLink;
url = data["@odata.nextLink"] || null;
}
+ const events = await this._backfillStrippedOccurrences(items, accountEmail);
+
+ const toUpsert = [];
+ const contactsToUpsert = [];
+ for (const item of events) {
+ toUpsert.push(this._mapEvent(item, calendar));
+ for (const a of item.attendees || []) {
+ if (a.emailAddress?.address) {
+ contactsToUpsert.push({
+ email: a.emailAddress.address,
+ displayName: a.emailAddress.name || null,
+ });
+ }
+ }
+ }
+
// A full sync has no delta baseline, so deletions that happened while the
// token was invalid never arrive as @removed — prune what the fresh
// snapshot no longer contains.
@@ -234,6 +248,38 @@ class MicrosoftCalendarManager {
if (contactsToUpsert.length > 0) this.databaseManager.upsertContacts(contactsToUpsert);
}
+ // Merges each stripped occurrence with its series master (fetched once per
+ // series); the occurrence's own id/start/end win. A failed master fetch
+ // leaves its occurrences bare instead of failing the calendar's sync.
+ async _backfillStrippedOccurrences(items, accountEmail) {
+ const masterIds = new Set(
+ items.filter(isStrippedOccurrence).map((item) => item.seriesMasterId)
+ );
+ if (masterIds.size === 0) return items;
+
+ const masters = new Map();
+ for (const id of masterIds) {
+ try {
+ const master = await this._apiGet(
+ `/me/events/${encodeURIComponent(id)}?$select=${SERIES_MASTER_FIELDS}`,
+ accountEmail
+ );
+ masters.set(id, master);
+ } catch (err) {
+ debugLogger.error(
+ "Error fetching series master",
+ { seriesMasterId: id, error: err.message },
+ "mcal"
+ );
+ }
+ }
+
+ return items.map((item) => {
+ const master = isStrippedOccurrence(item) ? masters.get(item.seriesMasterId) : null;
+ return master ? { ...master, ...item } : item;
+ });
+ }
+
_mapEvent(item, calendar) {
const attendees = item.attendees || [];
const accountEmail = (calendar.account_email || "").toLowerCase();
diff --git a/test/helpers/microsoftCalendarManager.test.js b/test/helpers/microsoftCalendarManager.test.js
index 6a7f8c1d0..843dbfd21 100644
--- a/test/helpers/microsoftCalendarManager.test.js
+++ b/test/helpers/microsoftCalendarManager.test.js
@@ -100,3 +100,104 @@ test("_mapEvent falls back to a meeting link found in location or body text", ()
assert.equal(mapped.hangout_link, "https://example.zoom.us/j/123456789");
assert.equal(mapped.attendees, null);
});
+
+function createManager(MicrosoftCalendarManager, upserted, contacts = []) {
+ return new MicrosoftCalendarManager(
+ {
+ removeStaleCalendarEvents: () => {},
+ upsertCalendarEvents: (events) => upserted.push(...events),
+ removeCalendarEvents: () => {},
+ updateMicrosoftCalendarSyncToken: () => {},
+ upsertContacts: (rows) => contacts.push(...rows),
+ },
+ {}
+ );
+}
+
+const STRIPPED_OCCURRENCE = {
+ id: "occ-1",
+ type: "occurrence",
+ seriesMasterId: "master-1",
+ start: { dateTime: "2026-07-20T09:25:00.0000000" },
+ end: { dateTime: "2026-07-20T09:30:00.0000000" },
+};
+
+test("_syncCalendar backfills stripped recurring occurrences from their series master", async () => {
+ const MicrosoftCalendarManager = loadManagerModule();
+ const upserted = [];
+ const contacts = [];
+ const manager = createManager(MicrosoftCalendarManager, upserted, contacts);
+
+ const masterFetches = [];
+ manager._apiGet = async (url) => {
+ if (url.includes("/calendarView/delta")) {
+ return {
+ "@odata.deltaLink": "delta-link",
+ value: [
+ STRIPPED_OCCURRENCE,
+ {
+ ...STRIPPED_OCCURRENCE,
+ id: "occ-2",
+ start: { dateTime: "2026-07-21T09:25:00.0000000" },
+ end: { dateTime: "2026-07-21T09:30:00.0000000" },
+ },
+ {
+ id: "evt-1",
+ subject: "One-off",
+ start: { dateTime: "2026-07-20T17:00:00.0000000" },
+ end: { dateTime: "2026-07-20T17:30:00.0000000" },
+ },
+ ],
+ };
+ }
+ masterFetches.push(url);
+ return {
+ id: "master-1",
+ subject: "Standup",
+ isAllDay: false,
+ onlineMeeting: { joinUrl: "https://teams.microsoft.com/l/meetup-join/abc" },
+ organizer: { emailAddress: { address: "[email protected]" } },
+ attendees: [
+ {
+ emailAddress: { address: "[email protected]", name: "Me" },
+ status: { response: "accepted" },
+ },
+ ],
+ };
+ };
+
+ await manager._syncCalendar({ id: "cal-1", account_email: "[email protected]" });
+
+ assert.equal(masterFetches.length, 1);
+ assert.match(masterFetches[0], /^\/me\/events\/master-1\?\$select=/);
+
+ const occurrence = upserted.find((event) => event.id === "occ-1");
+ assert.equal(occurrence.summary, "Standup");
+ assert.equal(occurrence.start_time, "2026-07-20T09:25:00Z");
+ assert.equal(occurrence.hangout_link, "https://teams.microsoft.com/l/meetup-join/abc");
+ assert.equal(occurrence.organizer_email, "[email protected]");
+ assert.equal(occurrence.attendees_count, 1);
+ assert.equal(upserted.find((event) => event.id === "occ-2").summary, "Standup");
+ assert.equal(upserted.find((event) => event.id === "evt-1").summary, "One-off");
+ assert.ok(contacts.some((contact) => contact.email === "[email protected]"));
+});
+
+test("_syncCalendar keeps stripped occurrences when the series master fetch fails", async () => {
+ const MicrosoftCalendarManager = loadManagerModule();
+ const upserted = [];
+ const manager = createManager(MicrosoftCalendarManager, upserted);
+
+ manager._apiGet = async (url) => {
+ if (url.includes("/calendarView/delta")) {
+ return { "@odata.deltaLink": "delta-link", value: [STRIPPED_OCCURRENCE] };
+ }
+ throw new Error("master gone");
+ };
+
+ await manager._syncCalendar({ id: "cal-1", account_email: "[email protected]" });
+
+ assert.equal(upserted.length, 1);
+ assert.equal(upserted[0].id, "occ-1");
+ assert.equal(upserted[0].summary, null);
+ assert.equal(upserted[0].start_time, "2026-07-20T09:25:00Z");
+});