sgl-project/sglang · critical · RuntimeError

--sidecar requires module {module_name!r} to expose a callab

Error message

--sidecar requires module {module_name!r} to expose a callable main(argv).

What it means

SGLang's sidecar launcher successfully imported the requested module but the `main` attribute it found is not callable. The sidecar protocol requires main(argv) as a function; anything else (a variable, class instance without __call__, None) triggers this error.

Source

Thrown at python/sglang/srt/entrypoints/sidecar.py:73

    parsed, provider_args = parser.parse_known_args(args or [])
    if parsed.sidecar_shutdown_timeout <= 0:
        raise ValueError("--sidecar-shutdown-timeout must be greater than 0.")
    return provider_args, parsed.sidecar_shutdown_timeout


def _run_sidecar(module_name: str, args: list[str], endpoint: str) -> None:
    kill_itself_when_parent_died()
    os.environ[SGLANG_GRPC_ENDPOINT_ENV] = endpoint
    try:
        main = getattr(importlib.import_module(module_name), "main")
    except (AttributeError, ImportError) as e:
        raise RuntimeError(
            f"--sidecar requires importable module {module_name!r} "
            "with a main(argv) function."
        ) from e

    if not callable(main):
        raise RuntimeError(
            f"--sidecar requires module {module_name!r} to expose "
            "a callable main(argv)."
        )

    main(args)


class Sidecar:
    def __init__(
        self,
        proc,
        module_name: str,
        shutdown_timeout: float,
    ):
        self.proc = proc
        self.module_name = module_name
        self.shutdown_timeout = shutdown_timeout
        self._watchdog = SubprocessWatchdog(

View on GitHub (pinned to 0132848349)

Solutions

  1. Define a plain function: def main(argv: list[str]) -> None (or a callable returning one)
  2. Check for accidental reassignment/shadowing of `main` in the module namespace
  3. If using a class, expose main = MyClass() where the instance implements __call__

Example fix

# before
main = SidecarRunner  # class, not callable instance
# after
def main(argv):
    SidecarRunner().run(argv)
Defensive patterns

Strategy: validation

Validate before calling

import importlib
mod = importlib.import_module(module_name)
assert callable(getattr(mod, "main", None)), f"{module_name}.main must be callable"

Type guard

def has_callable_main(mod) -> bool:
    return callable(getattr(mod, "main", None))

Prevention

When it happens

Trigger: --sidecar module where module.main is assigned a non-callable value, e.g. `main = None`, `main = some_object`, or main was shadowed by an import.

Common situations: Refactoring a sidecar module and turning main into a variable, accidentally shadowing `main` with an import (`from x import main` where x.main is data), or writing a class without instantiating it as the entry point.

Related errors


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