Expand description
Per-connection context threaded through every method handler (#2054).
Why: session.attach needs a way to push server-initiated JSON-RPC
notifications (session lifecycle/events) back to the SAME connection
that called it, asynchronously, after the initial response has already
been sent. Most handlers (ping, health, session.list, …) have no
use for this, but the Router dispatch path
must thread it uniformly so a handful of methods aren’t a special case
with a different call signature.
What: ConnectionContext carries a connection_id (identifies which
connection/subscriber this call came from — one per STDIO process
lifetime, one per HTTP POST /rpc call) and a NotifySender the
connection’s transport drains and writes to the wire. Over STDIO, the
transport loop keeps one long-lived receiver for the whole process and
interleaves notifications with request/response lines on stdout. Over
HTTP, each POST /rpc call gets a throwaway channel — any queued
notification vanishes once the response is written, because HTTP’s real
streaming path for session.attach is the dedicated GET /sessions/{id}/events SSE route (see crate::serve::http), not this
channel. A handler that spawns a background forwarder using notify
(like session.attach) must treat a failed send as “the connection is
gone” and stop.
Test: context::tests::connection_context_is_constructible.
Structs§
- Connection
Context - Per-connection state passed to every JSON-RPC method handler.
Type Aliases§
- Notify
Sender - Channel used to push a fully-formed JSON-RPC wire object (a
Responseserialised toValue, or a server-initiated notification) to the connection’s outbound stream, asynchronously, outside the normal request/response cycle.