{"record":{"id":"ea927172628698df","repo":"xai-org/x-algorithm","slug":"key-sha256-mismatch","errorCode":null,"errorMessage":"{key}: sha256 mismatch","messagePattern":"(.+?): sha256 mismatch","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"bdsm/runtime/load_backbone.py","lineNumber":33,"sourceCode":"    if manifest_path is not None:\n        with open(manifest_path) as f:\n            manifest = json.load(f)\n        entries = manifest[\"params\"]\n        if set(entries) != set(flat):\n            missing = sorted(set(entries) - set(flat))\n            extra = sorted(set(flat) - set(entries))\n            raise ValueError(f\"key mismatch vs manifest: missing={missing} extra={extra}\")\n        for key, arr in flat.items():\n            meta = entries[key]\n            if list(arr.shape) != meta[\"shape\"] or str(arr.dtype) != meta[\"dtype\"]:\n                raise ValueError(\n                    f\"{key}: got {arr.shape}/{arr.dtype}, \"\n                    f\"manifest says {meta['shape']}/{meta['dtype']}\"\n                )\n            if verify_hashes:\n                digest = hashlib.sha256(np.ascontiguousarray(arr).tobytes()).hexdigest()\n                if digest != meta[\"sha256\"]:\n                    raise ValueError(f\"{key}: sha256 mismatch\")\n\n    params: dict[str, dict[str, np.ndarray]] = {}\n    for key, arr in flat.items():\n        module, _, name = key.partition(\"/\")\n        params.setdefault(module, {})[name] = arr\n    return params\n","sourceCodeStart":15,"sourceCodeEnd":40,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/bdsm/runtime/load_backbone.py#L15-L40","documentation":"With verify_hashes enabled, each parameter array is serialized (ascontiguousarray + tobytes) and sha256-hashed; a digest differing from the manifest's recorded sha256 means the weight bytes changed (silent corruption or a different checkpoint) and loading fails.","triggerScenarios":"Bit-level corruption of the npz (bad disk, interrupted write); weights re-saved with identical shapes/dtypes but different values; mixed artifacts where the manifest belongs to another checkpoint; different memory layout producing different bytes.","commonSituations":"Partial download/sync of model artifacts; storage-level corruption; tamper detection working as intended; cross-platform export differences.","solutions":["Re-download/re-sync the backbone artifacts (npz + MANIFEST.json) from the source of truth","If weights legitimately changed, regenerate the manifest so hashes match","Verify disk/filesystem health if corruption is suspected","Keep verify_hashes=True in production; only bypass in trusted local debugging"],"exampleFix":"# integrity check outside the loader:\npython -c \"import hashlib,numpy as np; a=np.load('/m/backbone.npz')[key]; print(hashlib.sha256(np.ascontiguousarray(a).tobytes()).hexdigest())\"","handlingStrategy":"validation","validationCode":"import hashlib, numpy as np\nfor k, arr in np.load(npz_path).items():\n    d = hashlib.sha256(np.ascontiguousarray(arr).tobytes()).hexdigest()\n    assert d == manifest['params'][k]['sha256'], k","typeGuard":null,"tryCatchPattern":"try:\n    load_params(npz_path, manifest_path, verify_hashes=True)\nexcept ValueError as e:\n    if 'sha256 mismatch' in str(e):\n        re_download_artifacts()\n    raise","preventionTips":["Keep verify_hashes=True in all production loads","Checksum artifacts right after download and before load","Store artifacts on checksumming/redundant storage"],"tags":["python","model-loading","sha256","corruption"],"backgroundTag":"artifact-checksum-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}