adopt

suspend fun adopt(seam: Seam, role: SessionRole, memberName: String? = null, roomKey: String? = null, reweave: suspend () -> Seam? = null, roomId: RoomId? = null): Room

Adopt an already-woven seam into a Room with an explicit role — no re-weave.

Unlike host/join (which each weave a fresh seam), adopt takes ownership of a seam the caller wove, so the calling layer can weave the mesh once and decide role afterward (the host-election lobby, #1439). The returned Room owns the seam's lifetime from here: Room.leave closes it — correct, because the seam is handed over exactly once.

role is fixed for the room's lifetime. roomKey is the admit-gate key (us.tractat.kuilt.core.Pattern.roomKey); memberName is this peer's own roster label (null → peer-id-derived).

reweave threads resume-after-tear into the adopted room (#1618). When null (the default) a joiner whose host link tears goes terminal (MembershipEvent.HostLost) — the pre-#1618 behaviour, correct for a seam that cannot heal. When the adopted seam self-heals in place (a fabric that re-forms Woven → Weaving → Woven on peer loss rather than latching us.tractat.kuilt.core.SeamState.Torn — e.g. a redialing radio loom), pass reweave = { seam } so a transient blip runs the JoinerResumeMachine resume path (wait for Woven, re-present the ResumeToken) instead of going straight to terminal. See the SeamRoom reweave KDoc for the same-instance-heal contract this must satisfy.

roomId is this room's identity (Room.roomId) and applies to a host adopt only — a joiner learns the room's id from the host's Welcome. Null — the default — mints a fresh one per adopt, which is what stops two rooms one device adopts in a row from colliding (#1594). Supply it when the identity is decided outside kuilt (a lobby code, an invite link, a matchmaker-assigned game id) and the room must adopt it. It does not make a host restart resumable — see Room.roomId and #1593.

Throws

if roomId is non-null and role is SessionRole.Joiner. A joiner cannot choose the room's identity, and silently overriding the caller's value with a different one would fork its durable records with no signal.