sgl-project/sglang · error · RuntimeError

config not published for role {role!r}: {detail}. The proces

Error message

config not published for role {role!r}: {detail}. The process entry publishes -- add publish(server_args, role=...) there rather than publishing from a constructor.

What it means

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.

Source

Thrown at python/sglang/srt/runtime_context.py:1400

    discarding every `override()` taken since and the provenance log with it,
    so this raises.
    """
    if _CONTEXT._server_args is server_args and _CONTEXT._publish_role == role:
        return _CONTEXT
    if _CONTEXT._server_args is None:
        detail = "nothing is published in this process"
    elif _CONTEXT._server_args is not server_args:
        detail = (
            "a different record is published "
            f"(role={_CONTEXT._publish_role!r}); this constructor was handed "
            "one the process never published"
        )
    else:
        detail = (
            f"this record is published under role "
            f"{_CONTEXT._publish_role!r}, not {role!r}"
        )
    raise RuntimeError(
        f"config not published for role {role!r}: {detail}. The process entry "
        "publishes -- add publish(server_args, role=...) there rather than "
        "publishing from a constructor."
    )


def publish_role() -> str | None:
    """The role recorded by the last ``publish`` (None for a legacy set)."""
    return _CONTEXT._publish_role


def get_stream(name: str) -> Any:
    return _CONTEXT.get_stream(name)


def set_stream(name: str, stream: Any) -> Any:
    return _CONTEXT.set_stream(name, stream)

View on GitHub (pinned to 0132848349)

Solutions

  1. Add publish(server_args, role=...) at your process entry point with the role the reader requires
  2. 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)
  3. In tests, publish the expected role in setUp before instantiating the guarded component

Example fix

# before
class MyComponent:
    def __init__(self):
        self.x = ctx.config_value("field", role="scheduler")  # nothing published
# after
# at process entry:
publish(server_args, role="scheduler")
c = MyComponent()
Defensive patterns

Strategy: validation

Validate before calling

from sglang.srt.runtime_context import _CONTEXT
published_role = getattr(_CONTEXT, "_publish_role", None)
if published_role != required_role:
    raise RuntimeError(f"publish under role {required_role!r} before this component")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/3d5a836650436c1d. Report an issue: GitHub.