Skip to content

Add events_update tool - #273

Merged
mattt merged 12 commits into
mattt:mainfrom
bradhallett:events-update
Oct 13, 2026
Merged

mattt merged 12 commits into
mattt:mainfrom
bradhallett:events-update

Conversation

@bradhallett

@bradhallett bradhallett commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #129

What

Adds events_update, following the shape of events_delete (#209):

  • Partial updates: only provided properties change; null clears location, notes, url, and alarms
  • Full events_create parity: title, start, end, calendar, location, notes, url, isAllDay, availability, alarms
  • Recurring events: occurrence start date + span (thisEvent | futureEvents, default thisEvent), exactly like events_delete; the recurring-without-occurrence error names the parameter to pass
  • Strict calendar moves: an unmatched calendar name is an error, not a silent default, and the target must allow modifications — a move into a read-only (e.g. subscribed) calendar throws before anything is mutated, instead of sitting unsaved in the shared store until the next successful save commits it

Shared helpers extracted inside CalendarService:

  • Alarm configuration parsing (relative/absolute/proximity + sound/email) now lives in one static builder used by both events_create and events_update
  • Occurrence resolution is prefix-tolerant: a detached exception from an earlier thisEvent edit carries <series-id>/RID=<n> instead of the series identifier, so events_delete's exact-match predicate could never find an already-edited occurrence again. One shared resolver (eventPossiblyDetached) serves both tools, so events_update and events_delete both accept the identifiers events_list exposes and events_update returns.

Hardening

  • All validation — identifier, span, occurrence, start/end, calendar and its editability, url, every alarm — completes before the first mutation, for the same reason as the calendar guard above: a throw after mutating EventKit's shared store strands the change in every later save.
  • Proximity alarms accept integer coordinates, which number validates and whole-degree positions make common; previously they were silently dropped (erasing an event's existing alarms on update) while the same builder bridged integer radii three lines below. Alarm type is now required in the absolute and proximity branches — a typeless {datetime} object used to validate but silently discard — while relative keeps its default.
  • Alarm minutes scale in Double: schema-legal large integers no longer trap the process, and the description now says which side of the event they land on (positive = before start, matching the builder and the reminders tools).
  • events_create rejects a present-but-wrong-shaped alarms or url the same way the update handler does (f416f84) — previously it silently ignored them.

Testing

  • swift format + xcodebuild (Xcode 27.0) clean
  • 28/28 live EventKit checks against the real store, covering: property round-trips, null-clears, all three alarm kinds, all-day boundary snapping, calendar moves, thisEvent edits (target only, neighbors untouched), re-editing a detached exception, and futureEvents splits (tail day +1 edited, prior days untouched)

Notes

  • iCloud rotates event identifiers when an event moves calendars, and a futureEvents split creates a new tail series identifier. The tool returns the saved event's identifier, so callers always get the authoritative one back.
  • Error codes mirror events_delete: 1 = not authorized, 2 = validation, 3 = not found.

Adds events_update with events_create's full property surface in
partial-update form: omitted properties are unchanged, null clears
optional properties (location, notes, url, alarms). Recurring events
take an occurrence start date plus span (thisEvent/futureEvents),
mirroring events_delete.

- Extracts the alarm configuration parser from events_create into a
  shared static builder used by create and update
- Extracts occurrence resolution into a prefix-tolerant helper shared
  with events_delete: detached exceptions from earlier thisEvent edits
  carry <series-id>/RID=<n> instead of the series identifier, so exact
  matching could never find them again
- Calendar moves are strict: an unmatched calendar name is an error
- The saved event's identifier is returned, which matters because
  iCloud rotates identifiers when an event moves calendars and
  futureEvents splits create a new tail series identifier
- Schemas accept null for title, location, notes, url, and alarms,
  matching the documented clear-on-null behavior; title null clears
- The description names exactly which properties null clears
- Identifiers returned with a detached-occurrence suffix
  (<series>/RID=<n>) now resolve: when the direct lookup fails, the
  series prefix is retried and the occurrence date still selects the
  exact occurrence
- events_update parses start, end, calendar and url before touching the
  fetched event. EventKit retains unsaved mutations in its shared store,
  so a failed call could otherwise leave changes that the next
  successful save commits without anyone asking for them
- a date-only absolute alarm datetime now means local midnight, as the
  schema already documents for every other date parameter, instead of
  being dropped with a log line — in the update path a dropped alarm
  config would remove existing alarms and report success
- events_delete accepts the detached-exception identifiers
  events_list exposes and events_update produces: the direct lookup
  falls back to the series prefix, and the start date still selects
  the exact occurrence, mirroring events_update
- The recurring-event error names the occurrence parameter, so a
  client retrying with the message's guidance no longer hits the same
  error through start, which means the new start time
…aring

- Proximity alarms accept integer latitude/longitude, which .number()
  validates and whole-degree coordinates make common; the shared
  builder dropped them (silently erasing an event's existing alarms
  in events_update) while bridging radius three lines below
- The absolute and proximity branches now require type: without it a
  validating client's {"datetime": ...} object fell through to the
  relative default and was silently discarded. The relative branch
  keeps type optional since it carries the default
…detached resolver

- The calendar-name match for a move now requires
  allowsContentModifications, so a read-only target (a subscribed
  calendar) throws before any mutation instead of leaving the move
  unsaved in the shared store for the next successful save to commit
- Alarm minutes scale in Double, matching the reminders fix: Int
  arithmetic traps at Int.min and past ~1.5e17, crashing the whole
  server on one tool call
- The /RID= detached-identifier fallback is one helper now,
  eventPossiblyDetached(_:), instead of the same 12-line closure
  twice in events_update and events_delete
The builder maps minutes to -minutes * 60 seconds, so positive
minutes fire before the event start and negative after — the
opposite of the old description in both schema copies. Align the
text with the behavior and with the reminders tools' "minutes
before" wording.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Runtime validation gaps can silently discard input or mutate EventKit objects before failed saves.

5 open findings
What changed in this PR

Adds calendar event updates with partial fields, recurring-event spans, and safer EventKit handling.

Changes:

  • Adds events_update with calendar moves, alarms, and recurrence support.
  • Shares alarm and detached-occurrence resolution logic.
  • Tightens alarm schemas and numeric handling.
File Description
App/​Services/​Calendar.swift Implements updates and shared Calendar helpers.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
inputSchema is advertised, not enforced, so the update handler now
type-checks every present argument (span, occurrence, start, end,
calendar, url, title, location, notes, availability including enum
membership, isAllDay, alarms) and throws before anything is resolved
or mutated. An event whose current calendar disallows modifications
is rejected up front, and the effective start/end range is checked
before mutation so EventKit cannot fail at save with the shared event
already changed. The alarm builder is now throwing and builds the
complete replacement list before the first mutation in both
events_update and events_create, so a malformed entry can no longer
quietly wipe alarms through compactMap. URLs must carry a scheme,
matching the advertised .uri format, and proximity coordinates and
radii are bounds-checked in code and schema.
The update handler rejects a present argument of the wrong shape;
create silently ignored alarms: "bad" or url: 42. Same class of bug,
same fix: throw instead of creating an event without them.
@bradhallett

Copy link
Copy Markdown
Contributor Author

Follow-up in f416f84: events_create now rejects wrong-shaped alarms (non-array) and url (non-string) instead of silently ignoring them — the same present-but-wrong-shape rejection the update handler got.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
Comment thread App/Services/Calendar.swift Resolved
bradhallett and others added 2 commits October 13, 2026 07:40
Alarm builder errors carried code 4, but this PR's documented contract
(and events_delete) uses 1/2/3; every alarm(from:) failure is now code
2. A present non-string alarm type no longer folds into the relative
default, matching the schemas the tools advertise. Proximity radius
distinguishes an absent value — now applying the 200 m default the
schema documents, instead of leaving a zero-radius geofence — from a
malformed one, which is rejected. Whole-day boundary normalization
follows the event's effective all-day state, so an already-all-day
event whose end moves without isAllDay being resent snaps to 23:59:59
instead of keeping a local-midnight end that can make it zero-length.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

No-op recurring updates can alter recurrence structure, and unsupported arguments remain silently ignored.

0 open findings

4 resolved since last review
Previously missed (4)

In code that hasn't changed since last review

Medium severity Reject unknown argument names before processing

App/​Services/​Calendar.swift:840

additionalProperties: false is only advertised; this handler never rejects unknown argument names. A request such as {identifier, notes, notez} therefore succeeds while silently ignoring the typo, even though Service.call forwards the dictionary without schema validation. Validate the key set before processing so partial updates cannot report success after dropping requested input.

Medium severity Reject recurring updates with no mutable event fields

App/​Services/​Calendar.swift:1167

A recurring update is allowed to contain only identifier and occurrence/span, so this mutation block eventually saves an unchanged occurrence. Saving with .thisEvent can create a detached exception, while .futureEvents can split the series, meaning a request with no property update still changes recurrence structure. Reject requests that contain none of the mutable event fields before touching the event.

Medium severity Reject unknown or inapplicable alarm fields

App/​Services/​Calendar.swift:1317

The alarm schemas also rely on additionalProperties: false, but the builder validates only fields it reads. Extra or branch-inapplicable fields are silently ignored—for example, a valid relative alarm with a misspelled emailAdress is saved without email while the call reports success. Reject keys not allowed for the selected alarm type before constructing it.

Low severity Resolve calendar by title before checking editability

App/​Services/​Calendar.swift:1073

Filtering on editability inside the title lookup conflates two distinct failures. If a subscribed calendar with this exact title exists, the tool reports No calendar named ..., which is false and prevents callers from understanding why the move was rejected. Resolve by title first, then issue the existing non-modifiable-calendar error when appropriate.

🧠 Review effort: Balanced

@mattt
mattt merged commit a55bdcc into mattt:main Oct 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add events_update and events_delete tools

3 participants