From b5d06a11c7c171855c57934391dbb5b7333e9481 Mon Sep 17 00:00:00 2001 From: Matin Gathani Date: Sun, 29 Mar 2026 18:35:38 -0700 Subject: [PATCH] Fix timestamp protection allowing equal-timestamp updates to be dropped The WHERE clause in constructUpsertWithTimestampProtectionSql used a strict less-than comparison for last_synced_at. This silently dropped updates when two events carried the same timestamp, e.g. webhook redeliveries or events generated within the same second. Changing the condition to <= ensures that an incoming event with a timestamp equal to the stored one still overwrites the row, which is the correct behaviour for idempotent event processing. Fixes #268 --- packages/sync-engine/src/database/postgres.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sync-engine/src/database/postgres.ts b/packages/sync-engine/src/database/postgres.ts index ba0c0e194..b68910cbb 100644 --- a/packages/sync-engine/src/database/postgres.ts +++ b/packages/sync-engine/src/database/postgres.ts @@ -199,8 +199,8 @@ export class PostgresClient { .map((x) => `"${x}" = EXCLUDED."${x}"`) .join(',')}, last_synced_at = :last_synced_at - WHERE "${table}"."last_synced_at" IS NULL - OR "${table}"."last_synced_at" < :last_synced_at;` + WHERE "${table}"."last_synced_at" IS NULL + OR "${table}"."last_synced_at" <= :last_synced_at;` } /**