{"record":{"id":"1b4c1b31fa50b2fa","repo":"sgl-project/sglang","slug":"sglang-role-namespaces-value-r-is-not-one-of-off","errorCode":null,"errorMessage":"SGLANG_ROLE_NAMESPACES={value!r} is not one of off / record / enforce — refusing to guess (a typo here would silently disable enforcement.)","messagePattern":"SGLANG_ROLE_NAMESPACES=(.+?) is not one of off / record / enforce — refusing to guess \\(a typo here would silently disable enforcement\\.\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/runtime_context.py","lineNumber":1228,"sourceCode":"    # exercise the multimodal processors, LoRA/score endpoints, the disagg\n    # roles, or the gRPC bridge; narrowing needs those shapes audited too, and\n    # a wrong set fails a request rather than a test.\n    \"tokenizer\": None,\n    # Deployment shapes not exercised locally; audit before restricting.\n    \"detokenizer\": None,\n    \"encoder\": None,\n    \"expert_backup\": None,\n    \"weight_cache_daemon\": None,\n    # The diffusion GPU worker runs a model and publishes a placeholder so\n    # shared SRT reads do not fail closed; declared full for that reason.\n    \"diffusion_gpu_worker\": None,\n}\n\n\ndef _validated_role_ns_mode(value: str) -> str:\n    mode = value.strip().lower()\n    if mode not in (\"off\", \"record\", \"enforce\"):\n        raise ValueError(\n            f\"SGLANG_ROLE_NAMESPACES={value!r} is not one of off / record / \"\n            \"enforce — refusing to guess (a typo here would silently disable \"\n            \"enforcement).\"\n        )\n    return mode\n\n\ndef _role_ns_mode_from_env() -> str:\n    # Resolved once at import so the config_bag gate stays a dynamo-prunable\n    # constant; validated fail-loud here (EnvField's warn-and-default parse\n    # would silently turn a typo into \"off\").\n    from sglang.srt.environ import envs\n\n    return _validated_role_ns_mode(envs.SGLANG_ROLE_NAMESPACES.get())\n\n\n_ROLE_NS_MODE = _role_ns_mode_from_env()\n_RECORDED_NS_READS: set[tuple[str | None, str]] = set()","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/runtime_context.py#L1210-L1246","documentation":"SGLANG_ROLE_NAMESPACES must normalize (strip+lowercase) to exactly off, record, or enforce. Any other value raises this ValueError because silently treating a typo like 'enforec' as 'off' would disable namespace enforcement without warning — the check is deliberately fail-closed.","triggerScenarios":"Setting SGLANG_ROLE_NAMESPACES to a typo (e.g. 'enforec'), a boolean-ish value ('1', 'true'), or a value with stray quotes/whitespace, then triggering _validated_role_ns_mode via the env read at startup.","commonSituations":"Typos in deployment env vars (k8s manifests, .env files, CI yaml); stale docs recommending old values like 'true'; shell exports that leave literal quotes in the value.","solutions":["Fix the value to exactly off, record, or enforce","Check how the env var was exported — surrounding quotes or whitespace become part of the value (e.g. export VAR=\"enforce \" keeps the space)","If you don't need role namespaces, unset the variable entirely rather than setting a wrong value"],"exampleFix":"# before\nexport SGLANG_ROLE_NAMESPACES=\"enforce \"  # or a typo like enforec\n# after\nexport SGLANG_ROLE_NAMESPACES=enforce","handlingStrategy":"validation","validationCode":"import os\nv = os.environ.get(\"SGLANG_ROLE_NAMESPACES\")\nif v is not None and v.strip().lower() not in {\"off\", \"record\", \"enforce\"}:\n    raise ValueError(\"SGLANG_ROLE_NAMESPACES must be off/record/enforce\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set env vars in one place (deployment manifest) and validate them at startup","Avoid quoting env var values in shell exports","Prefer unsetting the var over guessing a value"],"tags":["environment-variable","config-validation","typo","sglang"],"backgroundTag":"invalid-env-var-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}