{"record":{"id":"f3c9f496e1678510","repo":"unicity-aos/aos-ce","slug":"failed-to-deserialize-ipc-message-payload-e","errorCode":null,"errorMessage":"failed to deserialize IPC message payload: {e}","messagePattern":"failed to deserialize IPC message payload: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"capsules/capsule-context-engine/src/lib.rs","lineNumber":342,"sourceCode":"\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\n        // Extract from Custom payload envelope or direct.\n        let request_value = payload.get(\"data\").unwrap_or(&payload);\n\n        match msg.topic.as_str() {\n            \"context_engine.v1.compact\" => handle_compact(request_value, config),\n            \"context_engine.v1.estimate_tokens\" => handle_estimate_tokens(request_value),\n            _ => {}\n        }\n    }\n}\n\n// ── Compact handler ─────────────────────────────────────────────────\n\n/// Handle a `context_engine.v1.compact` request.","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/capsules/capsule-context-engine/src/lib.rs#L324-L360","documentation":"Each IPC message carries a JSON string payload. dispatch_poll_result deserializes it with serde_json; when parsing fails (malformed JSON, empty string, binary data), the capsule logs this warning and skips the message via continue. The library throws it to prevent one corrupt message from aborting the whole poll dispatch.","triggerScenarios":"dispatch_poll_result encounters a queued message whose msg.payload is not valid JSON — e.g. a publisher wrote a non-UTF8-safe string, truncated payload, or raw bytes serialized as a string.","commonSituations":"A publisher capsule serializing with a different/older schema writes invalid JSON; truncated IPC frames under backpressure; hand-crafted test messages pasted into the bus; payloads built via string concatenation instead of a serializer.","solutions":["Fix the producing capsule to serialize payloads with serde_json::to_string instead of manual string building.","Log msg.topic and a payload prefix alongside the error to identify the offending publisher, then repair it.","Validate payload shape on the producer side before publishing (round-trip serialize/deserialize in tests).","If the payload is intentionally non-JSON, switch the message to an encoding the bus contract defines (e.g. base64-wrapped JSON)."],"exampleFix":"// before: building payload by hand\nlet payload = format!(\"{key}={value}\");\nbus.publish(topic, payload);\n// after: proper JSON serialization\nlet payload = serde_json::to_string(&serde_json::json!({ \"key\": key, \"value\": value }))?;\nbus.publish(topic, payload);","handlingStrategy":"validation","validationCode":"// guard before dispatching a message\nfn is_valid_json(s: &str) -> bool { serde_json::from_str::<serde_json::Value>(s).is_ok() }\nif !is_valid_json(&msg.payload) { skip(msg); }","typeGuard":"fn as_json(payload: &str) -> Option<serde_json::Value> {\n    serde_json::from_str(payload).ok()\n}","tryCatchPattern":null,"preventionTips":["Always serialize payloads with a JSON library, never string concatenation","Round-trip test producer payloads before publishing","Keep publisher and consumer schema versions in sync"],"tags":["ipc","json","deserialization","rust"],"backgroundTag":"json-parse-error","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"}