{"record":{"id":"810e7c8c366c3fef","repo":"xai-org/x-algorithm","slug":"failed-to-serialize-servedhistory-e","errorCode":null,"errorMessage":"failed to serialize ServedHistory: {e}","messagePattern":"failed to serialize ServedHistory: (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"home-mixer/clients/served_history_client.rs","lineNumber":165,"sourceCode":"                }\n            }\n        }\n\n        Ok(entries)\n    }\n\n    async fn put(\n        &self,\n        user_id: u64,\n        timeline_type: TimelineType,\n        client_platform: i32,\n        served_time_ms: i64,\n        history: &ServedHistory,\n    ) -> Result<()> {\n        let pkey = timeline_pkey(timeline_type, user_id, client_platform);\n        let lkey = vec![(i64::MAX - served_time_ms).to_be_bytes().to_vec()];\n        let value = xai_x_thrift::serialize_compact(history)\n            .map_err(|e| anyhow::anyhow!(\"failed to serialize ServedHistory: {e}\"))?;\n\n        self.client\n            .put(self.tenant.clone(), pkey, lkey, value)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"MH put failed: {e}\"))\n    }\n\n    async fn delete(\n        &self,\n        user_id: u64,\n        timeline_type: TimelineType,\n        client_platform: i32,\n        served_times_ms: &[i64],\n    ) -> Result<()> {\n        let pkey = timeline_pkey(timeline_type, user_id, client_platform);\n        for &ts in served_times_ms {\n            let lkey = vec![(i64::MAX - ts).to_be_bytes().to_vec()];\n            self.client","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/home-mixer/clients/served_history_client.rs#L147-L183","documentation":"Raised in put when xai_x_thrift::serialize_compact fails to serialize the ServedHistory struct into compact Thrift bytes before writing to Manhattan. This is a data-shape problem: the struct cannot be encoded, so nothing is written.","triggerScenarios":"Calling put() with a ServedHistory containing fields the compact Thrift writer cannot encode (e.g. malformed nested enums, invalid UTF-8, or a schema/struct definition mismatch between writer and thrift definitions).","commonSituations":"Schema evolution where a new field type isn't supported by serialize_compact; corrupt/inconsistent struct invariants; version skew between the xai-x-thrift crate and the ServedHistory definition.","solutions":["Log and inspect the exact ServedHistory values that fail to serialize; look for newly added or invalid fields","Pin/align the xai-x-thrift crate version with the ServedHistory schema version","Add a unit test that round-trips serialize_compact/deserialize_compact for representative ServedHistory values","Reject/normalize invalid fields upstream before constructing ServedHistory"],"exampleFix":"// before\nlet value = xai_x_thrift::serialize_compact(history)\n    .map_err(|e| anyhow::anyhow!(\"failed to serialize ServedHistory: {e}\"))?;\n\n// after\nlet value = xai_x_thrift::serialize_compact(history)\n    .map_err(|e| {\n        tracing::error!(error = ?e, history = ?history, \"ServedHistory serialization failed\");\n        anyhow::anyhow!(\"failed to serialize ServedHistory: {e}\")\n    })?;","handlingStrategy":"validation","validationCode":"fn valid_served_history(h: &ServedHistory) -> bool { /* check invariants: known enum values, valid utf-8, non-negative where required */ true }","typeGuard":"fn is_serializable(h: &ServedHistory) -> bool { xai_x_thrift::serialize_compact(h).is_ok() }","tryCatchPattern":"// Fail fast at construction; serialization errors are deterministic and non-retryable","preventionTips":["Round-trip unit tests for ServedHistory serialization","Schema-version pin the thrift crate","Validate struct invariants before put()"],"tags":["thrift","serialization","schema","rust"],"backgroundTag":"thrift-serialization-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}