WarpCausalClock

class WarpCausalClock(replica: ReplicaId)

Mints causal Dots for spans and tracks the current happens-before frontier.

Call tick once per span, in the order the spans are created: it allocates the span's own Dot and records the frontier observed so far as that span's predecessors. The frontier then collapses to the new dot, so the next span's predecessors point back here — building the happens-before chain a SpanLink is later derived from.

The clock is span-scoped: it advances on span events only, which keeps inference total — every predecessor dot resolves to a span in the set. Cross-signal causality (a log or metric happening-before a span) is future work.

Recovery is mandatory

A restart that reset seq to 0 would re-mint dots already used by earlier spans and silently corrupt causality. Always recover from a DurableStore at startup, and persist after the spans of a batch are durably exported. tick itself stays pure (non-suspending) so the lock stays tight; persistence is the caller's explicit step.

Thread-safety

seq and the frontier are guarded by an explicit reentrant lock, so the clock is correct under a real multi-threaded dispatcher — not merely under a test dispatcher. limitedParallelism(1) confinement is BANNED (see CLAUDE.md).

Parameters

replica

the stable ReplicaId for this device/process; namespaces every dot.

Constructors

Link copied to clipboard
constructor(replica: ReplicaId)

Functions

Link copied to clipboard
fun frontier(): Set<Dot>

A snapshot of the current causal frontier.

Link copied to clipboard
fun observe(remote: Set<Dot>)

Fold a remote frontier (received from another replica via anti-entropy) into the local frontier, so the next tick records those remote dots as predecessors — the cross-replica causal path.

Link copied to clipboard
suspend fun persist(store: DurableStore)

Durably persist the current (seq, frontier) to store. Call after a batch of ticks is durably exported so a restart never re-mints a used dot.

Link copied to clipboard
suspend fun recover(store: DurableStore)

Reload (seq, frontier) from store. Call once at startup before any tick; a missing or corrupt entry leaves the clock fresh (seq 0, empty frontier).

Link copied to clipboard

Mint the next span's CausalStamp: a fresh Dot whose predecessors are the current frontier (empty on the very first tick). Advances the frontier to the new dot.