{"record":{"id":"e20da8d84277b701","repo":"unicity-aos/aos-ce","slug":"event-bus-dropped-poll-result-dropped-messages-tui-may-be","errorCode":null,"errorMessage":"Event bus dropped {poll_result.dropped} messages - TUI may be stale","messagePattern":"Event bus dropped (.+?) messages - TUI may be stale","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"capsules/capsule-cli/src/lib.rs","lineNumber":650,"sourceCode":"    session: Option<String>,\n}\n\n/// Fan a `PollResult` out to connected clients, demultiplexed by principal AND\n/// session so a bound connection only sees IPC stamped with its own principal\n/// (plus unprincipaled system events), and a chat response only when it is on\n/// that session. Tracks failed stream indices (into `clients`) in `dead`.\n///\n/// `stream_accum` carries streamed chat tokens across calls so a turn's terminal\n/// response can be reconciled against what was already streamed live (see\n/// [`reconcile_stream_payload`]).\nfn broadcast_poll_messages(\n    clients: &[ProxyClient],\n    poll_result: &ipc::PollResult,\n    stream_accum: &mut HashMap<String, String>,\n    dead: &mut Vec<usize>,\n) {\n    if poll_result.dropped > 0 {\n        log::warn(format!(\n            \"Event bus dropped {} messages - TUI may be stale\",\n            poll_result.dropped\n        ));\n    }\n\n    // Pre-serialize each message once and compute its principal target once\n    // (not per client). Reconstruct the wire format the TUI expects:\n    // {topic, payload, source_id}.\n    let outbound: Vec<OutboundMessage> = poll_result\n        .messages\n        .iter()\n        .filter_map(|msg| {\n            // Parse the payload string back to a JSON value so the TUI\n            // receives an embedded object, not an escaped string.\n            let mut payload = serde_json::from_str::<serde_json::Value>(&msg.payload)\n                .unwrap_or(serde_json::Value::String(msg.payload.clone()));\n            // Accumulate streamed tokens and reconcile the terminal response so\n            // the TUI (append-then-flush) renders the reply exactly once.","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/capsules/capsule-cli/src/lib.rs#L632-L668","documentation":"broadcast_poll_messages polls the IPC event bus and the PollResult reported that `dropped` messages were discarded (e.g. a bounded broadcast channel overflowed between polls). The library logs a warning because the TUI consumes these messages to update streams; dropped messages mean the TUI's accumulated stream output can be incomplete or stale.","triggerScenarios":"poll_result.dropped > 0 after an ipc poll — the event bus buffer filled faster than the TUI consumed it; broadcast_poll_messages logs this warning before processing the surviving messages.","commonSituations":"TUI rendering stalls (terminal backpressure, paused output) while proxies emit high-volume stream output; slow consumer on a busy system with many ProxyClients; undersized event-bus buffer capacity.","solutions":["Increase the event bus / broadcast channel buffer capacity to absorb bursts","Reduce emission rate at the producer side or batch stream chunks","Investigate why the TUI consumer is slow (rendering backpressure, blocking calls)","Treat the affected stream as truncated — trigger a resync/re-fetch of the stream state instead of trusting the accumulated output"],"exampleFix":"// before\nbroadcast::channel(64) // overflows under burst\n// after\nbroadcast::channel(4096) // larger buffer for stream bursts","handlingStrategy":"fallback","validationCode":"if poll_result.dropped > 0 {\n    stream_accum.clear(); // accumulated output is incomplete; resync instead of trusting it\n    schedule_resync();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size broadcast buffers for peak producer burst rates","Keep the TUI consumer responsive; avoid blocking renders on the poll loop","Track a dropped-count watermark and resync streams when it advances","Alert on recurring dropped messages as a backpressure capacity problem"],"tags":["event-bus","backpressure","tui","dropped-messages"],"backgroundTag":"broken-pipe","analyzedSha":"f6f22024fb1e8d122f28a1b4a9f75aee448ae839","analyzedAt":"2026-09-13T03:04:44.565Z","contentChangedAt":"2026-09-13T03:04:44.565Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}