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_CAPACITYevents, each delta payload chunked toRELAY_FORWARD_CHUNK_BYTES); - high-volume preview deltas (
LlmEvent::Text/Thinking/ToolUseDelta/ToolResultDelta) are COALESCED once retention crossesRELAY_COALESCE_THRESHOLD_BYTESand DROPPED oldest-first (exact byte accounting) once retention would exceedRELAY_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 sharedArcs, 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§
- Relay
Snapshot - Point-in-time view of the global relay accounting. At quiescence,
produced bytes equal forwarded plus dropped plus retained bytes;
retainedreturns 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.