sgl-project/sglang · critical · ValueError

Kimi expert-pack file has trailing or missing bytes

Error message

Kimi expert-pack file has trailing or missing bytes

What it means

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.

Source

Thrown at python/sglang/srt/layers/moe/expert_pack.py:887

                    expert=expert,
                    role_id=logical_role_id,
                    dtype_id=int(roles[physical_role]["dtype_id"]),
                    dtype=str(roles[physical_role]["dtype"]),
                    tensor_name=name,
                    source_slice_offset=0,
                    source_slice_nbytes=nbytes,
                    pack_offset=offset,
                    pack_nbytes=nbytes,
                    checksum="",
                    shape=logical_shape,
                    quant_scheme=str(roles[physical_role]["dtype"]),
                    transform_id="identity-v1",
                    block_size=256,
                    generation=generation,
                )

        if previous_end != self.path.stat().st_size:
            raise ValueError("Kimi expert-pack file has trailing or missing bytes")
        actual_index_sha256 = index_digest.hexdigest()
        if actual_index_sha256 != pack_manifest["index_sha256"]:
            raise ValueError("Kimi expert-pack index SHA-256 does not match manifest")
        if verify_pack_sha256:
            expected_sha256 = pack_manifest.get("sha256")
            if not expected_sha256:
                raise ValueError(
                    "full pack verification requested, but manifest has no full SHA-256"
                )
            if _sha256_file(self.path) != expected_sha256:
                raise ValueError("Kimi expert-pack SHA-256 does not match manifest")

        self.header = ExpertPackHeader(
            flags=REQUIRED_FLAGS,
            index_count=expected_entry_count,
            data_start=int(pack_manifest["data_start"]),
            alignment=int(pack_manifest["alignment"]),
            num_layers=expected_layers,

View on GitHub (pinned to 0132848349)

Solutions

  1. Check the file's SHA-256 against the manifest to confirm corruption; re-download/rebuild the pack
  2. If you appended metadata to the file, move it out of the pack file
Defensive patterns

Strategy: validation

Validate before calling

null

Try / catch

try:
    pack = KimiExpertPack(path, manifest)
except ValueError as e:
    if 'trailing or missing bytes' in str(e):
        log.error('pack file length mismatch; verify sha256 and re-download')
    raise

Prevention

When it happens

Trigger: 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.

Common situations: See trigger scenarios.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/a6f0256d8addf874. Report an issue: GitHub.