@harperfast/harper 5.0.30 → 5.0.31

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.
@@ -1623,6 +1623,23 @@ function makeTable(options) {
1623
1623
  // of the updates to the record to ensure consistency across the cluster
1624
1624
  // TODO: can the previous version be older, but even more previous version be newer?
1625
1625
  if (audit) {
1626
+ // A re-delivered out-of-order write (full-copy audit-replay re-delivers writes) must not have
1627
+ // its commutative ops re-folded. additionalAuditRefs is the record's own list of folded
1628
+ // out-of-order versions, read with read-your-writes consistency, so this skips the duplicate up
1629
+ // front — before the audit-log walk below, which can miss it: the walk stops at the depth cap, or
1630
+ // breaks early on a not-yet-visible audit entry, before reaching txnTime, and the keyed
1631
+ // transaction-log lookup it would otherwise use can lag a back-to-back re-delivery (that lag
1632
+ // silently double-applied the increment — #1137). This covers the re-delivery while the ref is
1633
+ // still on the record; a later in-order write rewrites the record and drops the ref (it survives
1634
+ // only as previousAdditionalAuditRefs on the audit log), so that case falls back to the
1635
+ // best-effort keyed lookup in the capped block below — see #1148. precedesExistingVersion(...)
1636
+ // === 0 is the identity tie: same version AND same node (the local node is id 0, so an undefined
1637
+ // options?.nodeId resolves to the same 0 the ref stored).
1638
+ if (existingEntry.additionalAuditRefs?.some((ref) => ref.version === txnTime &&
1639
+ precedesExistingVersion(txnTime, { version: txnTime, localTime: txnTime, key: id, nodeId: ref.nodeId }, options?.nodeId) === 0)) {
1640
+ write.skipped = true;
1641
+ return; // out-of-order write already folded into this record
1642
+ }
1626
1643
  // incremental CRDT updates are only available with audit logging on
1627
1644
  let localTime = existingEntry.localTime;
1628
1645
  let auditedVersion = existingEntry.version;
@@ -1733,8 +1750,12 @@ function makeTable(options) {
1733
1750
  // retained window are not layered in — but the authoritative full-copy record restores exact
1734
1751
  // convergence. Because we stopped before reaching txnTime, the inline duplicate detection in
1735
1752
  // the walk never ran; full-copy audit-replay re-delivers writes, and re-applying one would
1736
- // double-apply its commutative ops, so rule that out here with a single O(1) lookup at txnTime
1737
- // (RocksDB audit logs are keyed by version, and the cap is RocksDB-only).
1753
+ // double-apply its commutative ops. A re-delivered out-of-order write is already ruled out by
1754
+ // the additionalAuditRefs check at the top of this block; this keyed lookup is the best-effort
1755
+ // guard for the remaining case — a re-delivered write that was originally in-order (so it left
1756
+ // no ref) and is now deeper than the cap. It is best-effort because the transaction-log lookup
1757
+ // can intermittently miss an entry under load (tracked separately); the authoritative full-copy
1758
+ // record still restores exact convergence.
1738
1759
  logger_ts_1.logger.warn?.('Out-of-order audit reconciliation exceeded depth cap; reconciling against most recent updates only', {
1739
1760
  table: tableName,
1740
1761
  id,