{"record":{"id":"665c5c36cb5ee385","repo":"unicity-aos/aos-ce","slug":"meta-harness-malformed-canonical-payload-error","errorCode":null,"errorMessage":"meta-harness: malformed canonical payload: {error}","messagePattern":"meta-harness: malformed canonical payload: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"capsules/capsule-meta-harness/src/lib.rs","lineNumber":79,"sourceCode":"    pub fn on_message_received(&self, payload: serde_json::Value) -> Result<(), SysError> {\n        let request: HookRequest = match serde_json::from_value(payload) {\n            Ok(request) => request,\n            Err(error) => {\n                log::warn(format!(\"meta-harness: malformed hook request: {error}\"));\n                return Ok(());\n            }\n        };\n        let Some(correlation_id) = request.correlation_id else {\n            return Ok(());\n        };\n        if !is_correlation(&correlation_id) {\n            log::warn(\"meta-harness: ignored unroutable hook correlation\");\n            return Ok(());\n        }\n        let canonical: CanonicalHostPayload = match serde_json::from_str(&request.payload) {\n            Ok(canonical) => canonical,\n            Err(error) => {\n                log::warn(format!(\n                    \"meta-harness: malformed canonical payload: {error}\"\n                ));\n                return Ok(());\n            }\n        };\n        if canonical.source_event != \"user_prompt_submit\"\n            || !matches!(canonical.host.as_str(), \"codex\" | \"claude\" | \"grok\")\n            || canonical.session_id.is_empty()\n        {\n            return Ok(());\n        }\n        let Some(context) = activation_context()? else {\n            return Ok(());\n        };\n        ipc::publish_json(\n            &format!(\"hook.v1.response.message_received.{correlation_id}\"),\n            &serde_json::json!({ \"additional_context\": context }),\n        )","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/capsules/capsule-meta-harness/src/lib.rs#L61-L97","documentation":"After the HookRequest parses and a correlation_id routes it, meta-harness parses request.payload (a JSON string) into CanonicalHostPayload. If the embedded canonical payload string does not deserialize, this warning is logged and the hook returns Ok(()), skipping reflection for the turn.","triggerScenarios":"request.payload is a JSON string that fails serde_json::from_str::<CanonicalHostPayload> — inner JSON malformed, missing required fields like source_event, or wrong field types inside the nested payload.","commonSituations":"Producer of the canonical payload changed its schema (e.g., renamed source_event); double-encoding issues where payload is an object rather than a string; truncated payloads from upstream.","solutions":["Print request.payload and validate it against CanonicalHostPayload's expected fields; fix the emitting side.","Add or relax serde attributes (deny_unknown_fields removal, Option fields) to match the current canonical schema.","Ensure the sender serializes the canonical payload as a JSON string, not an object, if the struct expects from_str.","Pin/upgrade capsule-meta-harness and payload producer to matching versions."],"exampleFix":"// before\nlet canonical: CanonicalHostPayload = serde_json::from_str(&request.payload)?;\n// after\n// ensure payload contains required fields, e.g. {\"source_event\":\"user_prompt_submit\", ...}\nlet canonical: CanonicalHostPayload = serde_json::from_str(&request.payload)?;","handlingStrategy":"validation","validationCode":"// validate inner canonical payload before dispatch\nconst inner = JSON.parse(request.payload);\nif (inner.source_event !== 'user_prompt_submit') throw new Error('unsupported event');","typeGuard":"fn is_canonical(s: &str) -> bool {\n    serde_json::from_str::<CanonicalHostPayload>(s).is_ok()\n}","tryCatchPattern":"let canonical: CanonicalHostPayload = match serde_json::from_str(&request.payload) {\n    Ok(c) => c,\n    Err(e) => { log::warn(\"malformed canonical payload: {e}\"); return Ok(()); }\n};","preventionTips":["Serialize canonical payload as a JSON string, not a nested object","Version the canonical payload schema","Round-trip test producer output against the consumer struct"],"tags":["json","deserialization","schema","hook"],"backgroundTag":"json-unmarshal-failed","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"}