The egress lanes’ receivers and per-connection state that the select! loop in
handle_ws_connection mutates, so each branch is a method instead of an inline block.
A method returns true when the connection should end.
Sentinel key for every priority-lane event that is NOT a blockfile
(terminal/PTY output) event. Not a valid block:<id> scope string, so it
can never collide with a real pane key.
Extract a coalescing key from a background-lane event.
Background events are RPC-wrapped MPS events:
{ “eventtype”: “rpc”, “data”: { “command”: “eventrecv”, “data”: { “event”: “sysinfo”, “scopes”: [“local”] } } }
Key = “:”, e.g. “sysinfo:local” or “blockstats:block:abc123”.
Falls back to “:” for events that don’t match the expected shape (safe: they coalesce
to one slot, which is acceptable because non-sysinfo/blockstats never reach this lane).
Drain all immediately-available events from rx (including first) and
coalesce them to the latest reading per (event-name:scope) key. Iteration
order in the returned Vec is first-seen (stable across coalescing rounds).
Route a decoded blockinput payload — the actual human-keystroke path
(termViewModel.ts’s blockinput WS command, used by both the
standalone Terminal widget and an agent pane’s composer-drawer shell) —
to its block’s controller.
Drain all immediately-available events from rx (including first) and
interleave them round-robin by pane (priority_pane_key), instead of
forwarding in raw arrival order. Without this, a pane producing output
faster than the socket can flush it fills this same lane with its own
frames, and a different pane’s keystroke-echo frame — queued in the same
FIFO — waits behind the entire backlog. Round-robining bounds that wait to
one slot per OTHER distinct pane with events currently queued, regardless
of how deep any single pane’s backlog is.
blockinput and setblocktermsize: a payload for a block’s controller from this connection. A refusal is sent back
as a bus:error frame (the one agent clients already read); a closed socket is the only Err.
Extract a fairness key so a flood of PTY output from one pane can’t queue
an unbounded number of frames ahead of a different pane’s own keystroke
echo sitting in the same lane.
The window’s input commands (blockinput keystrokes, setblocktermsize, and controllerinput’s Stop and resize)
are the person’s hands: typed into a block they read as the person’s own words. A connection registered as an
agent (the agent’s own token, proven at bus:register) writes into no block through them. An agent writes into
its own terminal with the Terminal tool (the PtyShell API checks that the shell is its own) and reaches another
agent with Message send. Everything else is as before.
The srvinfo event sent once on every WebSocket connect, right after
config: srv’s version, which the UI compares with its own, and the
machine srv runs on (crate::srv_info).
Run f on block_id’s persistent controller for agent.answer /
agent.cancel. The error strings are matched by the frontend’s
SAFE_TO_RETRY_VIA_FOLLOWUP allowlist (useAgentQuestions.ts).