{"record":{"id":"eafe7c6222ab3652","repo":"sgl-project/sglang","slug":"invalid-json-mapping-normalized-input","errorCode":null,"errorMessage":"Invalid JSON mapping: {normalized_input}","messagePattern":"Invalid JSON mapping: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py","lineNumber":54,"sourceCode":"    if normalized_input.endswith(\".json\"):\n        if not os.path.isfile(normalized_input):\n            raise RuntimeError(f\"File {normalized_input} does not exist.\")\n        try:\n            with open(normalized_input, \"r\", encoding=\"utf-8\") as file:\n                mapping = json.load(file)\n        except json.JSONDecodeError as exc:\n            raise RuntimeError(\n                f\"Failed to parse JSON content from file {normalized_input}\"\n            ) from exc\n        except (IOError, OSError) as exc:\n            raise RuntimeError(\n                f\"Failed to read JSON file {normalized_input}: {exc}\"\n            ) from exc\n    else:\n        try:\n            mapping = json.loads(normalized_input)\n        except json.JSONDecodeError as exc:\n            raise ValueError(f\"Invalid JSON mapping: {normalized_input}\") from exc\n\n    if not isinstance(mapping, dict):\n        raise ValueError(\n            \"Invalid format: expected a mapping from GPU id to IB device string\"\n        )\n\n    normalized_mapping: Dict[int, str] = {}\n    for gpu_key, ib_devices in mapping.items():\n        normalized_key = int(gpu_key) if str(gpu_key).isdigit() else None\n        if normalized_key is None or not isinstance(ib_devices, str):\n            raise ValueError(\n                \"Invalid format: keys must be integers (or string \"\n                \"representations of integers) and values must be strings\"\n            )\n        normalized_mapping[normalized_key] = ib_devices.strip()\n\n    if not normalized_mapping:\n        raise ValueError(\"No valid GPU mappings found in JSON\")","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/distributed/device_communicators/mooncake_transfer_engine.py#L36-L72","documentation":"The IB-device config string started with '{' (detected as an inline JSON mapping) but json.loads could not parse it as JSON. parse_ib_device_config raises ValueError with the raw input embedded, chained from JSONDecodeError identifying the syntax position.","triggerScenarios":"Passing an inline mapping string like \"{'0': 'mlx5_0'}\" (single quotes), trailing commas, or a stray '{' prefix, instead of strict double-quoted JSON in the CLI/file argument.","commonSituations":"Copy-pasting a Python dict literal into --mooncake-ip-device, shell quoting that mangles or truncates the JSON, or forgetting to close the braces.","solutions":["Use strict JSON with double quotes and no trailing commas: --mooncake-ip-device '{\"0\": \"mlx5_0\", \"1\": \"mlx5_2\"}'","Test the literal locally: echo '<value>' | python -m json.tool","Simplify: if a single IB device applies to all GPUs, pass the plain device string without braces"],"exampleFix":"# before\n--mooncake-ip-device \"{'0': 'mlx5_0'}\"   # Python-style -> ValueError\n\n# after\n--mooncake-ip-device '{\"0\": \"mlx5_0\"}'  # strict JSON","handlingStrategy":"validation","validationCode":"import json\n\ndef validate_inline_ib_mapping(cfg: str) -> dict:\n    s = cfg.strip()\n    if s.startswith(\"{\"):\n        return json.loads(s)  # fail fast with exact position\n    return s","typeGuard":null,"tryCatchPattern":"try:\n    mapping = parse_ib_device_config(cfg)\nexcept ValueError as e:\n    raise ConfigError(f\"inline IB mapping is not strict JSON: {e}\") from e","preventionTips":["Always double-quote keys and values in inline JSON CLI args","Shell-quote the whole argument; verify with echo \"$CFG\" | python -m json.tool","Pass a plain device string when no per-GPU mapping is needed"],"tags":["json","config","mooncake","cli"],"backgroundTag":"invalid-json-config","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}