handle_connection

Function handle_connection 

Source
async fn handle_connection(stream: NamedPipeServer, ctx: Arc<ServerCtx>)
Expand description

Drive one connection: read newline-delimited JSON Commands, write back JSON Events. First message MUST be Register.

Phase B.3: every Command goes through reducer::update. The reducer is sync; we hold the state mutex only while it runs. Events come back from the reducer as Vec; we patch sentinel fields (Registered.launcher_pid / launcher_version — the reducer can’t read those) and publish them on the broadcast bus.

Phase B.8 — events from the reducer flow through the broadcast bus (ctx.events_tx); a per-connection fanout task subscribes and writes events to this connection’s pipe. Per-connection direct writes are reserved for “response-to-this-client-only” errors (parse failure, register-first violation). (codex P1 PR #605.)