raceCollapse
Run body but abort it with a SeamCollapsedException the instant this Seam collapses mid-operation — either the fabric latches SeamState.Torn (transport tear) OR the live peer set satisfies abortWhen (membership drain). Whichever of body, the tear, or the drain resolves first wins; the losers are cancelled.
The mechanism generalises the hand-rolled "abort the handshake when the peer set collapses" watchers that request/response protocols over a Seam need: a suspended channel.receive() / flow.first { … } that waits on a peer's reply never wakes if that peer vanishes, because Seam.incoming simply stops delivering — nothing else completes the waiter. Racing the wait against the collapse turns an indefinite hang into a bounded throw.
Two collapse shapes, both covered. A fabric that latches Torn on drain is caught by the always-present torn watcher. A fabric whose membership drains while state stays Woven (the peer left the roster, no transport death) is caught by abortWhen over Seam.peers. The default { it.size < 2 } aborts once this peer is alone; pass a predicate to key on specific required participants (e.g. { live -> required.any { it !in live } }).
Eager entry checks. A collapse already true at entry — the seam is already Torn, or abortWhen already holds for the current peer set — throws immediately, before body is ever started.
Structured, cancellation-correct. body and both watchers run as CoroutineStart.UNDISPATCHED siblings, so each reaches its first suspension point before control returns — a collapse racing entry is never missed. All three are cancelled in a finally when the race resolves. Cancellation of the caller propagates through body untouched (this owns no long-lived scope of its own). Correct under a multi-threaded dispatcher: the single CompletableDeferred is the only shared state and first-writer-wins is atomic.
Parameters
predicate over the live Seam.peers set that marks a membership-drain collapse; the default aborts once this peer is alone (size < 2).
the operation to run to completion unless the seam collapses first.
Throws
if the seam tears or drains before body completes.