rouse-context/core/bridge
monkopedia-coder b27709ec10
Run SessionHandler's session work off the caller's thread (#800)
1.0.13 crashed every incoming session with NetworkOnMainThreadException.
#781 replaced a java.net.Socket connected under withContext(Dispatchers.IO)
with a Ktor socket, whose connect calls SocketChannel.connect synchronously
on the calling thread -- and handleStream is called from lifecycleScope,
i.e. the Android main thread.

serveStream now runs under an injected ioDispatcher (default
Dispatchers.IO): cert/Keystore loading, TLS accept, MCP session
create/stop, the loopback connect, the copy loops and the socket close.
closeStream hops to it too, outside serveStream's hop so a caller
cancelled before it still sends CLOSE (#796). Suspending on IO holds no
thread while a session idles, so #781's behaviour is unchanged.

SessionHandlerCallerThreadTest calls handleStream from a single-thread
stand-in for the main thread and records the thread of each seam,
observing the connect via a recording SelectorProvider.


Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

Co-authored-by: monkopedia-coder <monkopedia-coder@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:29:25 -04:00
..
src Run SessionHandler's session work off the caller's thread (#800) 2026-10-22 20:29:25 -04:00
build.gradle.kts Stop abandoned bridge sessions from pinning IO threads (#778) (#781) 2026-10-19 10:06:18 -04:00