{"record":{"id":"27f17d7e6c6af566","repo":"jax-ml/jax","slug":"malformed-pickled-sequencekey-expected-1-tuple","errorCode":null,"errorMessage":"Malformed pickled SequenceKey, expected 1-tuple","messagePattern":"Malformed pickled SequenceKey, expected 1-tuple","errorType":"exception","errorClass":"XlaRuntimeError","httpStatus":null,"severity":"error","filePath":"jaxlib/pytree.cc","lineNumber":1937,"sourceCode":"  });\n\n  nb::class_<SequenceKey> sequence_key(\n      pytree, \"SequenceKey\", nb::sig(\"class SequenceKey(typing.Hashable)\"));\n  sequence_key.def(nb::init<int>(), nb::arg(\"idx\"));\n  sequence_key.def(\"__str__\", &SequenceKey::ToString);\n  sequence_key.def(\"__repr__\", &SequenceKey::ToReprString);\n  sequence_key.def(\"__eq__\", &SequenceKey::Equals);\n  sequence_key.def(\"__hash__\", [](const SequenceKey& key) {\n    return key.idx() + kSequenceKeyHashSalt;\n  });\n  sequence_key.def_prop_ro(\"idx\", &SequenceKey::idx);\n  sequence_key.def_prop_ro_static(\"__match_args__\", &SequenceKey::MatchArgs);\n  sequence_key.def(\"__getstate__\",\n                   [](SequenceKey& key) { return nb::make_tuple(key.idx()); });\n  sequence_key.def(\"__setstate__\",\n                   [](SequenceKey& key, const nb::tuple& state) {\n                     if (state.size() != 1) {\n                       throw xla::XlaRuntimeError(\n                           \"Malformed pickled SequenceKey, expected 1-tuple\");\n                     }\n                     new (&key) SequenceKey(nb::cast<int>(state[0]));\n                   });\n\n  nb::class_<DictKey> dict_key(pytree, \"DictKey\",\n                               nb::type_slots(DictKey::slots_),\n                               nb::sig(\"class DictKey(typing.Hashable)\"));\n  dict_key.def(nb::init<nb::object>(), nb::arg(\"key\").none());\n  dict_key.def(\"__str__\", &DictKey::ToString);\n  dict_key.def(\"__repr__\", &DictKey::ToReprString);\n  dict_key.def(\"__eq__\", &DictKey::Equals);\n  dict_key.def(\"__hash__\",\n               [](const DictKey& key) { return nanobind::hash(key.key()); });\n  dict_key.def_prop_ro(\"key\", &DictKey::key);\n  dict_key.def_prop_ro_static(\"__match_args__\", &DictKey::MatchArgs);\n  dict_key.def(\"__getstate__\",\n               [](DictKey& key) { return nb::make_tuple(key.key()); });","sourceCodeStart":1919,"sourceCodeEnd":1955,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/pytree.cc#L1919-L1955","documentation":"SequenceKey.__setstate__ requires its pickled state to be a 1-tuple containing the integer index. Any other tuple length is rejected as malformed.","triggerScenarios":"Unpickling a jaxlib.pytree.SequenceKey (an entry in treedef node paths) whose pickled state tuple doesn't have exactly one element, e.g. crafted or version-skewed pickles.","commonSituations":"Manually constructing/reconstructing key objects; pickles produced by an older jaxlib that serialized different fields.","solutions":["Don't hand-build pickle state; unpickle objects produced by the same jaxlib","Re-pickle via __getstate__ after upgrading","Upgrade both environments to matching jaxlib versions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def valid_seq_key_state(s) -> bool:\n    return isinstance(s, tuple) and len(s) == 1 and isinstance(s[0], int)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't construct pickle state manually for jaxlib.pytree keys"],"tags":["jax","pytree","pickle"],"backgroundTag":"pickle-format-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}