{"record":{"id":"3d5a836650436c1d","repo":"sgl-project/sglang","slug":"config-not-published-for-role-role-r-detail","errorCode":null,"errorMessage":"config not published for role {role!r}: {detail}. The process entry publishes -- add publish(server_args, role=...) there rather than publishing from a constructor.","messagePattern":"config not published for role (.+?): (.+?)\\. The process entry publishes -- add publish\\(server_args, role=\\.\\.\\.\\) there rather than publishing from a constructor\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/runtime_context.py","lineNumber":1400,"sourceCode":"    discarding every `override()` taken since and the provenance log with it,\n    so this raises.\n    \"\"\"\n    if _CONTEXT._server_args is server_args and _CONTEXT._publish_role == role:\n        return _CONTEXT\n    if _CONTEXT._server_args is None:\n        detail = \"nothing is published in this process\"\n    elif _CONTEXT._server_args is not server_args:\n        detail = (\n            \"a different record is published \"\n            f\"(role={_CONTEXT._publish_role!r}); this constructor was handed \"\n            \"one the process never published\"\n        )\n    else:\n        detail = (\n            f\"this record is published under role \"\n            f\"{_CONTEXT._publish_role!r}, not {role!r}\"\n        )\n    raise RuntimeError(\n        f\"config not published for role {role!r}: {detail}. The process entry \"\n        \"publishes -- add publish(server_args, role=...) there rather than \"\n        \"publishing from a constructor.\"\n    )\n\n\ndef publish_role() -> str | None:\n    \"\"\"The role recorded by the last ``publish`` (None for a legacy set).\"\"\"\n    return _CONTEXT._publish_role\n\n\ndef get_stream(name: str) -> Any:\n    return _CONTEXT.get_stream(name)\n\n\ndef set_stream(name: str, stream: Any) -> Any:\n    return _CONTEXT.set_stream(name, stream)\n","sourceCodeStart":1382,"sourceCodeEnd":1418,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/runtime_context.py#L1382-L1418","documentation":"RuntimeError raised when a role-guarded read requires the config to be published under a specific role, but either nothing has been published yet, or the record is published under a different role. The message points at the fix: publish belongs at the process entry point (publish(server_args, role=...)), not in a constructor.","triggerScenarios":"A role-guarded helper is invoked before publish, or after publish with role='scheduler' when the caller requires role='tokenizer_manager'. Publishing from a constructor to work around it is explicitly called out as the wrong pattern.","commonSituations":"Embedding the sglang engine in another app where the entry point was skipped; tests that construct a component without publishing under the right role; refactors that moved publish calls deeper into constructors.","solutions":["Add publish(server_args, role=...) at your process entry point with the role the reader requires","If a different role is already published, re-publish with the required role — re-publish is allowed and last-publish-wins (bags re-projected, role overwritten)","In tests, publish the expected role in setUp before instantiating the guarded component"],"exampleFix":"# before\nclass MyComponent:\n    def __init__(self):\n        self.x = ctx.config_value(\"field\", role=\"scheduler\")  # nothing published\n# after\n# at process entry:\npublish(server_args, role=\"scheduler\")\nc = MyComponent()","handlingStrategy":"validation","validationCode":"from sglang.srt.runtime_context import _CONTEXT\npublished_role = getattr(_CONTEXT, \"_publish_role\", None)\nif published_role != required_role:\n    raise RuntimeError(f\"publish under role {required_role!r} before this component\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep publish at the single process entry point; never publish from constructors","Add a startup assertion that the expected role is published before constructing role-guarded components"],"tags":["runtime-context","initialization-order","roles","sglang"],"backgroundTag":"config-not-published-for-role","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}