{"record":{"id":"6f19069067c11955","repo":"sgl-project/sglang","slug":"cannot-msgpack-decode-object-of-type-type-obj-a","errorCode":null,"errorMessage":"Cannot msgpack decode object of type {type(obj)} as {tp} with dec_hook. Use an explicit PickleWrapper field via wrap_as_pickle(...) and unwrap_from_pickle(...) for arbitrary payloads, or add a dedicated enc_hook/dec_hook branch for this transport type.","messagePattern":"Cannot msgpack decode object of type (.+?) as (.+?) with dec_hook\\. Use an explicit PickleWrapper field via wrap_as_pickle\\(\\.\\.\\.\\) and unwrap_from_pickle\\(\\.\\.\\.\\) for arbitrary payloads, or add a dedicated enc_hook/dec_hook branch for this transport type\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/msgpack_utils.py","lineNumber":213,"sourceCode":"        \"for this transport type.\"\n    )\n\n\ndef dec_hook(tp: type, obj: object) -> object:\n    if isinstance(obj, tp):\n        return obj\n    if tp is array:\n        typecode, raw_data = obj\n        res = array(typecode)\n        res.frombytes(raw_data)\n        return res\n    if tp is torch.Tensor:\n        shape, dtype, data, *device = obj\n        return _restore_torch_tensor(shape, dtype, data, device[0] if device else \"cpu\")\n    if tp is np.ndarray:\n        shape, dtype, data = obj\n        return np.frombuffer(data, dtype=np.dtype(dtype)).copy().reshape(shape)\n    raise TypeError(\n        f\"Cannot msgpack decode object of type {type(obj)} as {tp} with \"\n        \"dec_hook. Use an explicit PickleWrapper field via wrap_as_pickle(...) \"\n        \"and unwrap_from_pickle(...) for arbitrary payloads, or add a \"\n        \"dedicated enc_hook/dec_hook branch for this transport type.\"\n    )\n\n\ndef ext_hook(code: int, data: memoryview) -> object:\n    if code not in (\n        _MSGPACK_EXT_ARRAY,\n        _MSGPACK_EXT_TORCH_TENSOR,\n        _MSGPACK_EXT_NP_ARRAY,\n        _MSGPACK_EXT_SHM_POINTER_MM_DATA,\n        _MSGPACK_EXT_CUDA_IPC_TENSOR_PROXY,\n    ):\n        return msgspec.msgpack.Ext(code, bytes(data))\n\n    if code == _MSGPACK_EXT_ARRAY:","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/msgpack_utils.py#L195-L231","documentation":"The mirror of the encode-side error: dec_hook only knows how to reconstruct a few types (torch.Tensor, np.ndarray) from their msgpack tuples. Hitting the raise means the packed stream tagged an ext/annotated type as something dec_hook cannot rebuild — arbitrary payloads must travel as PickleWrapper fields.","triggerScenarios":"msgpack.unpackb(raw, ext_hook=ext_hook) where the payload contains a type annotation for a type dec_hook doesn't handle (not torch.Tensor/np.ndarray and not a PickleWrapper).","commonSituations":"Cross-version mismatch: sender added a new transport type branch that the receiver's dec_hook lacks; or a payload packed by unrelated code being decoded with these hooks.","solutions":["Ensure the sender used wrap_as_pickle(...) for that field so the receiver can unwrap_from_pickle(...) it.","Align sender and receiver versions of sglang so both have the same enc/dec_hook branches.","Add a matching dec_hook branch if you intentionally introduced a new transport type."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    obj = msgpack.unpackb(raw, ext_hook=ext_hook)\nexcept TypeError:\n    # sender older/newer than receiver: re-route or drop message\n    logging.exception(\"wire format mismatch\"); raise","preventionTips":["Pin identical sglang versions on both ends of an IPC channel.","Version message schemas and reject unknown versions early."],"tags":["serialization","msgpack","version-mismatch"],"backgroundTag":"deserialization-type-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}