weave

open suspend override fun weave(rendezvous: Rendezvous): Seam

Establish a Seam according to rendezvous — either host a new session or join an existing one.

A fabric failure must NOT be reported as a cancellation

Throw an ordinary exception when the fabric cannot be reached. An implementation must not let a CancellationException out of this method unless it is signalling the caller's own cancellation, because the caller cannot tell the two apart: the idiomatic guard (runCatchingCancellable) rethrows any CancellationException, and a rethrown one cancels the calling coroutine rather than failing it — no failure handler runs, and there is not even a stack trace to find it by.

The trap is withTimeout(dialTimeout) { dial() }. withTimeout throws TimeoutCancellationException — which is a CancellationException — to its caller, without cancelling that caller's job. Convert it before it escapes: withTimeoutOrNull plus an explicit throw, or catch it and rethrow as a plain Exception. NwLoom in :kuilt-nw is the in-tree pattern — it converts its own dial timeout into a plain NwUnreachableException for exactly this reason. A ply whose Loom.weave breaks this rule used to kill a CompositeLoom's reconciliation for the life of the seam, silently (#1784).

A cancelled weave leaves nothing open

If the caller is cancelled before this returns, start closing whatever the dial opened before the cancellation propagates. The close may finish a moment later, but it must not depend on anyone else: only a return hands anything over, and a coroutine cancelled as this resumes takes the cancellation instead of the seam, so nobody else can ever reach what was left. The far end sees a healthy peer that will never speak, for as long as the socket lasts.

The trap is a library that runs its handshake somewhere the caller's cancel does not reach. Ktor's webSocketSession is one: ownedWebSocketSession in :kuilt-websocket is what to dial through instead, and its KDoc names the engine it cannot keep this promise on. NwLoom.discardUnreturnedSeam in :kuilt-nw is the pattern for a seam built during the weave.

No conformance suite checks this: the in-memory reference never suspends in its weave, so it could not fail a test of it (tracked by #3102).