Skip to main content

Module relay

Module relay 

Source
Expand description

CP-11 fix-2 (A): bounded caller-facing stream boundary.

Runtime::run_stream_with_messages produces StreamEvents from an internal turn task. Delivery to the CALLER is routed through this relay, which enforces a fixed retention policy so a slow or absent consumer can never make the runtime retain unbounded provider bytes:

  • the caller-facing channel is BOUNDED (RELAY_CHANNEL_CAPACITY events, each delta payload chunked to RELAY_FORWARD_CHUNK_BYTES);
  • high-volume preview deltas (LlmEvent::Text / Thinking / ToolUseDelta / ToolResultDelta) are COALESCED once retention crosses RELAY_COALESCE_THRESHOLD_BYTES and DROPPED oldest-first (exact byte accounting) once retention would exceed RELAY_DELTA_RETAINED_BUDGET_BYTES;
  • semantic terminal/control/tool-call events (tool_use, tool_result, session history, errors, Done, agent events) are NEVER dropped or reordered — their volume is structurally bounded by the turn budget (calls × max_tool_output, rounds, one history per round — each a vector of shared Arcs, not a copy of the history);
  • a dropped caller stream cancels the turn token so provider tasks are released instead of streaming into the void.

The internal producer hop stays an unbounded sender for API stability, but the relay drains it EAGERLY (it never awaits caller capacity while input is available), so retention there is scheduling-transient, not caller-dependent; all caller-dependent retention is governed by the budget above.

Structs§

RelaySnapshot
Point-in-time view of the global relay accounting. At quiescence, produced bytes equal forwarded plus dropped plus retained bytes; retained returns to zero when every relay has terminated.

Constants§

RELAY_CHANNEL_CAPACITY
Bounded caller-facing channel capacity, in events.
RELAY_COALESCE_THRESHOLD_BYTES
Retained-delta level above which adjacent same-class deltas coalesce. Below it, event granularity is preserved for prompt consumers.
RELAY_DELTA_RETAINED_BUDGET_BYTES
Maximum delta payload bytes retained inside the relay while the caller is not consuming. Beyond this, oldest preview bytes are dropped.
RELAY_FORWARD_CHUNK_BYTES
Maximum delta payload bytes per forwarded event (large coalesced runs are re-chunked), bounding bytes parked in the caller channel itself.

Functions§

stream_relay_snapshot