Skip to content

fix(web): stop 404 signout on post-signup sync and tolerate cache-only local edits#2195

Merged
tyler-dane merged 1 commit into
mainfrom
posthog-code/fix-offline-sync-404-and-local-edit
Jul 19, 2026
Merged

fix(web): stop 404 signout on post-signup sync and tolerate cache-only local edits#2195
tyler-dane merged 1 commit into
mainfrom
posthog-code/fix-offline-sync-404-and-local-edit

Conversation

@posthog

@posthog posthog Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two offline-handling regressions introduced by the event-runtime cutover to calendar-owned contracts (#2017):

  1. Post-signup sync 404 → surprise sign-out. syncLocalEventsToCloud fell back to a client-generated sentinel calendar id when it couldn't find a server-side local calendar, then POST /event against it. The backend can't resolve that id and throws CALENDAR_NOT_FOUND (404). handleErrorResponse treated a 404 on a data endpoint as an auth failure and signed the user out — right after they signed up. Now the sync only ever targets the real server local calendar; if it isn't available yet, the records stay on-device (untouched) for a later sync instead of being pushed with a bogus id. Separately, a 404 on a non-auth endpoint no longer forces sign-out — only genuine session failures (GONE/UNAUTHORIZED) do.

  2. Event not found when editing offline. The optimistic layer resolves the edit target from the react-query cache, but LocalEventRepository reads IndexedDB. An id present in the cache but absent from the store (e.g. a materialized recurring-occurrence instance) threw Event not found. replace now upserts instead of throwing, so the edit persists rather than crashing.

Simplicity

Changes are minimal and local to the three affected modules: drop the sentinel fallback in the sync util, remove NOT_FOUND from the sign-out trigger, and make the local repository's replace tolerant of a missing record. No interface or contract changes.

Automated validation

Not run in this environment (no app/browser session). Covered by unit tests below.

Independent review

Self-reviewed the diff; the sentinel fallback, the sign-out trigger, and the throwing lookup were the three root causes and each is addressed at its source.

Test plan

  • bun test src/api src/auth/google/util src/events/repositories src/common/utils/sync (packages/web) — 79 pass, 0 fail, including new cases:
    • sync keeps records on-device (no POST, no clear) when no server local calendar exists
    • handleErrorResponse does not sign out on a 404 data-endpoint response, and still does on UNAUTHORIZED
    • LocalEventRepository.replace upserts (instead of throwing) when the target is absent from the store, and preserves an input-provided calendar

Created with PostHog Code from this inbox report.

…y local edits

The event-runtime cutover (#2017) introduced two offline-handling bugs:

- syncLocalEventsToCloud fell back to a client-generated sentinel calendar
  id when no server-side local calendar was found, so the POST /event 404'd
  with CALENDAR_NOT_FOUND. handleErrorResponse then treated that 404 as an
  auth failure and signed the just-signed-up user out. Now the sync only
  targets the real server local calendar and otherwise keeps records
  on-device for a later sync; a 404 on a data endpoint no longer forces
  sign-out (only GONE/UNAUTHORIZED do).

- Editing an event whose id lives only in the react-query cache (e.g. a
  materialized recurring-occurrence instance) but not in IndexedDB threw
  "Event not found" from LocalEventRepository. replace now upserts instead
  of throwing, so offline edits persist rather than crashing.

Generated-By: PostHog Code
Task-Id: 3b0e5f4a-eb9c-4db7-8522-feeb18b17dc8
@tyler-dane
tyler-dane marked this pull request as ready for review July 19, 2026 03:27
@tyler-dane
tyler-dane merged commit f218d0a into main Jul 19, 2026
16 checks passed
@tyler-dane
tyler-dane deleted the posthog-code/fix-offline-sync-404-and-local-edit branch July 19, 2026 03:27
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.

1 participant