Expand description
Deferred context delivery — flush pending context alongside user content.
When the control plane produces model-role context turns (tool advisory,
repair nudge, steering modifiers, phase instructions, on_enter_context),
they can be queued in a PendingContext buffer instead of sent immediately.
DeferredWriter wraps any [SessionWriter] and transparently drains the
pending queue before forwarding user-initiated sends (send_audio,
send_text, send_video). This ensures context arrives in the same burst
as user content rather than as isolated WebSocket frames that can confuse
the model or clash with concurrent user input.
§Architecture
Control lane (lifecycle) User code (LiveHandle)
| |
push context to send_audio / send_text
PendingContext |
| DeferredWriter
v 1. drain PendingContext
+---------------+ 2. send_client_content(drained, false)
| PendingContext | <-- drain --- 3. forward original send
+---------------+The queue uses parking_lot::Mutex for fast, uncontested locking — the
control lane pushes once per turn, and user sends drain before each frame.
Structs§
- Deferred
Writer - A [
SessionWriter] wrapper that flushes pending context before user content. - Pending
Context - Thread-safe buffer for pending context turns awaiting delivery.