@pylonsync/sync 0.3.184 → 0.3.185
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +16 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1735,6 +1735,13 @@ export class SyncEngine {
|
|
|
1735
1735
|
// bypass the tombstone — re-creation server-side still propagates.
|
|
1736
1736
|
const tombstoneSeq = this.cursor.last_seq;
|
|
1737
1737
|
for (const entity of names) {
|
|
1738
|
+
// Capture cursor BEFORE the fetch so we can detect drift mid-
|
|
1739
|
+
// reconcile. If a WS event lands while this entity is being
|
|
1740
|
+
// pulled, our snapshot is already stale — applying it would
|
|
1741
|
+
// overwrite a newer authoritative row. Skip apply in that case
|
|
1742
|
+
// and rely on the WS event (which has the correct seq) plus the
|
|
1743
|
+
// next reconcile trigger to converge. Codex P1.
|
|
1744
|
+
const cursorBeforeFetch = this.cursor.last_seq;
|
|
1738
1745
|
let serverRows: Row[];
|
|
1739
1746
|
try {
|
|
1740
1747
|
serverRows = await this.fetchEntityRows(entity);
|
|
@@ -1750,6 +1757,15 @@ export class SyncEngine {
|
|
|
1750
1757
|
}
|
|
1751
1758
|
continue;
|
|
1752
1759
|
}
|
|
1760
|
+
if (this.cursor.last_seq !== cursorBeforeFetch) {
|
|
1761
|
+
// Cursor moved during fetch — at least one WS event for this
|
|
1762
|
+
// (or another) entity landed and might have a fresher value
|
|
1763
|
+
// for a row our snapshot just captured. Bail out for this
|
|
1764
|
+
// entity; reconcile() is triggered again on visibility-change
|
|
1765
|
+
// and reconnect, and the WS event already carried the latest
|
|
1766
|
+
// state for the affected row.
|
|
1767
|
+
continue;
|
|
1768
|
+
}
|
|
1753
1769
|
await this.applyEntityReconcile(entity, serverRows, tombstoneSeq);
|
|
1754
1770
|
}
|
|
1755
1771
|
}
|