{"record":{"id":"d28424e3c725c8ab","repo":"vllm-project/vllm","slug":"unsupported-data-type-for-serialization-type-dat","errorCode":null,"errorMessage":"Unsupported data type for serialization: {type(data)}","messagePattern":"Unsupported data type for serialization: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vllm/distributed/device_communicators/shm_object_storage.py","lineNumber":523,"sourceCode":"    def copy_to_buffer(\n        self,\n        data: bytes | list[bytes],\n        data_bytes: int,\n        metadata: bytes,\n        md_bytes: int,\n        data_view: memoryview,\n    ) -> None:\n        data_view[self.flag_bytes : self.flag_bytes + md_bytes] = metadata\n        if isinstance(data, bytes):\n            data_view[-data_bytes:] = data\n        elif isinstance(data, list):\n            start_idx = self.flag_bytes + md_bytes\n            for item_bytes in data:\n                item_size = len(item_bytes)\n                data_view[start_idx : start_idx + item_size] = item_bytes\n                start_idx += item_size\n        else:\n            raise ValueError(f\"Unsupported data type for serialization: {type(data)}\")\n\n    def increment_writer_flag(self, id: int) -> None:\n        \"\"\"Set the in-use flag for the writer.\"\"\"\n        self.writer_flag[id] = self.writer_flag.get(id, 0) + 1\n\n    def increment_reader_flag(self, data_view: memoryview) -> None:\n        \"\"\"Set the in-use flag for the reader.\"\"\"\n        # >0 for in-use flag\n        reader_count = self.ring_buffer.byte2int(data_view)\n        data_view[:] = self.ring_buffer.int2byte(reader_count + 1)\n\n    def free_unused(self) -> None:\n        \"\"\"Free unused buffers in the ring buffer.\"\"\"\n        # try to free up 2*max_object_size bytes of space in the ring buffer,\n        # since the buffer might be fragmented\n        freed_ids = self.ring_buffer.free_buf(\n            self.default_is_free_check, 2 * self.max_object_size\n        )","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/distributed/device_communicators/shm_object_storage.py#L505-L541","documentation":"The write path of ShmObjectStorage expects `data` to be either bytes (single pickle/serialized blob) or a list of bytes chunks (multimodal items). The branch that copies data into the shared memory view raises ValueError for anything else, guarding against writing a malformed layout into shm.","triggerScenarios":"A custom ObjectSerde.serialize() returning a data payload that is e.g. a torch.Tensor, str, numpy array, or list of non-bytes items instead of bytes/list[bytes]; the writer then hits this when storing the object.","commonSituations":"Extending ShmObjectStorage with a new serde class whose serialize() return contract is misunderstood; refactors that changed serialize()'s return type from bytes to memoryview or bytearray without casting.","solutions":["Fix serialize() to return (bytes, data_bytes, metadata, md_bytes) with the payload strictly bytes or list[bytes]","Convert memoryview/bytearray payloads with bytes(...) before returning","Add a unit test asserting the serde's return types match the write path's expectations"],"exampleFix":"# before\ndef serialize(self, value):\n    return memoryview(buf), n, md, md_n  # ValueError in writer\n\n# after\ndef serialize(self, value):\n    return bytes(buf), n, md, md_n","handlingStrategy":"type-guard","validationCode":"data, data_bytes, md, md_bytes = serde.serialize(value)\nassert isinstance(data, (bytes, list)), \"serialize() must return bytes or list[bytes]\"","typeGuard":"def serde_payload_ok(data) -> bool:\n    return isinstance(data, bytes) or (\n        isinstance(data, list) and all(isinstance(x, bytes) for x in data)\n    )","tryCatchPattern":null,"preventionTips":["Pin the serde contract: payload is bytes | list[bytes] only","Cast memoryview/bytearray to bytes at the serde boundary","Property-test serde round-trips including exotic payload types"],"tags":["serialization","api-misuse","type-error"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}