Skip to content

fix(calendar): stop re-checking access every minute without a grant - #1922

Merged
abue-ammar merged 1 commit into
abue-ammar:mainfrom
hannoeru:fix/calendar-access-poll
Nov 16, 2026
Merged

abue-ammar merged 1 commit into
abue-ammar:mainfrom
hannoeru:fix/calendar-access-poll

Conversation

@hannoeru

@hannoeru hannoeru commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Related issue

Closes #1927

Why this is needed

It is for users who have Calendar on in Settings but no Calendar grant from macOS. Every user who upgraded from a com.tinycast.app build with Calendar on is in this state, because the grant stays with the old bundle id. For them, Tinycast wakes every minute, calls two system daemons and tccd, and writes an error to the system log, with no result. This change stops that work and makes the "Nothing polls" invariant in docs/features/calendar.md true again.

What it could break

  • With no grant, Tinycast now checks access again after 10 minutes, at the day change, on wake, and on each palette summon, not each minute. So a grant made in System Settings while the palette stays closed can take up to 10 minutes to show on the menu bar. A palette summon finds it at once.
  • With a grant, nothing changes. lastReloadAt was already set on each granted reload, and the stamp now comes a few lines earlier in the same synchronous call.
  • span.didSet now also re-runs reload() after a denied reload. That re-checks access and publishes an empty list, which is correct.

What changed

Calendar is on, but macOS has not granted full Calendar access. In this state, Tinycast checks access again on every minute tick. The unified log shows this pattern on the minute, every minute (246 times in 2 days on one Mac):

[com.apple.xpc:connection] activating connection: … name=com.apple.remindd
[com.apple.xpc:connection] activating connection: … name=com.apple.CalendarAgent
[com.apple.reminderkit:xpc] REMXPCDaemonController invalidate
E [com.apple.reminderkit:xpc] XPC connection was invalidated

For each tick, tccd also answers four kTCCServiceCalendar / kTCCServiceReminders preflight requests.

Cause: CalendarStore.reload() set lastReloadAt only after the access guard. Without a grant, the stamp stays nil. So reloadIfStale(now:) calls reload() on every MeetingClock tick, and reload() calls EKEventStore.authorizationStatus(for:) again. This breaks the "Nothing polls" invariant in docs/features/calendar.md.

Fix: set lastReloadAt before the guard. A missing grant is still checked again on the 10-minute stale interval, at the day rollover, on wake, and on every palette summon (paletteDidShow calls reload()). So a grant made later in System Settings is still found. span.didSet and stop() work as before.

How a Mac gets into this state: the com.tinycast.app to com.abueammar.tinycast move carries calendarEnabled = true over in preferences, but TCC grants stay with the old bundle id. The new id has no TCC record, so it does not show in System Settings › Privacy › Calendars, and nothing prompts until the user toggles Calendar in Settings.

Memory footprint

Tinycast Dev, fixed build, footprint:

Step Memory
Idle after launch 42 MB
Palette open 44 MB
Feature in use (peak) n/a. Without a grant the feature only publishes an empty list.
Palette closed, settled 42 MB

Leak-tested: no. The change adds no allocation.

Drawbacks

See "What it could break". The one tradeoff is the up-to-10-minute delay before a new grant shows while the palette stays closed.

Tests & validation

On Tinycast Dev (no Calendar grant) with calendarEnabled = true and calendarMenuBarDisplay = 2, I watched the unified log:

  • Before: remindd and CalendarAgent connections at launch, then at 00:13:00 and 00:14:00.
  • After: connections at launch only, none at the 00:17 to 00:21 minute boundaries, and one for each palette summon.

Checks:

  • ./Scripts/run-tests.sh: 113 of 114 pass. FileSearchTests fails at "undeclared waits on bytes" because an installed Adobe app declares com.adobe.jsx on this Mac. That harness compiles only Features/FileSearch/Model, so this change does not affect it.
  • ./Scripts/lint.sh: clean.
  • Debug build: no new warnings.
  • Features/*/Model/ import grep: no output.

reload() set lastReloadAt only after the access guard, so with Calendar on but no full access, reloadIfStale saw a nil stamp on every MeetingClock tick and re-ran EKEventStore.authorizationStatus. Each call opened and cancelled XPC connections to remindd and CalendarAgent and logged 'XPC connection was invalidated' once a minute. Stamp it before the guard, so a missing grant is re-checked on the stale interval and on each summon.
Copilot AI lite review requested due to automatic review settings November 15, 2026 15:29
@github-actions

Copy link
Copy Markdown

Thanks for the PR! A maintainer will review it soon.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the change addresses repeated Calendar authorization checks while preserving the existing refresh triggers.

No open issues 🎉

What changed in this PR

This PR prevents Calendar access checks and EventKit/XPC activity from recurring every minute when Calendar access has not been granted, while preserving existing refresh triggers.

Changes:

  • Records lastReloadAt before the authorization guard.
  • Preserves retries on the stale interval, day rollover, wake, and palette summon.
  • Avoids repeated denied-access checks without changing granted-access behavior.
File Description
Tinycast/​Features/​Calendar/​Service/​CalendarStore.swift Records reload attempts before checking Calendar authorization to prevent repeated minute-by-minute access checks without a grant.

Review effort: Lite

@abue-ammar
abue-ammar merged commit e4c9bd5 into abue-ammar:main Nov 16, 2026
3 of 5 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.

Calendar re-checks access every minute when it has no grant

3 participants