ElectionLobby

interface ElectionLobby

A pre-session lobby over a symmetric mesh. Not a Room — during the lobby there is no admit handshake and no admitted roster: just the live connected peers and a reactive elected host. A Room is created exactly once, at start/awaitRoom, by adopting the woven seam with a now-fixed role. See docs/host-election-design.md.

A lobby does run a heartbeat. Every lobby answers pings from the moment it exists, so a host may take as long as its user likes to call start. start and awaitRoom also watch their counterparts, so a peer that stays connected but stops answering ends the election. A lobby that answers is only open, though, not necessarily taking part, so a peer abandoning a lobby must call leave.

Properties

Link copied to clipboard
abstract val host: StateFlow<PeerId>

The elected host — electHost(peers) — reactive. Every peer computes the same value.

Link copied to clipboard
abstract val peers: StateFlow<Set<PeerId>>

Live set of connected peers (includes selfId). Join / leave / two-group-merge are all just set changes. Sourced from us.tractat.kuilt.core.Seam.peers — never a discovery roster such as NwLoom.visiblePeers, which accumulates and never removes.

Link copied to clipboard
abstract val selfId: PeerId

This peer's own identifier.

Link copied to clipboard
abstract val state: StateFlow<SeamState>

The underlying seam's own lifecycle — Weaving / Woven / Torn — exposed so a consumer can distinguish the two ways liveness can collapse mid-election (#1466): a transport tear (SeamState.Torn) versus a membership drain (peers shrinking while state stays SeamState.Woven). Sourced from us.tractat.kuilt.core.Seam.state — same value the lobby's own collapse detection races against.

Functions

Link copied to clipboard
abstract suspend fun awaitRoom(memberName: String? = null, deviceId: String? = null): ElectionOutcome

Await the session as a member: suspend until the elected host freezes the lobby, acknowledge it, and adopt the seam as us.tractat.kuilt.session.SessionRole.Joiner. (The host obtains its Room from start instead.)

Link copied to clipboard
abstract suspend fun leave()

Leave the lobby, closing the underlying seam — unless a Room has already adopted it. Idempotent.

Link copied to clipboard
abstract suspend fun start(memberName: String? = null, deviceId: String? = null, admission: HostAdmission): Room

HOST-ONLY. Close the lobby and begin the session: run the freeze/ack round, then adopt the seam as us.tractat.kuilt.session.SessionRole.Host. Retries internally while membership churns and while a live member has not acknowledged; returns the admitted Room once every member has.