Skip to content

Calendar commands fail with 404 in pure SA mode (getUserTimezone fetches CalendarList/primary) #2

@delight-ai-agent

Description

@delight-ai-agent

Problem

Calendar commands (e.g. gog calendar events <calendarId>) fail with 404 notFound when using a service account in pure SA mode (no impersonation).

The root cause is getUserTimezone() in internal/cmd/time_helpers.go:56, which unconditionally calls CalendarList.Get("primary") to resolve the user's timezone. A service account running in pure mode has no "primary" calendar, so the Google Calendar API returns 404.

This blocks all calendar commands that go through ResolveTimeRangegetUserTimezone.

Repro

# Set up pure SA mode (SA email matches --account)
gog auth service-account set --key=sa-key.json sa@project.iam.gserviceaccount.com

# Calendar shared with the SA has events, but this fails:
gog calendar events someone@example.com --account sa@project.iam.gserviceaccount.com
# → Google API error (404 notFound): Not Found

# Drive commands work fine in the same setup:
gog drive ls --parent <folderId> --account sa@project.iam.gserviceaccount.com
# → OK

Expected: Events listed from the shared calendar.

Actual: 404 notFound from CalendarList.Get("primary") before the actual events request is made.

Analysis

time_helpers.go:56:

func getUserTimezone(ctx context.Context, svc *calendar.Service) (*time.Location, error) {
    cal, err := svc.CalendarList.Get("primary").Context(ctx).Do()
    // ↑ SA has no primary calendar → 404

In impersonation mode (DWD), cfg.Subject is set so the API call runs as the impersonated user who does have a primary calendar. In pure SA mode (introduced in PR #1), no impersonation occurs, so CalendarList.Get("primary") has no user context.

Possible fix

When CalendarList.Get("primary") fails in pure SA mode, fall back to:

  1. The timezone of the explicitly specified calendarId (via CalendarList.Get(calendarId)), or
  2. UTC

✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions