Skip to content

Newer-version replica admission keeps the stub version, so a later in-order commutative patch folds twice into the stub's indexed fields #3640

Closed

Description

@kriszyp

When a non-owner replica holder has an INVALIDATED stub at version T1 and admits a resident GET_RECORD answer at version T2 > T1 before the T2 replication entry arrives on the stream, storeReplicaRow (resources/Table.ts:11548-11578) stores the resident's T2 record body in the REPLICA row while keeping current.version (T1), current.additionalAuditRefs, and current.receivedIdentityRefs, with indexedRecord: current.value (#3610) so the stub's secondary-index keys stay at T1.

If the T2 write was a commutative patch (saveBeforeAfter: true, such as an add(1) counter increment) on an @indexed attribute, the resident's T2 body already reflects that increment. When the T2 audit entry subsequently arrives on the replication stream in order (entry.version === T2 > current.version === T1):

  1. replicatePatch takes the in-order branch (resources/Table.ts:6248) and reads the REPLICA row via getRecordEntryToUpdate, whose .value is the resident's T2 body (already incremented once).
  2. combineRecords applies the patch delta a second time against that body (count + 2).
  3. putReplicationEntry sees existingEntry.residencyId !== 0 && !this.isResident(residencyList) (resources/Table.ts:6092-6097), demotes the REPLICA row back to an INVALIDATED stub at version T2, and projects the indexed fields from content — writing the double-incremented value into the stub's value and the local secondary index.

Applying the in-order patch against the stub's T1 indexed snapshot (or recording the admitted resident body's version/identity so the in-order delivery of T2 does not re-apply a delta the body already carries) would keep the stub's indexed fields consistent with the resident.

Review-Deferral: e563b9bb7a542363 severity=minor category=data-integrity

🤖 Generated by Google Gemini (Gemini 4 Argon); posted via @kriszyp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

Priority

P2

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions