YSync: Engineering a Custom RGA-Based Sequence CRDT for Real-Time Collaborative Editing
Learn how YSync handles real-time collaborative editing using a custom RGA-based Sequence CRDT. Explore stable element IDs, insertion anchors, Lamport timestamps, deterministic ordering, tombstones, offline synchronization, and out-of-order operations.
YSync: Engineering a Custom RGA-Based Sequence CRDT for Collaborative Editing
#1. The Problem Behind Collaborative Text Editing
YSync is a real-time collaborative text editor built around a custom RGA-based Sequence Conflict-free Replicated Data Type (CRDT). The goal is to let independent replicas make edits, including while disconnected, and later merge those edits into a consistent ordered document.
The interesting engineering problem is not drawing text in an editor. It is preserving the meaning of edits when each replica has only a partial view of what other users have done.
A conventional editor can represent a document as a string or array. That representation is useful for rendering, cursor calculations, and local editing. It is not, by itself, a complete representation of independently generated operations.
Imagine two users starting with AB.
Alice inserts X after A.
Bob inserts Y after A.
Alice's local view becomes AXB.
Bob's local view becomes AYB.
Neither user has made an invalid edit. The replicas simply have different local knowledge. When they exchange their changes, the system must preserve both insertions and determine a stable order for the two new elements.
The final order of X and Y is not inherently
determined by the
characters themselves. A sequence algorithm must
define how concurrent
insertions at the same logical position are ordered.
The essential requirement is that the replicas use the
same rule. If one
replica produces AXYB while another produces AYXB
after both have
received the same operations, the system has not
converged.
This problem becomes more subtle when users delete elements, reconnect after a long offline period, or receive operations in a different order from the order in which those operations were created.
The sequence representation therefore needs to preserve information that a plain array does not contain:
- Which insertion created an element.
- Which existing element served as the insertion anchor.
- Which metadata participates in deterministic sibling ordering.
- Whether an element is logically deleted.
- Whether an operation is waiting for a missing dependency.
- Whether an operation has already been applied.
- How the internal relationships become a visible linear sequence.
These are not independent implementation details. They form one model. Stable identity makes references meaningful. Anchors preserve intended relationships. Ordering rules resolve concurrent siblings. Tombstones preserve references through deletion. Dependency handling allows delayed operations to be integrated safely. Traversal turns the structure into the text the user sees.
#2. What a Replica Means in YSync
A replica is a copy of the relevant document state maintained by a node or client. Replicas may be connected, disconnected, or temporarily aware of different subsets of the operations.
The model matters because independent editing is a deliberate capability. If a user can type only after a central server has accepted every change, the local editing experience is tied to network availability and latency.
With optimistic replication, a replica can apply an edit locally and later exchange that edit with other replicas. The data structure must then define how the independent changes are integrated.
This does not mean networking becomes unnecessary. Replicas still need a way to exchange operations or state. It means the merge semantics do not depend on a central process choosing the order of every concurrent edit.
2.1 Local state is not necessarily global state
At any moment, a replica's visible text represents the operations it has already integrated. It may not include operations that another replica has generated but not yet transmitted.
For example:
Replica A has seen: insert X after A
Replica B has seen: insert Y after ANeither local state is necessarily corrupted. Each state reflects the replica's current knowledge.
The synchronization protocol must eventually deliver the missing operations, and the sequence algorithm must integrate them consistently.
2.2 Concurrency is about causal independence
Two operations are concurrent when neither operation was generated with knowledge of the other. They do not have to execute at precisely the same physical instant.
A user can edit while offline and another user can edit online. Their operations may be concurrent because neither replica observed the other's change before producing its own.
This distinction is important when thinking about timestamps. Physical time can tell us what a local clock displayed, but it does not necessarily tell us which operation knew about which other operation.
2.3 A causal relationship
Suppose Alice changes a document, Bob receives that change, and Bob then makes another edit.
Bob's edit is causally dependent on the update from Alice because Bob had already observed that update.
The fact that Bob observed Alice's operation gives the events a causal relationship. The reverse is not true for two independent offline edits.
2.4 Why delivery order is not causality
Network delivery order is an observation about messages arriving at a receiver. Causality is a relationship between the events that generated those messages.
A receiver can observe operations in an order different from their causal order if the transport does not guarantee causal delivery.
The sequence engine must either rely on an explicit delivery guarantee or represent unresolved dependencies and delay integration until the necessary elements exist.
That is why the insertion anchor is more than a convenience. It gives the receiver a concrete dependency to validate.
#3. Why a Mutable Array Is Not the Whole Model
A JavaScript array is an excellent representation for many local tasks.
const text = ["A", "B", "C"];
text.splice(1, 0, "X");The operation inserts X at the current index 1.
The array updates the
positions of later elements.
The difficulty is that the index describes a location in one current view of the array. It does not identify a logical element across replicas.
Suppose a user creates the operation insert X at index 1. Before that
operation is received elsewhere, another insertion may
shift the local
positions. Index 1 can now refer to a different
logical location.
An operation based only on a mutable index therefore lacks enough information to express the original intent reliably.
3.1 A concrete index example
Start with:
Index: 0 1 2
Value: A B CA local insertion before B changes the visible
positions:
Index: 0 1 2 3
Value: A X B CB is still the same logical element, but its index
has changed from 1
to 2.
If another operation means “insert after B,” an index-only encoding must somehow know which version of the array its index refers to. A stable ID removes that ambiguity by naming the element rather than its current numeric position.
3.2 Indexes remain useful
The conclusion is not that arrays or indexes should never be used.
A text editor still needs a visible sequence and often needs numeric positions for cursor movement, selection ranges, rendering, and user input.
The distinction is between the visible representation and the replicated identity model.
Indexes can be derived from the current visible sequence. They should not be the only durable reference used to merge independent operations.
#4. Stable Element Identity
The sequence model gives each insertion a stable identity. An element can then be referenced independently of its current visible index.
A conceptual identity type is:
type ElementId = {
replicaId: string;
counter: number;
};The replica identifier distinguishes the origin of the element. The counter distinguishes successive elements created by that replica.
This model assumes that replica IDs are unique within the relevant identity scope and that counters do not get reused in a way that creates collisions.
An element's value is not its identity. Two users can insert the same character, and both insertions must remain distinguishable.
Element 1: id = alice:7, value = "X"
Element 2: id = bob:4, value = "X"The values are equal, but the elements represent different insertions.
That distinction is essential for deletion. A deletion must identify the specific element it removes, not every element that happens to contain the same character.
4.1 Identity and position are different fields
A stable ID answers “which element is this?” It does not answer “where does the element belong?”
For that, the insertion records an anchor:
type SequenceElement = {
id: ElementId;
value: string;
after: ElementId | null;
timestamp: number;
deleted: boolean;
};The after field identifies the existing element
after which the new
element was inserted. The null value represents the
root position in this
simplified model.
The timestamp field carries ordering metadata. It
should not be
mistaken for the insertion position.
The deleted field distinguishes an element that
remains structurally
present from one that should be emitted as visible
text.
4.2 A sequence as relationships
For the text ABC, a conceptual chain can be
represented as:
A (a1, after = null)
B (a2, after = a1)
C (a3, after = a2)The structure expresses the insertion relationships:
If X is inserted after A, the new record refers to
A. The existing
IDs for B and C do not need to change merely
because the visible
sequence is updated.
The exact final order depends on the selected RGA sibling-ordering and traversal rules. The important point here is that the insertion's anchor remains stable.
#5. The Three Responsibilities of Insertion Metadata
A distributed insertion needs three logically distinct pieces of information.
| Responsibility | Information | Question answered |
|---|---|---|
| Identity | Element ID | Which insertion is this? |
| Position | Anchor / after | After which element was it inserted? |
| Ordering | Timestamp or ordering key | How are competing siblings ordered? |
These responsibilities should not be collapsed into one field.
5.1 The anchor preserves intent
Suppose the document contains A → B → C and a user
inserts X after
B.
The anchor records the intended logical neighborhood:
A → B → X → CSorting every element globally by timestamp would not preserve this relationship. A newly generated timestamp might be larger than all the others, but that does not mean the character belongs at the end.
5.2 The ordering key resolves ambiguity
If two elements share the same anchor, the anchor alone does not tell the receiver which sibling should appear first.
A
/ \
X YThe implementation must define a deterministic sibling-ordering rule. It might compare stable IDs, logical timestamps, or a combination of metadata. The chosen rule must be applied consistently on every replica.
5.3 Identity prevents accidental merging
The visible character X cannot be used as the unique
key for an
insertion. Multiple users can insert the same
character, and a user can
insert the same character more than once.
Unique identity allows the implementation to distinguish those events, recognize duplicate delivery, and target a particular element for deletion.
#6. Lamport Timestamps
A Lamport timestamp is a logical counter used to capture ordering relationships between events without relying on synchronized physical clocks.
A local clock can be advanced as follows:
let clock = 0;
function nextTimestamp() {
clock += 1;
return clock;
}When a replica observes a remote logical timestamp, it can update its clock using the Lamport rule:
function nextTimestamp(remoteClock) {
clock = Math.max(clock, remoteClock) + 1;
return clock;
}The second example assumes the remote timestamp is available and relevant to the event being generated. A complete implementation must define how it extracts that value from remote operations and how it handles batches.
6.1 What the clock tells us
If event A causally precedes event B, the Lamport clock rules ensure that A's timestamp is lower than B's timestamp.
For example, Alice creates an operation at logical
time 1. Bob receives
it and then creates an operation. Bob advances his
clock beyond the
observed value.
The resulting order reflects the fact that Bob observed Alice's event.
6.2 What the clock does not tell us
The converse is not guaranteed. A larger timestamp does not prove that the event with the larger timestamp observed the other event.
Alice can generate an operation at timestamp 3,
while Bob independently
generates an operation at timestamp 7 without
receiving Alice's
operation. Bob's event has a larger timestamp, but the
operations remain
concurrent.
This matters because timestamp order and causal order are not identical concepts.
6.3 Why physical time is not a complete solution
Using Date.now() as the primary ordering mechanism
creates several
problems. Client clocks may differ, clock adjustments
can move time
backward, and two operations can receive the same
timestamp.
A wall-clock timestamp also does not establish that one replica had observed another replica's operation.
Logical clocks avoid depending on synchronized physical clocks for their logical ordering guarantees. They still need a deterministic tie-breaker when the algorithm requires a total ordering among events with equal logical timestamps.
6.4 A possible ordering key
A conceptual key can contain a logical timestamp and replica identifier:
type OrderingKey = {
timestamp: number;
replicaId: string;
};
type Operation = {
timestamp: number;
replicaId: string;
};
function compare(a: Operation, b: Operation): number {
if (a.timestamp !== b.timestamp) {
return a.timestamp - b.timestamp;
}
return a.replicaId.localeCompare(b.replicaId);
}This comparator demonstrates one deterministic tie-breaking strategy. It is not, by itself, a complete RGA algorithm.
The full algorithm must define how sibling order interacts with descendant relationships and how traversal converts the structure into a linear sequence.
Some RGA implementations use insertion IDs directly to order siblings rather than using a separate Lamport timestamp. The notes identify these as design alternatives; the actual YSync choice should be documented from the implementation.
#7. Vector Clocks and Causal Relationships
A vector clock maintains a separate counter for each replica. It can represent more information about causal relationships than a single Lamport timestamp.
Suppose replicas A and B begin with:
{A: 0, B: 0}Replica A performs an operation:
{A: 1, B: 0}B observes that operation and then performs another operation:
{A: 1, B: 1}The vector records that B's event was created after B observed A's event.
If A and B instead generate operations independently, their vectors can show that neither event causally precedes the other.
Lamport timestamps provide a logical ordering that respects causality. Vector clocks can distinguish causal relationships from concurrency under the assumptions of the vector-clock scheme.
A sequence CRDT does not automatically need vector clocks. The required metadata depends on the algorithm and protocol. The key is to avoid claiming that a timestamp alone proves causal knowledge.
#8. CRDTs in the Larger Distributed-Systems Context
A Conflict-free Replicated Data Type is designed to let replicas integrate updates according to defined rules and eventually converge under the appropriate delivery assumptions.
CRDTs are relevant to distributed storage and multi-user applications, but they are not the only mechanism used in distributed systems.
8.1 Partitioning and sharding
Partitioning splits a large dataset into smaller parts. Sharding commonly refers to distributing those parts across multiple machines.
These techniques distribute data and work. They do not, by themselves, define how two concurrent edits to the same sequence should be merged.
8.2 Replication and availability
Replication keeps copies of data on multiple nodes. It can improve availability and fault tolerance, but independently modified copies need a strategy for reconciling updates.
A collaborative editor is one example of replicated state. The same general issue appears in distributed databases and mobile applications that allow local updates before synchronization.
8.3 Consensus and leader-based coordination
Consensus algorithms such as Raft and Paxos help distributed nodes agree on values or ordering decisions despite certain failures.
A leader-based system may direct writes through a leader, which coordinates replication with followers. If the leader fails, the system may need to elect a new one according to its consensus protocol.
That architecture solves a different problem from an optimistic, coordination-free sequence CRDT.
Consensus can be appropriate when a system requires an agreed ordering or strong consistency. A CRDT can be appropriate when replicas need to make local changes independently and reconcile them later.
Neither approach should be described as universally better. The choice depends on the system's consistency requirements, latency constraints, failure model, and offline behavior.
8.4 Strong consistency and its cost
Strongly coordinated replication can provide guarantees such as linearizability or support serializable transactions when implemented with the required protocols and storage semantics.
Linearizability means operations appear to take effect in a single real-time-respecting order. Serializable transactions mean concurrent transactions have an outcome equivalent to some serial execution.
These guarantees do not follow merely from replicas exchanging acknowledgements. They depend on the complete protocol and system design.
Coordination can add latency and may prevent progress when required participants are unavailable. That is one reason an offline-first editor may prefer local operations and later reconciliation for document edits.
8.5 Optimistic replication
Optimistic replication allows replicas to update local state without waiting for every other replica to participate.
It is well suited to low-latency and offline workflows, but independent updates still need well-defined merge semantics.
A CRDT supplies those semantics for the data type it implements. It does not guarantee that every application-level intention is semantically compatible, nor does it replace transport, persistence, authentication, or authorization.
#9. State-Based and Operation-Based CRDTs
CRDT designs are commonly divided into state-based and operation-based families.
A state-based CRDT communicates state. A receiving replica merges the incoming state with its own state using a merge function designed for convergence.
An operation-based CRDT communicates changes. Replicas exchange operations and apply them to their local state.
Operation-based designs can avoid repeatedly transmitting the entire state for every edit, but their correctness depends on operation semantics and delivery assumptions.
The notes describe YSync in terms of insertion and deletion operations. The exact transport protocol and all delivery guarantees should be verified against the implementation before describing it as a complete operation-based CRDT protocol.
#10. RGA: Replicated Growable Array
RGA is a sequence CRDT algorithm for maintaining an ordered collection across replicas that may edit concurrently.
It replaces mutable array positions with stable element identities, insertion relationships, and deterministic ordering rules.
The word “replicated” describes the fact that each replica maintains its own copy of the sequence state. The word “growable” describes the ability to insert new elements dynamically; it does not mean that deletion is unsupported.
10.1 A simple insertion
Suppose the document contains AB.
Alice inserts X after A. The operation identifies
the new element and
records A as the anchor.
type InsertOperation = {
type: "insert";
id: string;
after: string | null;
value: string;
timestamp: number;
};
const operation: InsertOperation = {
type: "insert",
id: "alice:3",
after: "a1",
value: "X",
timestamp: 3,
};This is an illustrative operation format. The
identifier "a1" is
assumed to be the stable ID for the existing element
A.
The receiving replica must interpret the after field
as a relationship,
not as a numeric array index.
10.2 Concurrent insertions after the same element
Suppose Alice and Bob both insert after A without
observing each
other's operation.
Alice: X after A
Bob: Y after ABoth insertions are children of the same anchor in the conceptual relationship structure.
The algorithm must order those siblings deterministically. A receiver must not simply append each newly received sibling in message-arrival order, because different replicas could receive the operations in different orders.
The ordering rule can use stable IDs or another defined ordering key. The exact choice belongs to the chosen RGA variant.
10.3 Insertions after different anchors
If one operation inserts X after B and another
inserts Y after C,
the anchors preserve the distinct logical
relationships.
Initial: A → B → C → D
Insert X: X after B
Insert Y: Y after CThe local views may differ temporarily, but the operations retain enough information for the replicas to integrate them according to the algorithm's rules.
10.4 Convergence depends on the complete algorithm
Stable IDs do not guarantee convergence by themselves.
The implementation also needs:
- A consistent sibling-ordering rule.
- A consistent traversal rule.
- Correct handling of duplicate operations.
- A policy for missing anchors.
- Deletion semantics that preserve required relationships.
- Safe treatment of malformed operations and invalid structures.
The result is a coordinated set of invariants rather than one isolated trick.
#11. Tombstones and Logical Deletion
In an ordinary array, deleting B from ABC can
physically remove the
element.
In an RGA-style structure, the element may still be referenced by other operations. Removing it immediately can destroy the anchor that those operations require.
The usual conceptual solution is a tombstone.
Internal structure: A → B(deleted) → C
Visible text: ACThe element remains in the internal structure but is skipped when rendering visible text.
11.1 Why the tombstone matters
Suppose Alice deletes B, while Bob concurrently
inserts X after B.
If the system retains B as a tombstone, it can still
interpret Bob's
insertion relative to the original anchor.
The visible result shown by the conceptual example is
AXC. The precise
linear order must follow the selected RGA variant's
rules.
The important distinction is that logical deletion changes visibility without necessarily removing the element's structural identity.
11.2 Rendering and traversal are separate
A simplified visibility function can operate on a sequence that is already in logical order:
function visibleText(elements: SequenceElement[]) {
return elements
.filter((element) => !element.deleted)
.map((element) => element.value)
.join("");
}This code is not a complete traversal algorithm. It assumes the input list has already been reconstructed correctly.
The traversal must still visit descendants of a deleted node. Filtering a tombstone out of the final visible string must not remove its descendants from the structural traversal.
11.3 Tombstone garbage collection
Tombstones consume memory and can increase the amount of metadata the system retains.
However, deleting a tombstone is safe only when the system can establish that no relevant replica or outstanding operation still depends on that identity.
A fixed timeout is not generally sufficient. A replica may remain offline longer than expected and later return with operations referencing an old anchor.
Safe garbage collection therefore depends on the synchronization and recovery protocol, not merely on the age of a deleted record.
The diagram describes a conceptual lifecycle. The exact safety conditions for YSync's garbage collection must be established by its implementation and synchronization protocol.
#12. Out-of-Order Delivery and Pending Dependencies
A distributed system may deliver an insertion before the operation that created its anchor.
For example:
Operation 1: insert C after B
Operation 2: insert B after A
Operation 3: insert A at rootA replica receiving operation 1 cannot yet attach C
to B if B does
not exist in its local state.
That does not necessarily make the operation invalid. Its dependency may simply be delayed.
12.1 Buffer instead of silently discarding
A naive implementation might throw an error:
if (!elements.has(operation.after)) {
throw new Error("Missing anchor");
}The check protects the data structure from an invalid immediate insertion, but it does not handle a valid operation whose dependency has not arrived yet.
One approach is to maintain a pending queue.
The implementation must define how pending operations are indexed and retried. The diagram describes the conceptual flow, not a claim about a specific queue implementation.
12.2 Dependency resolution
For the example sequence, the replica first buffers
C because B is
missing. It then buffers B because A is missing.
When A arrives, the replica can integrate B, then
resolve C after
B becomes available.
This preserves the relationships required by the insertion model.
12.3 Other valid approaches
Explicit buffering is not the only design.
A system can store unresolved elements and resolve their anchors later, provided traversal and validation safely handle incomplete structures.
Alternatively, the transport protocol can enforce causal delivery so that dependencies are delivered before dependent operations are applied.
That shifts complexity into the protocol and its buffering logic.
The right choice depends on the protocol guarantees. If the protocol does not guarantee causal delivery, the sequence engine must safely represent operations whose dependencies are missing.
12.4 A useful invariant
For every insertion that the system has accepted:
- The ID must be unique.
- The anchor must exist, or the operation must remain explicitly unresolved.
- Reapplying the same operation must not create a duplicate element.
- Once dependencies are resolved, the operation must be integrated using the same ordering rules as every other replica.
This invariant gives the implementation a clear contract for delayed messages.
#13. A Map-Based Representation
A simple internal representation can use two maps:
type ElementId = string;
type SequenceElement = {
id: ElementId;
value: string;
after: ElementId | null;
timestamp: number;
deleted: boolean;
};
type SequenceState = {
elements: Map<ElementId, SequenceElement>;
children: Map<ElementId | null, ElementId[]>;
};The elements map supports lookup by stable ID. The
children map
records which elements were inserted after each
anchor.
The two structures serve different purposes.
The element map makes it practical to find a record by ID without scanning every stored element. A hash map typically offers expected O(1) lookup.
The children map lets traversal retrieve the children
of an anchor
without scanning all elements and checking each
after field.
13.1 Structural invariants
If children.get("a1") contains "b1", then:
- The element record for
"b1"must exist. - Its
afterfield must refer to"a1". - Its ID must be unique.
- It must be represented consistently in the structure.
If the maps disagree, traversal can omit elements, visit elements incorrectly, or reconstruct an invalid sequence.
The implementation must keep the maps synchronized during insertion, deletion, duplicate handling, persistence, and recovery.
13.2 Complexity
Let n be the number of stored elements and k the
number of siblings
under an anchor.
Expected hash-map lookup is O(1).
Appending to an unsorted child array is amortized O(1).
Inserting into a sorted sibling array may require O(k) work because elements may need to be shifted.
A complete traversal is O(n) if each stored element is visited once and sorting work is excluded.
If the algorithm sorts child lists during traversal, the actual cost also depends on the distribution of sibling counts and the sorting strategy.
These are complexity estimates for the conceptual representation, not benchmarks of YSync.
13.3 Why the simplest structure may not scale
indefinitely
A map and child arrays are relatively easy to reason about. They make identity lookup and insertion relationships explicit.
For large documents, the implementation may need a more efficient ordered tree or indexed sequence structure, especially if it frequently calculates visible positions or repeatedly reconstructs the full text.
The right optimization depends on measured workloads. It should not be assumed that a more complicated structure is automatically better.
#14. Reconstructing the Visible Sequence
The internal representation is a relationship structure. The editor needs a linear sequence of visible characters.
A conceptual traversal begins at the root, visits children in deterministic order, emits visible values, and continues through descendants.
The traversal must not stop at a tombstone. A deleted element can still have descendants that belong in the visible document.
This diagram is conceptual. A concrete implementation must define the actual traversal order, avoid cycles, and handle malformed relationships.
14.1 Example structure
Consider these relationships:
Root
└── A
├── B
│ └── C (deleted)
│ └── D
│ └── F
└── X
├── Y
└── Z (deleted)If the child arrays are already ordered and the implementation uses parent-first depth-first traversal, the visible output depends on that specific ordering.
The deleted values are skipped, but their descendants are still visited.
The example demonstrates the distinction between internal structure and visible output. It should not be taken as a universal output order for every RGA variant.
14.2 Traversal safety
A malformed relationship graph could contain a cycle or an element linked inconsistently. A traversal that assumes every structure is valid can loop indefinitely or visit an element multiple times.
The sequence engine should validate incoming operations and preserve its structural invariants. Traversal should also have a safe strategy for detecting malformed or cyclic state.
#15. Deletion Targets and Stable References
Deletion must identify a specific element, not a current array index.
Suppose two replicas contain elements with the visible
value X:
alice:7 → "X"
bob:4 → "X"Deleting one element must not accidentally delete the other just because their values match.
The same principle applies when surrounding insertions change the visible positions. The stable ID remains the reference used to identify the target.
A deletion operation's exact wire format is not established by the conceptual model here. What matters is that its target be unambiguous and that repeated application does not create inconsistent state.
15.1 Concurrent insertion and deletion
A deletion and an insertion may affect the same region of the sequence. The tombstone preserves the deleted element's identity so that an insertion anchored to it can still be interpreted.
This does not mean every concurrent edit has an obvious human-level meaning. It means the data structure retains the information needed to apply the algorithm's defined semantics.
15.2 Deleted does not mean forgotten
Logical deletion is a state of an element. Garbage collection is a later decision to remove metadata.
Conflating the two makes it difficult to reason about operations that arrive late or refer to historical anchors.
The implementation should document the conditions under which tombstones can be removed and what assumptions the synchronization protocol makes about offline replicas and outstanding operations.
#16. Idempotency and Duplicate Operations
An operation can be delivered more than once. A client may retry a send, a synchronization process may replay history, or a transport may provide at-least-once delivery.
The sequence engine must ensure that applying the same insertion twice does not create two elements.
Stable IDs support this by giving the receiver a way to recognize an insertion that has already been applied.
However, a duplicate ID with a different payload is not necessarily a valid duplicate. The implementation should not silently replace an existing element's value or anchor merely because the ID matches.
The ID represents one logical insertion. Conflicting payloads should be handled according to an explicit validation policy.
16.1 Idempotency flow
The diagram expresses a desired integration flow. The precise error handling and persistence semantics must be verified against the actual implementation.
#17. Correctness Properties
A sequence CRDT should be evaluated against invariants, not just a few successful examples.
17.1 Convergence
Replicas that eventually receive the same valid operation set must reconstruct the same visible sequence under the algorithm's assumptions.
17.2 Unique identity
Every insertion must have a unique ID within the relevant scope.
Two equal character values do not imply that the elements are the same.
17.3 Idempotency
Repeated application of the same operation must not duplicate its effect.
17.4 Anchor integrity
An element must reference a valid anchor or remain explicitly unresolved until the dependency becomes available.
17.5 Deterministic ordering
All replicas must apply the same ordering and traversal rules, regardless of message arrival order.
17.6 Deletion consistency
Deleted elements must not appear in visible text, while structural relationships needed by other operations remain available.
17.7 Offline synchronization
Local operations created while disconnected must be integrated correctly after reconnection, including duplicate delivery and unresolved dependencies allowed by the protocol.
17.8 Safe traversal
Traversal must handle deep nesting and reject or safely handle malformed relationships, including cycles and inconsistent parent-child links.
These properties are useful because they remain relevant as the code changes. They describe the behavior the implementation must preserve, rather than the internal shape of one particular function.
#18. Testing Strategy
Testing a sequence CRDT requires deliberately varying operation history and delivery order.
A test that inserts one character into an empty sequence checks only a small part of the problem. The difficult cases involve concurrent edits, deletion, duplicate delivery, and dependencies that arrive late.
18.1 Basic insertion tests
Start with a sequence containing AB.
Insert X after A.
Verify that the resulting order matches the algorithm's defined sibling ordering and traversal semantics.
Do not hard-code a universal RGA ordering unless the chosen variant actually specifies it.
18.2 Concurrent sibling tests
Create two independent operations:
X after A
Y after AApply them to one replica in the order X then Y, and to another replica in the order Y then X.
After both replicas have received the same valid operations, compare their visible sequences.
The test should verify convergence, not merely assert one order without establishing the ordering rule.
18.3 Deletion tests
Create A → B → C, then delete B.
Verify that B is omitted from visible output and
that its structural
relationships remain available where required.
Add a descendant under the tombstone and verify that traversal still reaches that descendant.
18.4 Missing-anchor tests
Deliver C after B before the operation creating B.
Verify that the operation is not silently lost and is not applied against an invalid anchor.
Then deliver the missing dependencies and verify that the pending operation is integrated.
18.5 Duplicate-delivery tests
Apply an insertion twice.
Verify that the element is not duplicated.
Then test a conflicting payload that reuses an existing ID. Verify that the implementation follows its explicit conflict policy rather than silently changing the existing element.
18.6 Property-based tests
Property-based testing can generate operation histories, distribute them across replicas, randomize delivery order within the protocol's allowed constraints, and check invariants.
A useful generated history includes insertions, deletions, duplicate operations, and dependencies that arrive after their dependents.
The test should create multiple replicas, let each integrate a subset of operations, then deliver the remaining operations and compare the final visible sequences.
If the protocol requires causal delivery, generated tests should respect that requirement or separately test the buffering behavior designed to handle reordering. Tests should not confuse a protocol violation with a failure of an algorithm that assumes a particular delivery guarantee.
18.7 Suggested edge-case matrix
| Case | Behavior to verify |
|---|---|
| Concurrent insertions at one anchor | Deterministic sibling order |
| Insert after a tombstone | Anchor remains interpretable |
| Duplicate insertion | No duplicate element |
| Duplicate ID with conflicting payload | Explicit validation behavior |
| Missing anchor | Pending or unresolved state is preserved |
| Dependency arrives late | Pending operation eventually resolves |
| Deep insertion chain | Traversal terminates and preserves order |
| Empty sequence | Root insertion is handled |
| Delete first element | Visible sequence is reconstructed correctly |
| Delete last element | Visible sequence is reconstructed correctly |
| Repeated deletion | State remains consistent |
| Cyclic or malformed structure | Traversal fails safely |
| Reordered delivery | Convergence under allowed delivery rules |
This matrix is a proposed testing plan based on the documented correctness requirements. It is not a report of tests that have already passed.
#19. Performance and Representation Trade-offs
The map-based TIL model is useful because it separates identity lookup from ordering relationships.
The element map gives the implementation a direct way to find a record. The child map makes traversal easier because it avoids scanning all elements for every anchor.
The cost is that the two structures must remain consistent.
A simple array of children is easy to implement, but
sorting siblings may
cost O(k) for insertion into a sorted array, where k
is the number of
siblings under an anchor.
A complete traversal is O(n) when every element is visited once and additional sorting costs are excluded.
For large documents, a more sophisticated ordered structure may improve performance, but the right choice depends on document size, insertion distribution, and how often the application needs to calculate positions.
19.1 Avoid premature performance claims
Complexity estimates describe the operations performed by the data structure under stated assumptions. They are not empirical performance measurements.
Actual performance depends on the runtime, memory layout, document shape, sorting strategy, and workload.
The supplied notes do not establish benchmark numbers for YSync's TIL implementation, so this article does not claim specific latency, throughput, or memory improvements.
19.2 Metadata is part of the cost
Stable identities, insertion anchors, timestamps, and tombstones consume more memory than a plain array of characters.
That metadata is not accidental overhead. It carries the information needed to merge independent operations.
The engineering challenge is to preserve the metadata required for correctness while defining safe policies for cleanup and efficient structures for lookup and traversal.
#20. Comparing Sequence CRDT Approaches
Several sequence CRDT families use different strategies to represent position and resolve concurrent insertion.
| Design | General idea | Trade-off described in the notes |
|---|---|---|
| RGA-style TIL | Stable IDs, anchors, deterministic ordering | Tombstones and traversal complexity |
| Logoot / LSEQ | Position identifiers between neighboring elements | Identifier allocation and growth |
| WOOT | Preserve element relationships and resolve concurrent insertion | More involved integration and ordering |
| Yjs sequence types | Optimized internal structures for collaborative data | More internal algorithmic complexity |
These designs are not interchangeable implementations of the same internal representation.
An anchor-based model expresses insertion relationships through element references. A position-identifier design uses identifiers intended to represent positions between neighboring elements.
A custom implementation should be evaluated on its requirements, correctness, complexity, and maintenance burden rather than assuming that a home-grown algorithm automatically outperforms an established library.
The TIL model makes identity, anchor, timestamp, and deletion state explicit. That helps explain the sequence semantics, but it does not automatically inherit the optimizations or correctness properties of another library.
#21. What the CRDT Does Not Provide
A CRDT defines how accepted operations are integrated. It does not automatically implement the entire collaborative application.
The application still needs a synchronization protocol, persistence, reconnection behavior, input validation, and access control.
21.1 Transport
The system needs a way to exchange operations or state between replicas. The sequence algorithm cannot recover an operation that is permanently lost and never replayed or otherwise recovered.
21.2 Persistence
If document state must survive process restarts, the stored representation must preserve the information needed to resume synchronization correctly. Saving only the visible text may not preserve the identities and anchors needed to interpret future operations.
The exact YSync persistence format is not specified by the conceptual TIL schema alone.
21.3 Recovery
A replica returning after a long offline period may have operations that other replicas have not seen. The recovery protocol must determine how those operations are exchanged and how missing dependencies are resolved.
21.4 Authorization
Convergence is not authorization. A CRDT can integrate an operation correctly even if the application should not have accepted that operation from the sender.
Authentication and document permissions remain separate concerns.
21.5 Garbage collection
Tombstone cleanup requires knowledge about outstanding dependencies and the synchronization protocol. It is not safely solved by deleting old records after an arbitrary timeout.
#22. Engineering Lessons
The sequence model reinforces several practical lessons.
First, stable identity and mutable position are different concepts. Indexes are useful views of the current sequence, but they are not reliable durable references across independent edits.
Second, insertion anchors and ordering keys solve different problems. An anchor preserves the intended neighborhood. A deterministic ordering rule resolves ambiguity among concurrent siblings.
Third, logical deletion is not the same as physical removal. Tombstones preserve the identities and relationships needed to integrate operations that may still refer to deleted elements.
Fourth, delivery behavior belongs in the correctness model. If operations can arrive more than once or before their dependencies, the implementation must account for those cases explicitly.
Fifth, traversal is part of the algorithm. The internal relationship structure does not become a visible string until a precise ordering and traversal policy is applied.
Sixth, correctness claims should be tied to evidence. A list of desired invariants is not proof that every operation history has been tested. A conceptual schema is not a complete production implementation. A convergence guarantee depends on both the algorithm and its delivery assumptions.
Finally, the simplest data structure that makes the invariants explicit is often the best starting point. More sophisticated indexing can be introduced when real workloads justify it, without weakening the underlying semantics.
#Conclusion
YSync's custom RGA-based sequence model begins with a simple observation: a character's array index is not a stable identity in a distributed document.
A collaborative sequence needs to preserve element identity, insertion relationships, ordering metadata, deletion state, and unresolved dependencies. Those pieces allow independent replicas to integrate changes without depending on message-arrival order to determine the document's final structure.
Stable IDs make operations refer to specific elements. Anchors preserve logical insertion relationships. Deterministic sibling ordering resolves concurrent insertions. Tombstones retain structural references after deletion. Causal buffering allows operations to wait for missing anchors. Traversal converts the internal relationships into visible text.
None of these mechanisms replaces the others. An anchor does not define sibling order. A timestamp does not define insertion position. A tombstone does not prove that garbage collection is safe. A deterministic traversal does not recover an operation that was never delivered.
The sequence engine is therefore best understood as a collection of interlocking invariants rather than a clever way to insert characters.
That perspective is useful beyond text editing. Any replicated ordered collection must decide how to identify elements, express position, order concurrent changes, handle deletion, and recover from incomplete knowledge. Making those decisions explicit is the foundation for a system that can continue accepting local work and reconcile it later.
Appendix A: Mermaid Diagram Gallery
The following diagrams can be reused independently in a technical blog. They represent conceptual behavior from the notes, not an assertion that every component is implemented exactly as shown.
#A.1 End-to-end conceptual operation flow
#A.2 Concurrent insertion
#A.3 Element identity and anchor
The IDs identify elements. The edges represent insertion relationships. The order in which siblings and descendants are traversed is determined by the selected sequence algorithm.
#A.4 Tombstone lifecycle
#A.5 Dependency resolution
#A.6 Visible sequence reconstruction
Appendix B: Operation Examples
These examples illustrate the concepts from the notes. They are not complete production operation handlers.
#B.1 Insertion record
type ElementId = string;
type InsertOperation = {
type: "insert";
id: ElementId;
after: ElementId | null;
value: string;
timestamp: number;
};The operation contains an identity, anchor, value, and timestamp. The timestamp is ordering metadata; the anchor expresses position.
#B.2 Deletion record
The notes establish that deletion should target a stable element identity and that a deleted element may be retained as a tombstone.
A complete deletion wire format is not specified here. The essential semantic requirement is that deletion identify the intended element rather than a mutable array index.
#B.3 Element lookup
type SequenceElement = {
id: ElementId;
value: string;
after: ElementId | null;
timestamp: number;
deleted: boolean;
};
type SequenceState = {
elements: Map<ElementId, SequenceElement>;
children: Map<ElementId | null, ElementId[]>;
};The maps divide identity lookup from relationship traversal.
#B.4 Visible text from an ordered list
function visibleText(elements: SequenceElement[]) {
return elements
.filter((element) => !element.deleted)
.map((element) => element.value)
.join("");
}This function assumes the elements are already in the correct logical order. It does not perform sequence reconstruction.
Appendix C: Proposed Correctness Test Catalog
This catalog expands the test categories in the notes into individual test intentions. These are proposed tests, not claims about existing test results.
#C.1 Identity tests
- Create one insertion and verify its ID is retained.
- Create two insertions with equal values and different IDs.
- Verify that equal values do not collapse into one element.
- Attempt to reuse an existing ID with the same payload.
- Attempt to reuse an existing ID with a conflicting payload.
- Verify that the implementation applies its explicit duplicate policy.
- Verify that counters do not move backward within a replica.
- Verify that restored identity state does not accidentally reuse IDs.
- Verify that the ID scope is defined for the relevant document.
- Verify that element lookup returns the correct record by ID.
#C.2 Anchor tests
- Insert after an existing element.
- Insert at the root.
- Insert after the last visible element.
- Insert after an element whose visible position has changed.
- Insert after an element that has been logically deleted.
- Deliver an insertion before its anchor.
- Deliver the anchor after the insertion.
- Verify that unresolved operations remain tracked.
- Verify that a resolved operation is attached to the correct anchor.
- Verify that every child record agrees with its
afterfield.
#C.3 Ordering tests
- Insert two siblings with distinct ordering keys.
- Insert two siblings with equal timestamps.
- Verify the tie-breaker is deterministic.
- Deliver siblings in one order to replica A.
- Deliver the same siblings in reverse order to replica B.
- Compare the resulting visible sequences.
- Add descendants under the first sibling.
- Add descendants under the second sibling.
- Verify traversal follows the documented variant.
- Verify that timestamps are not used as a global positional sort.
#C.4 Deletion tests
- Delete an element from the middle of the sequence.
- Delete the first visible element.
- Delete the last visible element.
- Delete an element with descendants.
- Verify that descendants remain traversable.
- Verify that the tombstone's value is not rendered.
- Deliver an insertion that references the tombstone.
- Apply the same deletion twice.
- Verify that repeated deletion does not corrupt the structure.
- Verify that tombstone metadata remains until GC is safe.
#C.5 Delivery tests
- Deliver an operation once.
- Deliver the same operation twice.
- Deliver operations in causal order.
- Deliver operations in reverse order where buffering permits it.
- Deliver a child insertion before its parent insertion.
- Deliver several levels of dependencies out of order.
- Verify that pending dependencies are retried.
- Verify that unrelated operations can still be processed when safe.
- Verify that unresolved operations are not silently discarded.
- Verify that the final state converges after all dependencies arrive.
#C.6 Traversal tests
- Traverse a simple chain.
- Traverse two siblings.
- Traverse siblings with descendants.
- Traverse a branch containing a tombstone.
- Traverse multiple tombstones.
- Traverse an empty sequence.
- Traverse a root with multiple children.
- Verify each reachable element is visited according to the rules.
- Verify malformed relationships are detected or handled safely.
- Verify cyclic structures cannot cause infinite traversal.
#C.7 Replica convergence tests
- Initialize two replicas with the same sequence.
- Generate an insertion on replica A.
- Generate a concurrent insertion on replica B.
- Exchange the operations.
- Compare visible sequences.
- Repeat with reversed delivery order.
- Add a deletion on one replica.
- Add an insertion on another replica.
- Exchange the operations and compare the final states.
- Repeat the history with duplicate operation delivery.
- Repeat with an offline replica returning later.
- Verify the same valid operation set yields the same final sequence.
- Verify the protocol assumptions used by each test are explicit.
- Verify invalid operations are not included as if they were valid history.
- Verify a failure report distinguishes convergence failure from invalid input.
Appendix D: Glossary
Anchor: The existing element after which a new element is inserted.
Availability: The ability of a system to continue responding despite certain failures.
Causal dependency: A relationship in which one operation was generated after observing another operation or its effect.
Concurrent operations: Operations for which neither was generated with knowledge of the other.
Convergence: The property that replicas receiving the same valid operation set eventually reconstruct the same logical state under the algorithm's assumptions.
CRDT: A Conflict-free Replicated Data Type whose merge or operation semantics support convergence under defined conditions.
CvRDT: A state-based CRDT that communicates and merges state.
CmRDT: An operation-based CRDT that communicates operations.
Element ID: A stable identity for one insertion or sequence element.
Garbage collection: Removal of metadata that is no longer needed and can be removed without breaking correctness.
Lamport timestamp: A logical counter that respects causal ordering implications but does not independently prove causal dependence.
Linearizability: A consistency property under which operations appear to take effect in a single order that respects real-time constraints.
Optimistic replication: A replication strategy in which replicas apply local changes without waiting for all other replicas to coordinate first.
Replica: A copy of the relevant state maintained by a node or client.
Sequence CRDT: A CRDT designed for ordered collections where element position and relative ordering matter.
TIL: Timestamped Insertion List, the descriptive name used in the supplied notes for the stable-element, anchor, and ordering-metadata model.
Tombstone: A logically deleted element retained internally because its identity or relationships may still be needed.
Vector clock: A logical clock containing a counter for each replica, used to reason about causal relationships.
Technical Review Notes
-
TIL naming: Verify whether Timestamped Insertion List is the official name of the implemented structure or a descriptive model used in the notes.
-
Sibling ordering: The source material mentions stable IDs, timestamps, and replica IDs as possible ordering inputs. The actual implementation must specify the chosen comparator and its relationship to traversal.
-
RGA traversal: The exact traversal convention must match the chosen RGA variant. A generic depth- first traversal should not be presented as universal behavior for every implementation.
-
Lamport timestamps: Confirm how YSync updates its logical clock when remote operations are received and how timestamp ties are handled.
-
Causal buffering: Confirm whether the implementation uses a pending queue, unresolved- element storage, causal delivery, or another mechanism.
-
Duplicate IDs: Confirm the behavior for an existing ID received with a different payload.
-
Garbage collection: The notes explain why tombstones need safe cleanup but do not establish a complete GC protocol.
-
Persistence and transport: The conceptual sequence model does not specify the complete durable storage format or network protocol.
-
Complexity: The stated complexity estimates apply to the conceptual map-and-child-list representation under the stated assumptions. They are not benchmark results.
-
Testing: The test catalog is proposed coverage based on the supplied correctness requirements. It does not claim that those tests have already been run or passed.
Appendix E: Expanded Test Scenarios
The following scenarios turn the correctness requirements into concrete test intentions. They are deliberately written as proposed coverage. They are not evidence that these tests already exist or have passed.
Each scenario identifies a starting condition, an action, and an expected property. A real test suite should encode the property using the actual YSync operation format and its documented protocol rules.
#E.1 Empty document accepts a root insertion
Setup: The initial state has no elements.
Action: Insert the first element with a null anchor.
Expected property: The element becomes reachable from the root and visible once.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.2 A second element anchors to the first
Setup: The sequence contains one root element.
Action: Insert another element after the root element.
Expected property: The second element references the first element's stable ID.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.3 A third element preserves the chain
Setup: The sequence contains two linked elements.
Action: Insert a third element after the second.
Expected property: The anchor relationships reconstruct the original chain.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.4 Equal values retain distinct identities
Setup: Two clients can insert the same character.
Action: Create two insertions with different unique IDs and equal values.
Expected property: Both elements remain distinct in the internal state.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.5 Different values retain distinct identities
Setup: Two insertions use different values.
Action: Insert both values with independent IDs.
Expected property: Each record is addressable by its own ID.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.6 An insertion does not renumber existing IDs
Setup: The sequence contains several identified elements.
Action: Insert a new element before an existing visible element.
Expected property: Existing element IDs remain unchanged.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.7 An anchor survives visible-position changes
Setup: An anchor element has moved to another visible index.
Action: Insert a new element after its ID.
Expected property: The operation still targets the same logical anchor.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.8 A sibling does not overwrite another sibling
Setup: Two insertions use the same anchor.
Action: Integrate both operations.
Expected property: Both element records are retained.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.9 Sibling ordering is independent of delivery order
Setup: Two concurrent sibling operations exist.
Action: Deliver them in opposite orders to two replicas.
Expected property: Both replicas apply the same deterministic order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.10 A timestamp tie uses a stable tie-breaker
Setup: Two siblings have equal timestamps.
Action: Compare their ordering metadata.
Expected property: The documented tie-breaker selects a reproducible order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.11 A timestamp is not treated as a global position
Setup: An insertion is anchored in the middle of a sequence.
Action: Give the insertion a timestamp larger than older elements.
Expected property: The anchor relationship still determines its logical neighborhood.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.12 A larger Lamport value does not imply observed causality
Setup: Two replicas generate independent operations.
Action: Assign different logical timestamps without message exchange.
Expected property: The test does not infer causal dependence from numeric order alone.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.13 A remote timestamp advances the logical clock
Setup: The local clock is lower than an observed remote clock.
Action: Generate a subsequent local event using the Lamport rule.
Expected property: The new logical timestamp exceeds the observed value.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.14 A local event advances the logical clock
Setup: The local clock has a known value.
Action: Generate a new local event.
Expected property: The clock increases monotonically.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.15 A repeated insertion is idempotent
Setup: An insertion has already been integrated.
Action: Deliver the same operation again.
Expected property: The operation does not create a second element.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.16 A repeated deletion is idempotent
Setup: An element is already marked deleted.
Action: Apply the same deletion again.
Expected property: The visible state remains unchanged.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.17 A conflicting duplicate ID is not silently accepted
Setup: An ID already maps to one payload.
Action: Deliver another payload using that ID.
Expected property: The implementation follows an explicit conflict policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.18 A deletion targets an ID rather than an index
Setup: The visible positions have changed after insertion.
Action: Delete a specific element by ID.
Expected property: The intended element is marked deleted.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.19 Equal character values can be deleted independently
Setup: Two elements share the same visible value.
Action: Delete one element by its ID.
Expected property: Only the targeted element is logically deleted.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.20 A tombstone is omitted from visible text
Setup: An element is marked deleted.
Action: Reconstruct visible text.
Expected property: The deleted element's value is not emitted.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.21 A tombstone's descendants remain reachable
Setup: A deleted element has a child.
Action: Traverse the structure.
Expected property: The child's value can still be emitted when visible.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.22 An insertion can reference a tombstone
Setup: The anchor exists but is logically deleted.
Action: Insert a child using that anchor.
Expected property: The relationship remains interpretable.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.23 A tombstone is not collected merely because it is old
Setup: A replica may still have outstanding operations.
Action: Evaluate the GC policy.
Expected property: Age alone is not treated as proof of safety.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.24 A safe GC decision respects dependencies
Setup: The protocol has established its required safety conditions.
Action: Evaluate an eligible tombstone.
Expected property: Collection occurs only under the defined policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.25 A missing anchor is represented as unresolved
Setup: An insertion arrives before its anchor.
Action: Attempt to integrate the operation.
Expected property: The operation is tracked rather than silently discarded.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.26 A missing anchor does not corrupt the child map
Setup: An insertion is pending.
Action: Inspect the applied element and child maps.
Expected property: No invalid parent-child relationship is recorded as applied.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.27 A delayed anchor resolves a pending insertion
Setup: An operation waits for an anchor.
Action: Deliver the operation that creates the anchor.
Expected property: The dependent insertion becomes eligible for integration.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.28 Several dependency levels resolve transitively
Setup: C depends on B and B depends on A.
Action: Deliver A after C and B have become pending.
Expected property: The system can resolve the dependency chain.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.29 A pending operation is not applied twice
Setup: A pending operation becomes resolvable.
Action: Trigger dependency processing more than once.
Expected property: The element is integrated only once.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.30 An unrelated operation can be processed safely
Setup: One operation is pending on a missing anchor.
Action: Deliver an independent valid operation.
Expected property: The independent operation follows the protocol's allowed processing policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.31 A root insertion has no missing anchor
Setup: The insertion uses a null root anchor.
Action: Integrate the operation.
Expected property: The root case follows the defined root semantics.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.32 An unknown non-root anchor is not treated as root
Setup: An insertion references a nonexistent ID.
Action: Attempt integration.
Expected property: The missing reference is not silently rewritten to null.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.33 An element has one consistent anchor
Setup: An element record is present in the map.
Action: Compare its anchor with the child index.
Expected property: Both structures agree.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.34 A child index does not reference absent records
Setup: The children map contains a child ID.
Action: Validate the state.
Expected property: The corresponding element record exists.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.35 A record is not listed under the wrong parent
Setup: An element's after field names one anchor.
Action: Inspect child lists.
Expected property: The element is listed under the matching anchor.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.36 A sibling list is ordered before traversal
Setup: Several children share an anchor.
Action: Run reconstruction.
Expected property: The ordering rule is applied consistently.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.37 Traversal visits a parent before its descendants
Setup: A node has a child and a grandchild.
Action: Run the documented parent-first traversal.
Expected property: The output follows the specified visit order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.38 Traversal processes descendants before the next sibling
Setup: The first sibling has a descendant and another sibling follows.
Action: Run the selected depth-first traversal.
Expected property: The descendant is visited according to the documented variant.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.39 Traversal skips a deleted node's value
Setup: A deleted node has visible descendants.
Action: Reconstruct visible text.
Expected property: The node's value is skipped but descendants are visited.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.40 Traversal handles an empty state
Setup: No elements exist.
Action: Reconstruct visible text.
Expected property: The result is an empty string.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.41 Traversal handles one root element
Setup: The state contains one visible root element.
Action: Reconstruct visible text.
Expected property: The root value appears once.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.42 Traversal handles a deep chain
Setup: A long sequence of descendants exists.
Action: Run reconstruction.
Expected property: Traversal terminates and visits the valid elements.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.43 Traversal detects a cycle
Setup: Malformed state contains a cycle.
Action: Run validation or traversal.
Expected property: The operation fails safely rather than looping forever.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.44 Traversal handles an orphaned element
Setup: A record references a missing anchor.
Action: Validate the state.
Expected property: The record remains unresolved or the state is rejected according to policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.45 Traversal does not visit a node twice
Setup: Malformed relationships attempt to expose a node twice.
Action: Run structural validation.
Expected property: The implementation prevents duplicate visible output.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.46 Two replicas start from equivalent state
Setup: Replica A and B have the same initial sequence.
Action: Compare their reconstructed visible text.
Expected property: The initial visible state is equal.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.47 Two replicas receive the same operation set
Setup: The replicas begin with equivalent state.
Action: Deliver the same valid operations in different allowed orders.
Expected property: The replicas converge.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.48 A disconnected replica keeps its local operation
Setup: The client is offline when an edit occurs.
Action: Record the local operation.
Expected property: The local operation remains available for later synchronization.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.49 An offline operation is replayed after reconnect
Setup: A replica has accumulated local operations while disconnected.
Action: Reconnect and exchange the operations.
Expected property: The valid operations can be integrated.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.50 A reconnect does not duplicate an operation
Setup: A synchronization round repeats an already applied operation.
Action: Replay the operation.
Expected property: The state remains idempotent.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.51 A reconnect can resolve an old anchor
Setup: A returning replica has an operation anchored to older state.
Action: Exchange the required operations.
Expected property: The anchor is restored or the dependency is handled explicitly.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.52 A lost operation is not magically recovered by convergence
Setup: A valid operation is never delivered or replayed.
Action: Observe the synchronization result.
Expected property: The test documents that delivery or recovery is a separate responsibility.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.53 A message arrival order is not used as a sibling key
Setup: Two replicas receive siblings in opposite orders.
Action: Reconstruct both sequences.
Expected property: Arrival order does not determine the final sibling order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.54 A set-like merge is not used for ordered text
Setup: The same values appear in different positions.
Action: Compare two candidate representations.
Expected property: The sequence model preserves order that a plain set would discard.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.55 A counter example merges both increments
Setup: Two replicas start at ten and independently increment.
Action: Merge the counter updates under a suitable counter CRDT.
Expected property: The merged value accounts for both increments.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.56 A set example ignores order
Setup: Two replicas add different members.
Action: Merge the set state under its defined semantics.
Expected property: The resulting membership contains both additions.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.57 A sequence example preserves relative position
Setup: Two replicas insert at different anchors.
Action: Merge the operations.
Expected property: The anchors remain represented in the final structure.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.58 The operation schema validates required fields
Setup: An incoming insertion is missing an ID or value.
Action: Run operation validation.
Expected property: Malformed input is rejected or quarantined according to policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.59 A malformed timestamp is handled explicitly
Setup: An operation contains an invalid timestamp value.
Action: Run validation.
Expected property: The operation does not silently corrupt ordering.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.60 A malformed anchor type is handled explicitly
Setup: An operation contains an invalid anchor representation.
Action: Run validation.
Expected property: The operation is rejected or tracked according to policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.61 A payload does not change after acceptance
Setup: An ID has already been integrated.
Action: Deliver a conflicting payload with that ID.
Expected property: The accepted element is not silently overwritten.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.62 The replica ID tie-breaker is stable
Setup: Two operations share a timestamp.
Action: Compare them on multiple replicas.
Expected property: The same comparison result is produced.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.63 String comparison behavior is defined
Setup: Replica IDs contain characters with differing sort behavior.
Action: Compare ordering keys.
Expected property: The implementation uses one documented comparison rule.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.64 The comparator is antisymmetric
Setup: Two valid ordering keys are supplied.
Action: Compare A to B and B to A.
Expected property: The signs of the comparison results are consistent.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.65 The comparator is transitive
Setup: Three valid ordering keys are supplied.
Action: Compare all three according to the comparator.
Expected property: The resulting order is transitive.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.66 The comparator distinguishes all valid siblings
Setup: Two distinct siblings have valid unique ordering keys.
Action: Compare their keys.
Expected property: The comparator provides a deterministic order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.67 A key collision is surfaced
Setup: Two distinct operations share every ordering field.
Action: Attempt to order them.
Expected property: The implementation has a defined final tie-breaker or rejects the invalid identity state.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.68 An element's value can be a repeated character
Setup: The sequence contains repeated letters.
Action: Reconstruct visible text.
Expected property: Every visible element appears according to its own identity and order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.69 A multi-character document remains ordered
Setup: The structure contains many character elements.
Action: Run traversal.
Expected property: The output follows the sequence algorithm's rules.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.70 Deleting a middle element preserves neighbors
Setup: A visible element between two others is deleted.
Action: Reconstruct visible text.
Expected property: The deleted value is omitted and remaining elements retain the defined order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.71 Concurrent deletion does not erase an unrelated insertion
Setup: One replica deletes an element and another inserts nearby.
Action: Exchange valid operations.
Expected property: Both operations are handled under the documented deletion and insertion semantics.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.72 A deletion arrives before the insertion it targets
Setup: A delete operation is delivered before its target element.
Action: Process the deletion.
Expected property: The implementation follows an explicit policy for unresolved deletion targets.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.73 A repeated delete after insertion is idempotent
Setup: The target element exists and is deleted.
Action: Replay the deletion.
Expected property: The state does not change unexpectedly.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.74 A deletion for an unknown ID is not mapped to an index
Setup: The target ID does not exist locally.
Action: Receive the deletion.
Expected property: The system tracks, defers, or rejects it according to policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.75 GC does not break descendants
Setup: A candidate tombstone has descendants.
Action: Evaluate collection safety.
Expected property: The system preserves or rewrites relationships only under a defined safe procedure.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.76 GC behavior is deterministic where required
Setup: Replicas evaluate equivalent GC eligibility state.
Action: Apply the documented GC protocol.
Expected property: The resulting structure remains compatible with convergence.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.77 Snapshot restoration preserves IDs
Setup: A persisted sequence snapshot is restored.
Action: Compare IDs before and after restoration.
Expected property: Stable identities are retained.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.78 Snapshot restoration preserves anchors
Setup: A snapshot includes linked elements.
Action: Restore and traverse it.
Expected property: The insertion relationships remain valid.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.79 Operation replay after snapshot is idempotent
Setup: A snapshot is restored and an already represented operation is replayed.
Action: Apply the operation.
Expected property: The state does not duplicate the represented insertion.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.80 Corrupt persisted relationships are detected
Setup: A stored child index disagrees with element records.
Action: Load or validate the state.
Expected property: The inconsistency is detected instead of silently accepted.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.81 Visible output excludes internal metadata
Setup: The sequence contains IDs, timestamps, and tombstones.
Action: Render the document.
Expected property: Only visible element values are emitted.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.82 Position lookup does not redefine identity
Setup: An element's visible index is recalculated.
Action: Use its stable ID in a subsequent operation.
Expected property: The operation still references the same element.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.83 Concurrent identical insertions remain separate
Setup: Two replicas insert the same character after the same anchor.
Action: Exchange operations.
Expected property: Both insertion identities remain represented.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.84 Two sequential local insertions preserve intended anchors
Setup: A client creates one insertion and then another based on the updated local state.
Action: Replay both operations.
Expected property: The second operation references the correct element or anchor.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.85 A dependent local insertion observes its predecessor
Setup: A client inserts B and then C after B.
Action: Inspect operation relationships.
Expected property: C references the stable identity of B.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.86 A stale client operation is validated
Setup: A client generates an operation using an anchor absent from the receiver.
Action: Receive the operation.
Expected property: The system resolves or tracks the dependency rather than guessing a position.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.87 A duplicate operation does not change sibling order
Setup: The same sibling insertion is delivered twice.
Action: Rebuild the child list.
Expected property: The element is present once and ordering remains stable.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.88 A pending operation is not garbage-collected as applied
Setup: An operation is unresolved.
Action: Run normal applied-state cleanup.
Expected property: The pending record remains tracked under the pending policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.89 Pending queue processing reaches a fixed point
Setup: Several pending operations depend on one another.
Action: Resolve the first available anchor and process dependencies.
Expected property: Processing stops when no additional dependency can be resolved.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.90 An unresolved cycle is not mistaken for a valid chain
Setup: Malformed operations form a dependency cycle.
Action: Run dependency processing.
Expected property: The system detects or safely retains the invalid unresolved state.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.91 A large sibling set remains deterministic
Setup: Many insertions share one anchor.
Action: Deliver them in several orders.
Expected property: All replicas produce the same sibling order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.92 A large descendant chain remains traversable
Setup: Many insertions form a deep chain.
Action: Run reconstruction.
Expected property: The implementation completes within its documented operational limits.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.93 A broad tree remains traversable
Setup: Many siblings and descendants exist.
Action: Run reconstruction.
Expected property: Each valid element is handled once according to ordering rules.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.94 Sorting cost is measured separately
Setup: A benchmark uses sibling groups of varying size.
Action: Measure insertion and reconstruction separately.
Expected property: Results distinguish sorting from lookup and traversal.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.95 Map lookup assumptions are verified
Setup: The implementation uses hash maps.
Action: Inspect or benchmark the actual operations.
Expected property: Expected constant-time lookup is treated as an implementation assumption, not a universal worst-case guarantee.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.96 Child-list insertion cost is measured
Setup: A sibling list grows to different sizes.
Action: Insert new siblings under the chosen policy.
Expected property: The test reveals the cost of sorted versus unsorted child lists.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.97 Full reconstruction cost is measured
Setup: Documents contain increasing element counts.
Action: Reconstruct the visible sequence.
Expected property: Measurements describe actual workloads rather than inferred performance.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.98 Tombstone growth is observable
Setup: Repeated edit/delete histories create tombstones.
Action: Inspect stored element counts.
Expected property: The implementation can quantify retained metadata.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.99 GC tests include offline replicas
Setup: A replica remains disconnected with old operations.
Action: Attempt tombstone cleanup on another replica.
Expected property: The GC policy does not assume the disconnected replica has no dependencies without evidence.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.100 Recovery tests include old operation anchors
Setup: A returning replica references a tombstone candidate.
Action: Reconcile the operation history.
Expected property: The system preserves enough information or uses a documented rewrite protocol.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.101 State-based merge assumptions are documented
Setup: A state exchange is used in a test harness.
Action: Merge two valid states.
Expected property: The merge operation follows its required algebraic properties.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.102 Operation-based delivery assumptions are documented
Setup: An operation exchange is used in a test harness.
Action: Vary delivery according to the protocol.
Expected property: The test distinguishes supported reordering from unsupported delivery.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.103 The protocol handles retries explicitly
Setup: A sender does not receive an acknowledgement.
Action: Retry an operation.
Expected property: The receiver's idempotency policy prevents duplicate effects.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.104 Acknowledgement is not confused with application
Setup: A transport acknowledges message receipt.
Action: Compare transport acknowledgement with CRDT integration state.
Expected property: The system does not assume receipt necessarily means successful integration.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.105 Invalid operations do not enter the valid history
Setup: An operation fails schema or invariant validation.
Action: Attempt to apply it.
Expected property: The operation is rejected or quarantined according to policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.106 Error handling preserves pending work
Setup: One operation cannot currently be integrated.
Action: Process it and later deliver its dependency.
Expected property: The operation remains available for retry if policy permits.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.107 Visible text is stable after all operations settle
Setup: All replicas have received the same valid operation set.
Action: Reconstruct text repeatedly.
Expected property: The output remains deterministic.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.108 A no-op duplicate leaves metadata unchanged
Setup: An operation is recognized as already applied.
Action: Apply it again.
Expected property: The duplicate does not add another child entry or alter the ordering key.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.109 A root child participates in sibling ordering
Setup: Several root-level elements exist.
Action: Reconstruct the sequence.
Expected property: Root siblings use the same documented deterministic policy where applicable.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.110 A deleted root remains structurally meaningful
Setup: The root element is logically deleted but has descendants.
Action: Traverse the structure.
Expected property: Its value is skipped and its descendants remain reachable.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.111 A child cannot point to itself
Setup: An insertion uses its own ID as its anchor.
Action: Validate the operation.
Expected property: The invalid self-reference is rejected or safely quarantined.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.112 An ID cannot introduce a cycle through redefinition
Setup: An existing element ID is reused with a different anchor.
Action: Validate the conflicting operation.
Expected property: The accepted structure is not silently reparented.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.113 Children are not appended based on network arrival
Setup: Sibling messages arrive in randomized order.
Action: Integrate and reconstruct.
Expected property: The final order follows the comparator rather than append history.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.114 The sequence preserves all accepted distinct insertions
Setup: Several valid unique insertions are exchanged.
Action: Compare internal IDs after convergence.
Expected property: Every accepted insertion remains represented unless a documented safe compaction applies.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.115 A visible character maps back to an element identity
Setup: The UI displays a character from a sequence element.
Action: Resolve its backing element record.
Expected property: The visible value can be associated with its stable identity.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.116 Cursor indexing is kept separate from CRDT identity
Setup: The visible text index changes after an insertion.
Action: Resolve the underlying element references.
Expected property: The implementation does not treat the numeric index as a permanent ID.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.117 The same history is replayable under documented assumptions
Setup: A deterministic valid operation history is stored.
Action: Replay it into an empty compatible state.
Expected property: The reconstructed sequence matches the expected state.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.118 A test distinguishes convergence from semantic intent
Setup: Two concurrent edits have more than one reasonable human interpretation.
Action: Apply the deterministic algorithm.
Expected property: The test asserts the algorithm's defined result rather than claiming it captures user intent perfectly.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.119 The test harness records delivery order
Setup: A convergence test randomizes operation delivery.
Action: Run the scenario.
Expected property: The failure report includes the delivery order needed to reproduce the result.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.120 A property test retains its random seed
Setup: A generated history fails an invariant.
Action: Record the generator seed and operations.
Expected property: The failure can be reproduced.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.121 A shrinking property test preserves the failure
Setup: A generated history has many operations.
Action: Reduce it to a minimal counterexample.
Expected property: The smaller history still demonstrates the violated invariant.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.122 Replica state comparison ignores irrelevant map iteration order
Setup: Two replicas store equivalent records in different map insertion orders.
Action: Compare their logical state.
Expected property: The comparison uses sequence semantics rather than raw map iteration order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.123 Serialization preserves null anchors
Setup: A root insertion is serialized and deserialized.
Action: Compare the anchor value.
Expected property: The root marker remains unambiguous.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.124 Serialization preserves element IDs
Setup: An operation is serialized and deserialized.
Action: Compare the ID.
Expected property: The ID remains stable.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.125 Serialization preserves timestamp values
Setup: An operation with ordering metadata is round-tripped.
Action: Compare the timestamp.
Expected property: The value does not change unexpectedly.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.126 Serialization preserves deletion state
Setup: A tombstone record is round-tripped.
Action: Compare the deletion flag.
Expected property: The record remains logically deleted.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.127 Serialization preserves anchor relationships
Setup: A linked structure is round-tripped.
Action: Reconstruct the sequence.
Expected property: The relationships remain valid.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.128 A replica restart does not reuse an ID
Setup: A replica restores its counter state.
Action: Create a new element.
Expected property: The new ID does not collide with a previously persisted ID.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.129 A stale counter state is handled
Setup: A replica's persisted counter is behind known IDs.
Action: Attempt to create an ID.
Expected property: The implementation detects or prevents reuse according to its identity policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.130 The operation log and current state are not conflated
Setup: A test has both an operation history and a materialized sequence.
Action: Compare their roles.
Expected property: The implementation does not treat a snapshot as interchangeable with the history without a defined replay model.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.131 A full snapshot and operations are reconciled consistently
Setup: A replica has a snapshot and some newer operations.
Action: Restore and replay using the documented protocol.
Expected property: The resulting state is consistent and duplicates are handled.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.132 The visible renderer does not mutate CRDT state
Setup: Visible text is reconstructed for display.
Action: Render repeatedly.
Expected property: Rendering does not reorder or delete internal records as a side effect.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.133 Sorting is stable for identical valid input
Setup: The same child collection is sorted repeatedly.
Action: Compare sorted results.
Expected property: The order remains identical.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.134 A comparator change is treated as a compatibility concern
Setup: Two versions use different sibling-ordering rules.
Action: Exchange operations between them in a compatibility test.
Expected property: The system documents or prevents mixed-rule divergence.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.135 A schema version is explicit where needed
Setup: Persisted data may outlive an implementation version.
Action: Load the state under a newer version.
Expected property: Any required migration or compatibility policy is explicit.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.136 Malformed remote data cannot create unbounded pending work silently
Setup: A sender provides many operations with nonexistent anchors.
Action: Process the input under the defined resource policy.
Expected property: The system has an explicit validation and resource-management response.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.137 Pending dependency metrics reflect unresolved work
Setup: Operations are waiting for anchors.
Action: Inspect diagnostic state if supported.
Expected property: The implementation can distinguish pending work from applied work.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.138 Garbage collection does not delete an active anchor
Setup: A live descendant still depends on a candidate element.
Action: Evaluate the candidate for collection.
Expected property: The required structural relationship is retained or safely rewritten.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.139 A compaction pass preserves visible output
Setup: A safe compaction procedure is available.
Action: Compare visible text before and after compaction.
Expected property: Compaction does not change the visible sequence.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.140 A compaction pass preserves future integration
Setup: A compacted structure is used by later valid operations.
Action: Apply operations under the documented protocol.
Expected property: The structure retains enough information for supported future integration.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.141 A generated operation uses an existing anchor
Setup: The local replica creates an insertion after a visible element.
Action: Inspect the generated operation.
Expected property: The anchor is the element's stable ID, not only its numeric index.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.142 An edit after local insertion references the new ID
Setup: A user inserts X and then inserts Y after X.
Action: Inspect the second operation.
Expected property: Y's anchor references X's stable identity.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.143 Concurrent insertions do not overwrite each other
Setup: Two replicas insert different elements after one anchor.
Action: Exchange operations.
Expected property: Both unique elements remain represented.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.144 A replica with no new operations stays unchanged
Setup: A synchronization round contains only already applied operations.
Action: Apply the round.
Expected property: The logical sequence does not change.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.145 An empty operation batch is harmless
Setup: A replica receives an empty batch.
Action: Process the batch.
Expected property: The state remains unchanged.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.146 An operation batch with one invalid entry is handled by policy
Setup: A batch mixes valid and invalid operations.
Action: Process the batch.
Expected property: Atomicity or partial-application behavior is explicit.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.147 A batch respects dependencies within the batch
Setup: A batch contains a parent insertion and child insertion.
Action: Deliver the batch in an order permitted by the protocol.
Expected property: The dependency logic produces a valid result.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.148 The same batch can be retried
Setup: A previously processed batch is replayed.
Action: Process it again.
Expected property: Duplicate effects are prevented.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.149 Two different operations can share a timestamp
Setup: Independent replicas use equal logical timestamp values.
Action: Integrate both operations.
Expected property: The tie-breaker resolves sibling order deterministically.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.150 Replica ID alone is not used as element identity
Setup: One replica creates multiple elements.
Action: Compare their IDs.
Expected property: The counter or operation component distinguishes the elements.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.151 The counter alone is not used across replicas
Setup: Two replicas start their counters at the same value.
Action: Create one element on each replica.
Expected property: The replica component prevents identity collision.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.152 An operation's anchor is not rewritten due to display index changes
Setup: The UI recalculates positions after edits.
Action: Inspect a previously created operation.
Expected property: Its anchor ID remains unchanged.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.153 A deleted element is not confused with a missing element
Setup: An anchor exists as a tombstone.
Action: Receive an insertion referencing it.
Expected property: The integration logic distinguishes a retained tombstone from an unresolved ID.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.154 An unresolved element is not rendered prematurely
Setup: An operation lacks a valid anchor.
Action: Request visible text before resolution.
Expected property: The renderer follows the defined unresolved-operation policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.155 A pending operation is eventually retried after its exact anchor arrives
Setup: The pending record references a specific missing ID.
Action: Deliver that ID.
Expected property: The dependency index or scan finds the matching pending operation.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.156 Pending work is removed after successful integration
Setup: A buffered operation becomes applicable.
Action: Integrate it.
Expected property: The pending record is no longer treated as unresolved.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.157 Pending work survives a transient processing failure when policy allows
Setup: Dependency resolution temporarily fails.
Action: Retry after correcting the prerequisite state.
Expected property: The operation can be processed without being lost.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.158 The operation handler separates validation from mutation
Setup: An operation contains several fields.
Action: Validate before changing the state.
Expected property: Invalid input does not leave a partially mutated structure unless atomic partial behavior is documented.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.159 The child index is updated exactly once
Setup: An insertion is successfully applied.
Action: Inspect the parent's child list.
Expected property: The new ID occurs once in the list.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.160 The element map is updated exactly once
Setup: An insertion is successfully applied.
Action: Inspect the element map.
Expected property: One record exists for the ID.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.161 A tombstone remains in the child index when required
Setup: A parent is logically deleted.
Action: Inspect descendants and relationships.
Expected property: The structure retains the links required by the algorithm.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.162 The renderer can skip a tombstone without deleting it
Setup: A deleted record is traversed.
Action: Produce visible output.
Expected property: Rendering omits the value without mutating the record.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.163 An invalid parent-child mismatch is detected
Setup: A child list names one parent while the element record names another.
Action: Run validation.
Expected property: The mismatch is reported or repaired through an explicit procedure.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.164 The traversal rule is documented alongside the comparator
Setup: Ordering code is changed.
Action: Review the algorithm contract.
Expected property: The relationship between sibling order and descendant traversal remains explicit.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.165 A regression test captures a discovered counterexample
Setup: A generated operation history violates an invariant.
Action: Reduce and retain the history as a test.
Expected property: The failure remains reproducible after the fix.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.166 A successful test does not imply untested guarantees
Setup: A focused test covers one operation pattern.
Action: Review the reported result.
Expected property: The report claims only the behavior actually exercised.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.167 A benchmark records the sequence shape
Setup: A performance run uses a document.
Action: Record element count, sibling distribution, and tombstones.
Expected property: Performance results can be interpreted in context.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.168 A stress test bounds resource use
Setup: Many pending operations or deep descendants are generated.
Action: Run the stress scenario.
Expected property: Resource behavior is observed against explicit limits.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.169 An offline client does not need a remote acknowledgement for local state
Setup: The client has no network connection.
Action: Apply a local edit.
Expected property: The local editing state can progress under the intended offline model.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.170 A reconnect does not imply immediate global observation
Setup: One replica reconnects while another is still offline.
Action: Synchronize available replicas.
Expected property: The test distinguishes local convergence from universal immediate visibility.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.171 Strong consistency is not attributed to the CRDT alone
Setup: A design document describes replicated edits.
Action: Review its consistency claim.
Expected property: The claim is limited to the CRDT's actual guarantees.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.172 Consensus is not inserted into the sequence algorithm without need
Setup: The sequence merges independent operations.
Action: Review architectural boundaries.
Expected property: The explanation distinguishes coordination protocols from CRDT integration.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.173 A set merge is not substituted for sequence reconstruction
Setup: A test uses repeated or reordered elements.
Action: Compare set and sequence semantics.
Expected property: The sequence preserves duplicate identities and ordering.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.174 A counter merge is not substituted for insertion history
Setup: A test counts operations and reconstructs text.
Action: Compare the required state.
Expected property: The sequence retains per-element information.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.175 The document can contain repeated letters
Setup: The text contains LL or another repeated character.
Action: Insert and delete one occurrence.
Expected property: Identity keeps the occurrences separate.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.176 The document can contain a single remaining visible element
Setup: All but one element are deleted.
Action: Reconstruct text.
Expected property: The remaining element is emitted exactly once.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.177 The document can become visibly empty with retained tombstones
Setup: Every visible element is deleted.
Action: Reconstruct text while records remain.
Expected property: The output is empty while internal tombstones may remain.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.178 An operation referencing a collected anchor follows policy
Setup: A stale operation references an anchor already safely collected under the protocol.
Action: Receive the operation.
Expected property: The system applies its documented stale-operation behavior.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.179 The GC protocol defines replica membership assumptions
Setup: Some replicas have been offline or removed.
Action: Evaluate whether a tombstone is collectible.
Expected property: The system does not assume unknown replicas are safe without a membership policy.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.180 The operation protocol defines what 'all operations received' means
Setup: A convergence test waits for synchronization completion.
Action: Determine completion.
Expected property: The test uses an explicit delivery or acknowledgement condition.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.181 A convergence test does not compare only text when metadata matters
Setup: Two replicas have equal visible strings but different structures.
Action: Compare the invariants required for future integration.
Expected property: The test can detect divergent internal state where relevant.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.182 A snapshot test validates both visible and structural state
Setup: A snapshot is restored.
Action: Compare IDs, anchors, tombstones, and visible output.
Expected property: Restoration preserves the required state.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.183 A renderer is deterministic for equivalent logical state
Setup: Two replicas have equivalent valid sequence state.
Action: Render both states.
Expected property: The same visible string is produced.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.184 The test harness separates operation generation from delivery
Setup: A randomized history is generated.
Action: Vary only delivery order in repeated runs.
Expected property: Failures can be attributed to integration behavior.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.185 The test harness records replica-local state before merge
Setup: Replicas generate independent edits.
Action: Capture each local sequence.
Expected property: The test demonstrates the intended concurrency scenario.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.186 The final test state includes every valid generated operation
Setup: The history has been fully delivered.
Action: Compare operation identities against integrated state.
Expected property: No accepted operation is missing without a documented semantic reason.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.187 A deletion does not delete every element with the same value
Setup: Several elements share a character value.
Action: Delete one element ID.
Expected property: Only the intended identity is hidden.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.188 An insertion after a deleted anchor follows the specified traversal semantics
Setup: A tombstone has new descendants.
Action: Reconstruct the sequence.
Expected property: The output follows the selected RGA variant rather than an assumed universal order.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.189 The root sentinel cannot collide with an ordinary element ID
Setup: The implementation represents root as null or another sentinel.
Action: Validate generated IDs.
Expected property: Root and real element identities remain distinct.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.190 An operation ID is not confused with a replica ID
Setup: The protocol uses both identifiers.
Action: Inspect metadata fields.
Expected property: Each identifier has one clearly defined purpose.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.191 The document identity scopes element identity where required
Setup: Two documents contain elements generated by the same replica.
Action: Compare their IDs under the storage model.
Expected property: The implementation defines whether IDs are globally or document scoped.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.192 A deleted node's child order remains deterministic
Setup: Several children reference a tombstone.
Action: Traverse after deletion.
Expected property: Sibling ordering still applies consistently.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.193 The state can be serialized without relying on map iteration order
Setup: Elements are stored in maps.
Action: Serialize the state.
Expected property: The serialization format defines deterministic ordering if needed.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.194 A recovered replica applies operations after restoration
Setup: A persisted state is restored and new operations arrive.
Action: Integrate new operations.
Expected property: The recovered state remains compatible with the operation protocol.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.
#E.195 The sequence algorithm's assumptions are written down
Setup: The implementation relies on a delivery or identity guarantee.
Action: Review its contract.
Expected property: The assumption is explicit and testable.
The test should report the generated operations and the replica-local delivery order when a failure depends on operation history.