clusterClient

fun CoroutineScope.clusterClient(loom: Loom, clusterEndpoints: ClusterEndpoints, clientNodeId: NodeId, clusterConfig: ClusterConfig, raftConfig: RaftConfig, identity: ClientIdentity = ClientIdentity.Auto, clock: () -> Instant): ClusterClient

Constructs a ClusterClient connected to the relay-room cluster.

Manages the full connect → use → reconnect lifecycle:

  1. Connects to the initial endpoint via loom.

  2. Backs a ManagedSeam with the resulting us.tractat.kuilt.core.Seam.

  3. Constructs a single RaftNode over a playerRelayTransport on that seam — it lives for the ClusterClient lifetime, across reconnects.

  4. On transport tear: advances ServerClusterReconnect to the next endpoint, re-joins via loom, and swaps the backing us.tractat.kuilt.core.Seam in the ManagedSeam — the RaftNode is not recreated.

Cross-server resume

A cross-server failover always requires a fresh join (proven by #532): each server's reconnect-window registry is in-memory and per-room-instance and its RoomId is its own, so a terminal ResumeResult.Refused is the invariable response. This extension therefore always performs a plain loom.join() on every reconnect — there is no optimistic resume attempt at the Seam level.

Dispatcher injection

The CoroutineScope receiver IS the dispatcher injection point. All background work (reconnect loop, relay coroutines inside ManagedSeam) runs on the caller's dispatcher. No real-clock defaults are introduced.

Parameters

loom

The Loom fabric for connecting to server endpoints.

clusterEndpoints

Endpoint list and rotation policy.

clientNodeId

Stable NodeId for this client — must be in ClusterConfig.learners.

clusterConfig

Full cluster membership (voters + this learner).

raftConfig

Raft timing and dedup configuration.

identity

How this client obtains its Raft §8 dedup id. ClientIdentity.Auto (default) mints a per-incarnation id; pass ClientIdentity.Durable with a stable ClientId for cross-crash exactly-once.

clock

Injected clock for session resume-token timestamps. Required — no real-clock default (prevents silent virtual-time breakage per the "optional ≠ tuning" policy). Threaded into the room-layer SeamRoomFactory, which stamps reconnect-token issuedAt timestamps and drives partition detection. (Cross-server resume is always terminally refused per the in-memory per-room reconnect registry, so the token is issued but never consumed across a failover — the clock still governs same-server room timing.)