{"record":{"id":"a6f0256d8addf874","repo":"sgl-project/sglang","slug":"kimi-expert-pack-file-has-trailing-or-missing-byte","errorCode":null,"errorMessage":"Kimi expert-pack file has trailing or missing bytes","messagePattern":"Kimi expert-pack file has trailing or missing bytes","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/layers/moe/expert_pack.py","lineNumber":887,"sourceCode":"                    expert=expert,\n                    role_id=logical_role_id,\n                    dtype_id=int(roles[physical_role][\"dtype_id\"]),\n                    dtype=str(roles[physical_role][\"dtype\"]),\n                    tensor_name=name,\n                    source_slice_offset=0,\n                    source_slice_nbytes=nbytes,\n                    pack_offset=offset,\n                    pack_nbytes=nbytes,\n                    checksum=\"\",\n                    shape=logical_shape,\n                    quant_scheme=str(roles[physical_role][\"dtype\"]),\n                    transform_id=\"identity-v1\",\n                    block_size=256,\n                    generation=generation,\n                )\n\n        if previous_end != self.path.stat().st_size:\n            raise ValueError(\"Kimi expert-pack file has trailing or missing bytes\")\n        actual_index_sha256 = index_digest.hexdigest()\n        if actual_index_sha256 != pack_manifest[\"index_sha256\"]:\n            raise ValueError(\"Kimi expert-pack index SHA-256 does not match manifest\")\n        if verify_pack_sha256:\n            expected_sha256 = pack_manifest.get(\"sha256\")\n            if not expected_sha256:\n                raise ValueError(\n                    \"full pack verification requested, but manifest has no full SHA-256\"\n                )\n            if _sha256_file(self.path) != expected_sha256:\n                raise ValueError(\"Kimi expert-pack SHA-256 does not match manifest\")\n\n        self.header = ExpertPackHeader(\n            flags=REQUIRED_FLAGS,\n            index_count=expected_entry_count,\n            data_start=int(pack_manifest[\"data_start\"]),\n            alignment=int(pack_manifest[\"alignment\"]),\n            num_layers=expected_layers,","sourceCodeStart":869,"sourceCodeEnd":905,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/moe/expert_pack.py#L869-L905","documentation":"After consuming all index entries, the end of the last data blob (previous_end) does not equal the total file size — the file has trailing bytes or is missing bytes at the end. This is a whole-file structural check complementing the per-entry range checks.","triggerScenarios":"Bytes appended to the pack (concatenation, stale tail from a rewrite-in-place), or a file truncated after the last entry; also mismatched header data_start cascading here.","commonSituations":"See trigger scenarios.","solutions":["Check the file's SHA-256 against the manifest to confirm corruption; re-download/rebuild the pack","If you appended metadata to the file, move it out of the pack file"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"null","typeGuard":null,"tryCatchPattern":"try:\n    pack = KimiExpertPack(path, manifest)\nexcept ValueError as e:\n    if 'trailing or missing bytes' in str(e):\n        log.error('pack file length mismatch; verify sha256 and re-download')\n    raise","preventionTips":["Never append data to pack files","Validate stat().st_size against manifest size first"],"tags":["kimi","moe","expert-pack","file-size-mismatch"],"backgroundTag":"file-integrity-check-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}