{"record":{"id":"6cb22cc782589912","repo":"sgl-project/sglang","slug":"sidecar-requires-module-module-name-r-to-expos","errorCode":null,"errorMessage":"--sidecar requires module {module_name!r} to expose a callable main(argv).","messagePattern":"--sidecar requires module (.+?) to expose a callable main\\(argv\\)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/entrypoints/sidecar.py","lineNumber":73,"sourceCode":"    parsed, provider_args = parser.parse_known_args(args or [])\n    if parsed.sidecar_shutdown_timeout <= 0:\n        raise ValueError(\"--sidecar-shutdown-timeout must be greater than 0.\")\n    return provider_args, parsed.sidecar_shutdown_timeout\n\n\ndef _run_sidecar(module_name: str, args: list[str], endpoint: str) -> None:\n    kill_itself_when_parent_died()\n    os.environ[SGLANG_GRPC_ENDPOINT_ENV] = endpoint\n    try:\n        main = getattr(importlib.import_module(module_name), \"main\")\n    except (AttributeError, ImportError) as e:\n        raise RuntimeError(\n            f\"--sidecar requires importable module {module_name!r} \"\n            \"with a main(argv) function.\"\n        ) from e\n\n    if not callable(main):\n        raise RuntimeError(\n            f\"--sidecar requires module {module_name!r} to expose \"\n            \"a callable main(argv).\"\n        )\n\n    main(args)\n\n\nclass Sidecar:\n    def __init__(\n        self,\n        proc,\n        module_name: str,\n        shutdown_timeout: float,\n    ):\n        self.proc = proc\n        self.module_name = module_name\n        self.shutdown_timeout = shutdown_timeout\n        self._watchdog = SubprocessWatchdog(","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/sidecar.py#L55-L91","documentation":"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.","triggerScenarios":"--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.","commonSituations":"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.","solutions":["Define a plain function: def main(argv: list[str]) -> None (or a callable returning one)","Check for accidental reassignment/shadowing of `main` in the module namespace","If using a class, expose main = MyClass() where the instance implements __call__"],"exampleFix":"# before\nmain = SidecarRunner  # class, not callable instance\n# after\ndef main(argv):\n    SidecarRunner().run(argv)","handlingStrategy":"validation","validationCode":"import importlib\nmod = importlib.import_module(module_name)\nassert callable(getattr(mod, \"main\", None)), f\"{module_name}.main must be callable\"","typeGuard":"def has_callable_main(mod) -> bool:\n    return callable(getattr(mod, \"main\", None))","tryCatchPattern":null,"preventionTips":["Pin the sidecar entrypoint with a unit test asserting callable(module.main)","Never rebind `main` to a non-function in sidecar modules"],"tags":["sidecar","callable","startup","sglang"],"backgroundTag":"entrypoint-not-callable","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}