{"record":{"id":"16b751c4f007ee44","repo":"unicity-aos/aos-ce","slug":"event-bus-dropped-result-dropped-messages-in-context-engine","errorCode":null,"errorMessage":"Event bus dropped {result.dropped} messages in context engine poll","messagePattern":"Event bus dropped (.+?) messages in context engine poll","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"capsules/capsule-context-engine/src/lib.rs","lineNumber":328,"sourceCode":"            let _ = after_sub.poll();\n        }\n    }\n}\n\n// ── Envelope dispatch ───────────────────────────────────────────────\n\n/// Returns `true` if the topic should be dispatched (not a self-echo).\nfn should_dispatch_topic(topic: &str) -> bool {\n    !topic.starts_with(\"context_engine.v1.response.\")\n        && !topic.starts_with(\"context_engine.v1.hook_response.\")\n        && topic != \"context_engine.v1.hook.before_compaction\"\n        && topic != \"context_engine.v1.hook.after_compaction\"\n}\n\n/// Dispatch messages from a typed `PollResult`.\nfn dispatch_poll_result(result: &ipc::PollResult, config: &Config) {\n    if result.dropped > 0 {\n        log::warn(format!(\n            \"Event bus dropped {} messages in context engine poll\",\n            result.dropped\n        ));\n    }\n\n    for msg in &result.messages {\n        if !should_dispatch_topic(&msg.topic) {\n            continue;\n        }\n\n        let payload: serde_json::Value = match serde_json::from_str(&msg.payload) {\n            Ok(v) => v,\n            Err(e) => {\n                log::warn(format!(\"failed to deserialize IPC message payload: {e}\"));\n                continue;\n            }\n        };\n","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/capsules/capsule-context-engine/src/lib.rs#L310-L346","documentation":"The context engine capsule polls the IPC event bus via a typed PollResult. The bus reports how many messages it dropped (e.g. due to buffer overflow or lag); when result.dropped > 0, dispatch_poll_result logs a warning so the developer knows some events never reached the dispatcher. It is a diagnostics warning, not a hard failure — processing continues with the messages that survived.","triggerScenarios":"Any call to dispatch_poll_result (via the capsule run loop) where the PollResult returned from the event bus poll carries dropped > 0, meaning the bus had to discard messages before delivery.","commonSituations":"Under heavy event traffic the subscription buffer overflows; a slow consumer (long compaction hooks, blocked dispatch) causes the bus to drop queued messages; bursts of tool.v1 events during parallel tool execution.","solutions":["Increase the event-bus subscription capacity/buffer size for the context engine so bursts fit.","Profile and speed up the dispatch loop; ensure run() polls frequently and never blocks inside message handling.","Instrument which topics drop most and throttle publishers emitting into those topics.","Treat the warning as data loss signal: re-derive lost context (e.g. re-run compaction) after observing drops."],"exampleFix":"// before: ignore polling cadence, large gaps let the queue overflow\nloop {\n    sleep(LONG_INTERVAL);\n    let result = bus.poll();\n    dispatch_poll_result(&result, &config);\n}\n// after: poll promptly and drain fully each cycle\nloop {\n    let result = bus.poll();\n    dispatch_poll_result(&result, &config);\n    if result.dropped > 0 {\n        rebuild_missed_context(&result, &config);\n    }\n    sleep(SHORT_INTERVAL);\n}","handlingStrategy":"validation","validationCode":"// after each poll, check for drops before trusting the dispatch\nif result.dropped > 0 {\n    eprintln!(\"context engine dropped {} events; refresh derived state\", result.dropped);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Poll the bus frequently; never sleep long between polls","Size subscription buffers for peak burst traffic","Alert on dropped counters rather than ignoring them"],"tags":["ipc","event-bus","message-loss","rust"],"backgroundTag":"message-loss-detected","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"}