close

open suspend override fun close(reason: CloseReason = CloseReason.Normal)

Disconnect from the session. Idempotent.

A close failure must NOT be reported as a cancellation

The obligation sendTo states, verbatim and for the same reason: throw an ordinary exception when teardown fails, and never let a CancellationException out of this method unless it is signalling the caller's own cancellation. The trap is identical — withTimeout(closeTimeout) { … } throws TimeoutCancellationException, which is a CancellationException, to its caller without cancelling that caller's job. Bound teardown with withTimeoutOrNull plus an explicit throw instead, or catch and rethrow as a plain Exception.

close carries it because best-effort cleanup is where the masquerade does the most damage. A library tearing down N things loops over them under a guard; one callee-minted cancellation cancels that loop rather than failing one item, so every remaining close is skipped — the leak the cleanup existed to prevent, with no failure handler and no stack trace. The caller cannot simply defend its way out: runCatchingCancellable rethrows every CancellationException by type, and type is exactly what cannot separate "my job was cancelled" from "the callee minted one". (That is why using it inside a withContext(NonCancellable) shield is forbidden repo-wide by the forbidRunCatchingCancellableUnderNonCancellable build guard: inside the shield our job is never cancelled, so every CancellationException reachable there is necessarily callee-minted.) Stating the obligation converts "every caller must defend" into "an implementation that does this is non-conforming" (#1826).

Every consumer-implemented suspend surface carries this

Exhaustively, the surfaces a kuilt call site invokes under a best-effort guard are: Loom.weave, broadcast, sendTo, this method, and us.tractat.kuilt.core.fabric.Connection.send/us.tractat.kuilt.core.fabric.Connection.close; outside :kuilt-core, Room.leave. Each points here or at sendTo rather than restating it.

Asserted by SeamConformanceSuite.closeDoesNotReportFailureAsCancellation.