{"record":{"id":"a1f49d68b2a5ef58","repo":"Unity-Technologies/ml-agents","slug":"no-brainparameters-found-in-demonstration-file-at","errorCode":null,"errorMessage":"No BrainParameters found in demonstration file at {file_path}.","messagePattern":"No BrainParameters found in demonstration file at (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/demo_loader.py","lineNumber":225,"sourceCode":"                    pos = INITIAL_POS\n                if obs_decoded == 1:\n                    brain_param_proto = BrainParametersProto()\n                    brain_param_proto.ParseFromString(data[pos : pos + next_pos])\n                    pos += next_pos\n                if obs_decoded > 1:\n                    agent_info_action = AgentInfoActionPairProto()\n                    agent_info_action.ParseFromString(data[pos : pos + next_pos])\n                    if behavior_spec is None:\n                        behavior_spec = behavior_spec_from_proto(\n                            brain_param_proto, agent_info_action.agent_info\n                        )\n                    info_action_pairs.append(agent_info_action)\n                    if len(info_action_pairs) == total_expected:\n                        break\n                    pos += next_pos\n                obs_decoded += 1\n    if not behavior_spec:\n        raise RuntimeError(\n            f\"No BrainParameters found in demonstration file at {file_path}.\"\n        )\n    return behavior_spec, info_action_pairs, total_expected\n\n\ndef write_delimited(f, message):\n    msg_string = message.SerializeToString()\n    msg_size = len(msg_string)\n    _EncodeVarint(f.write, msg_size)\n    f.write(msg_string)\n\n\ndef write_demo(demo_path, meta_data_proto, brain_param_proto, agent_info_protos):\n    with open(demo_path, \"wb\") as f:\n        # write metadata\n        write_delimited(f, meta_data_proto)\n        f.seek(INITIAL_POS)\n        write_delimited(f, brain_param_proto)","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/demo_loader.py#L207-L243","documentation":"After parsing all records in a .demo file, load_demonstration raises this RuntimeError if no BrainParameters (behavior spec) record was found. A valid demonstration file must contain a brain/behavior parameters section before agent experience records; without it the data cannot be interpreted.","triggerScenarios":"load_demonstration called on a .demo file that contains no BrainParametersProto section — e.g. a truncated, empty, or corrupt file, or a file whose INITIAL_POS (33-byte) header was stripped or malformed.","commonSituations":"Recording was interrupted in Unity so the file was never fully written; the file got corrupted in transfer (FTP ASCII mode, git LFS placeholder); someone truncated the header; the path points at a file that isn't actually a demo recording.","solutions":["Re-record the demonstration file in Unity, letting the recording finish and the editor write the complete file.","Check the file is a genuine .demo recording (non-trivial size, starts with the expected meta header) and re-copy it in binary-safe mode if it was transferred.","Restore the file from version control or a backup if it was corrupted or truncated."],"exampleFix":"// before\ndemo_path = \"demo/demo.demo\"  # 0-byte truncated file\n// after\ndemo_path = \"demo/demo.demo\"  # re-recorded, complete file","handlingStrategy":"try-catch","validationCode":"import os\npath = \"demos/my_demo.demo\"\nassert os.path.getsize(path) > 33, \"demo file too small / truncated (INITIAL_POS header missing)\"","typeGuard":"def looks_like_demo_file(path: str) -> bool:\n    import os\n    return os.path.isfile(path) and path.endswith(\".demo\") and os.path.getsize(path) > 33","tryCatchPattern":"try:\n    demo_spec, pairs, _ = load_demonstration(path)\nexcept RuntimeError as e:\n    if \"No BrainParameters found\" in str(e):\n        logger.error(\"Demo file corrupt/truncated: re-record in Unity\")\n        raise SystemExit(1)\n    raise","preventionTips":["Let Unity finish writing the demo recording before stopping play mode","Transfer .demo files in binary mode; avoid tools that mangle binary data","Check file size is non-trivial and the recording completed before training"],"tags":["ml-agents","demonstrations","corrupt-file","serialization"],"backgroundTag":"missing-behavior-parameters","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}