{"record":{"id":"196a3c31653c2e01","repo":"sgl-project/sglang","slug":"expert-pack-index-role-or-rank-is-invalid","errorCode":null,"errorMessage":"expert-pack index role or rank is invalid","messagePattern":"expert-pack index role or rank is invalid","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/layers/moe/expert_pack.py","lineNumber":130,"sourceCode":"    source_slice_nbytes: int\n    pack_offset: int\n    pack_nbytes: int\n    checksum: str\n    shape: tuple[int, ...]\n    quant_scheme: str\n    transform_id: str\n    block_size: int\n    generation: int\n\n    @classmethod\n    def read(cls, stream) -> ExpertPackEntry:\n        raw = stream.read(ENTRY_STRUCT.size)\n        if len(raw) != ENTRY_STRUCT.size:\n            raise ValueError(\"expert-pack index is truncated\")\n        values = ENTRY_STRUCT.unpack(raw)\n        role_id, rank = values[2], values[3]\n        if role_id >= len(ROLE_NAMES) or not 1 <= rank <= 4:\n            raise ValueError(\"expert-pack index role or rank is invalid\")\n        return cls(\n            layer=values[0],\n            expert=values[1],\n            role_id=role_id,\n            dtype_id=values[4],\n            dtype=_fixed_string(values[5]),\n            tensor_name=_fixed_string(values[6]),\n            source_slice_offset=values[9],\n            source_slice_nbytes=values[10],\n            pack_offset=values[11],\n            pack_nbytes=values[12],\n            checksum=values[15].hex(),\n            shape=tuple(values[16 : 16 + rank]),\n            quant_scheme=_fixed_string(values[20]),\n            transform_id=_fixed_string(values[21]),\n            block_size=values[22],\n            generation=values[23],\n        )","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/moe/expert_pack.py#L112-L148","documentation":"An index entry's role_id is >= 3 (outside gate/up/down) or its rank field is outside 1..4. The per-entry rank is validated to the 1–4 range and roles to the three known names, so out-of-range values mean a malformed or incompatible entry encoding.","triggerScenarios":"ExpertPackEntry.read when values[2] (role_id) >= len(ROLE_NAMES) or values[3] (rank) is 0 or > 4 — e.g. a pack written with more roles or a different entry struct layout (struct-size skew between writer and reader).","commonSituations":"Version mismatch where the writer's ENTRY_STRUCT differs from the reader's; experimental packs with extra roles (e.g. shared experts); corrupted entry bytes.","solutions":["Rebuild the pack with the same sglang version that will read it, so ENTRY_STRUCT layouts match","Verify the reader and packer come from the same sglang release (struct sizes are also cross-checked earlier in the header)","Validate the file checksum against the manifest to rule out corruption"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def entry_ranges_ok(role_id, rank):\n    return 0 <= role_id < 3 and 1 <= rank <= 4","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the same sglang version for packing and serving so ENTRY_STRUCT layouts match","Treat any entry-level validation failure as corruption and re-verify the sha256"],"tags":["moe","expert-pack","binary-format","index-entry","version-skew"],"backgroundTag":"file-format-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}