rouse-context/docs/design
monkopedia-coder 31475597a4
docs(design): correct the session path in overall.md and tunnel-client.md (#685)
* docs(design): correct the session path in overall.md and tunnel-client.md

`overall.md` and `tunnel-client.md` both described a session path that has
never shipped: plaintext handed straight from the tunnel into
`McpSession.run(input, output)`, one lightweight Ktor server per stream.
There is no `McpSession.run`, and the per-stream claim is exactly inverted.

Verified against the tree and corrected:

- `McpSession`'s real surface is `start(port)`, `resolvePort()`,
  `internalToken`, `awaitClose()`, `shutdown()`, `stop()`. `grep -rn '\.run('`
  over `app/src/main work/src/main core/bridge/src/jvmMain` finds no caller.
- `:work`'s `TunnelForegroundService.collectIncomingSessions` collects
  `incomingSessions`; `:core:bridge`'s `SessionHandler.handleStream` handles
  each stream. `:app` does neither -- `TlsAcceptor` has no reference anywhere
  in `app/src/main`.
- The Ktor server is a singleton started once at app boot;
  `SharedMcpSessionFactory` hands out its port and its `stop` is a no-op.
  Each stream is a new loopback TCP connection, not a new server.
- The stack diagram omitted `:core:bridge`, the module that does the TLS
  accept and the bridging. It is now named at both hops.
- The `TokenStore` sketch was stale: adds `resolveClientName`,
  `resolveClientId`, `resolveClientLabel`, `upgradeClientLabel`,
  `createTokenPair`, `revokeByClientId`, `refreshToken`, `tokensFlow`.
- `MuxStream` carries raw, still-encrypted bytes and no hostname: the relay
  puts the SNI hostname in the OPEN payload but `MuxCodec.decode` drops it
  (`MuxFrame.Open(streamId)`). Integration resolution is by HTTP `Host`
  header in `McpRoutes.resolveIntegration`, not by SNI -- corrected in the
  diagram, in "Auth per integration" and in "Routing inside :core:mcp".
- Route list corrected to what `configureMcpRouting` registers, and the 401
  challenge to what `respondUnauthorized` actually sends
  (`resource_metadata` pointing at `/.well-known/oauth-protected-resource`,
  not the authorization-server document).

Adds two sections the inverted model left nowhere to put:

- Why `X-Internal-Token` exists (177): loopback is not a trust boundary on
  Android, so the bridge proves provenance with a per-start 256-bit secret
  that `InternalTokenGuard` checks in constant time before any route runs.
- The failure path, with the point that `classifyTunnelFailure`'s quiet set
  is a closed allowlist whose `else` arm is `Defect` -- an unanticipated
  exception defaults to *loud*, deliberately.

Documentation only; no code changes.

Closes #653

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

* docs(design): finish the SNI sweep in overall.md

Review of 685 caught that the SNI-on-device claim was corrected in three
places but stated in five, leaving the file contradicting itself: :445 said
`:core:mcp` reads the SNI hostname from the OPEN frame while :461, sixteen
lines below, said the opposite. A consistently-wrong document had become an
inconsistent one.

Swept for the claim's vocabulary (`sni`, `ClientHello`, `first label`,
`OPEN frame`) rather than for the reported line numbers, which turned up
three further sites beyond the two flagged:

- :206 "identified by the SNI label" -> the hostname's first label, with a
  pointer to where each carrier applies.
- :210 "the SNI tells `:core:mcp` which provider to dispatch to" -> the
  request's `Host` header does.
- :231 "scoped to the SNI-derived integration id" -> derived from the
  request's `Host` header.
- :431 "identified by the SNI label" -> the hostname's first label; SNI
  carries it to the relay, `Host` carries it to `:core:mcp`.
- :445 "`:core:mcp` reads the SNI hostname from the OPEN frame" -> the SNI
  is gone inside the tunnel; the relay does put the hostname in the OPEN
  payload but `MuxCodec.decode` maps `OPEN` to `MuxFrame.Open(streamId)`,
  which has no hostname field (`MuxFrame.kt:70`), so `:core:mcp` resolves
  from the `Host` header (`McpRouting.kt:215-223`).

The relay-side SNI statements at :54, :100, :105, :444 and :530 are true and
are retained: the relay does parse SNI from the ClientHello and route on it.
That device/relay split is what :241-244 explains.

Post-fix sweep: every remaining SNI mention in the file is either relay-side
or explicitly device-side-correct. `tunnel-client.md` and `android-app.md`
were swept too; the only hit in either is `android-app.md:12`, which is
relay-side and true.

Documentation only; no code changes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 14:51:28 -04:00
..
android-app.md Remove TunnelSessionManager from jvmMain (#671) (#684) 2026-09-02 07:06:24 -04:00
health-connect-expansion.md Cap Health Connect raw reads and answer spanning ranges with buckets (#545) (#611) 2026-08-26 13:32:10 -04:00
notifications-integration.md Add design specs for new integrations and overnight execution plan 2026-04-06 17:03:37 -04:00
outreach-integration.md Add design specs for new integrations and overnight execution plan 2026-04-06 17:03:37 -04:00
overall.md docs(design): correct the session path in overall.md and tunnel-client.md (#685) 2026-09-02 14:51:28 -04:00
relay-api.md Fix #406 (chunk B, relay-api.md): rewrite to match shipped relay API (#410) 2026-04-25 17:26:38 -04:00
relay.md Fix #406 final wave: ui.md drift fixes + relay.md endpoint pointer (#413) 2026-04-25 18:49:10 -04:00
tunnel-client.md docs(design): correct the session path in overall.md and tunnel-client.md (#685) 2026-09-02 14:51:28 -04:00
ui.md Fix #406 final wave: ui.md drift fixes + relay.md endpoint pointer (#413) 2026-04-25 18:49:10 -04:00
usage-integration.md Add design specs for new integrations and overnight execution plan 2026-04-06 17:03:37 -04:00