Skip to content

fix(sync): converge event create onto an imported provider identity row - #5443

Merged
tyler-dane merged 2 commits into
mainfrom
posthog-self-driving/fixsync-converge-event-create-onto-an-9b2cec
Dec 5, 2026
Merged

tyler-dane merged 2 commits into
mainfrom
posthog-self-driving/fixsync-converge-event-create-onto-an-9b2cec

Conversation

@posthog

@posthog posthog Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5441
Fixes #5442

What and why

Problem

  • A user creates an event, the event reaches Google, but Compass shows a failed save (502). The event is missing in Compass until a later sync.
  • The create writes to Google with the Compass id, then stores the event with put(), which upserts by _id only. If a webhook or pull import stores the same Google event first under a new _id, the put() insert collides on provider_event_identity (E11000). The new db test reproduces this exact replaceOne error.
  • The backend log for this failure has no HTTP status and no correlation id, because throwSyncCommandSubmitFailure drops the SyncClientError.

Changes

  • On E11000, the create finds the imported row by provider identity, clears its occurrences, deletes it, and stores the create's record again. The event keeps the Compass _id, because the web and later commands address it by that id. Updating the imported row in place (as upsertException does) would leave the event under an id that the client does not know.
  • New helper putCreatedProviderEvent in provider-command.internal.ts. Both create paths use it: the plain create and the "this and following" remainder create, which has the same race.
  • throwSyncCommandSubmitFailure takes the whole SyncClientError and passes it on as syncError, so syncFailureLogContext logs the status and correlation id. Log levels do not change: logLevelForSyncClientError gives the same level as before for every kind.

Warning

Residual risks, both narrow:

  • If the import flushes its occurrence projection after the create removes the imported row, an orphan occurrence row can stay until the next repair.
  • The stored record is the create's record, with the write's etag. If the import read a newer version, Compass keeps the older etag until the next provider change.

Agent context

  • I did not reproduce this in production. The db test reproduces the race and the same E11000 from replaceOne.
  • I rejected a fix in the import path: the import cannot see the create's record yet, so it cannot avoid the new _id.

Verify

  • bun run verify --strict: VERDICT: PASS. Checks run: test:sync, test:backend:fast, type-check, lint, knip. No PRE-EXISTING or FLAKY failures.
  • New test replaces the row an import stored between the provider write and put fails on main with E11000 on provider_event_identity, and passes with this change.

Created with PostHog Desktop from this inbox report.

Origin

  • Error tracking: issue
  • First signal: 2026-12-05
  • Inbox report: open
  • Task started by: auto-start, after the report was rated P2 and ready to fix

A webhook or pull import can store a new provider event between the provider write and the create's put. The put then hit E11000 on provider_event_identity and the user saw a failed save. The create now replaces the imported row and its occurrences, so the event keeps its Compass id.

The backend also passes the SyncClientError into the command submit failure, so the log shows the status and correlation id.

Generated-By: PostHog Desktop
Task-Id: 0a34c050-6fdf-41f4-a8ac-bf00a51837af
@posthog
posthog Bot requested a review from tyler-dane December 5, 2026 15:40
Generated-By: PostHog Desktop
Task-Id: 0a34c050-6fdf-41f4-a8ac-bf00a51837af
@tyler-dane
tyler-dane marked this pull request as ready for review December 5, 2026 20:34
@tyler-dane
tyler-dane added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit f3105d1 Dec 5, 2026
19 checks passed
@tyler-dane
tyler-dane deleted the posthog-self-driving/fixsync-converge-event-create-onto-an-9b2cec branch December 5, 2026 20:42
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.

Error Error

1 participant