{"record":{"id":"3b5af2b4f3964ff2","repo":"sgl-project/sglang","slug":"sglang-rust-server-is-not-supported-with-the-offli","errorCode":null,"errorMessage":"SGLANG_RUST_SERVER is not supported with the offline Engine API; it only replaces the HTTP server path (`sglang serve`). Unset SGLANG_RUST_SERVER to use sgl.Engine.","messagePattern":"SGLANG_RUST_SERVER is not supported with the offline Engine API; it only replaces the HTTP server path \\(`sglang serve`\\)\\. Unset SGLANG_RUST_SERVER to use sgl\\.Engine\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/entrypoints/engine.py","lineNumber":258,"sourceCode":"        # so hooks on ServerArgs.__post_init__ fire correctly.\n        load_plugins()\n\n        # Parse server_args\n        if \"server_args\" in kwargs:\n            # Directly load server_args\n            server_args = kwargs[\"server_args\"]\n        else:\n            # Construct server_args from kwargs\n            if \"log_level\" not in kwargs:\n                # Do not print logs by default\n                kwargs[\"log_level\"] = \"error\"\n            server_args = self.server_args_class(**kwargs)\n        self.server_args = server_args\n        logger.info(f\"server_args={server_args.resolved_dict()}\")\n\n        # Rust Server is not supported with the offline Engine API\n        if envs.SGLANG_RUST_SERVER.get():\n            raise ValueError(\n                \"SGLANG_RUST_SERVER is not supported with the offline Engine \"\n                \"API; it only replaces the HTTP server path (`sglang serve`). \"\n                \"Unset SGLANG_RUST_SERVER to use sgl.Engine.\"\n            )\n\n        # Pre-initialize tokenizer_manager so the atexit handler in\n        # shutdown() won't hit AttributeError.\n        self.tokenizer_manager = None\n\n        # Shutdown the subprocesses automatically when the program exits\n        atexit.register(self.shutdown)\n\n        # Launch subprocesses\n        (\n            tokenizer_manager,\n            template_manager,\n            port_args,\n            scheduler_init_result,","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/engine.py#L240-L276","documentation":"sgl.Engine (the offline Python Engine API) does not support SGLANG_RUST_SERVER. That env var only swaps the HTTP server frontend used by `sglang serve` for a Rust implementation; the offline Engine spawns schedulers directly and has no HTTP path to replace. Constructing sgl.Engine with the env var set raises ValueError immediately after server_args resolution.","triggerScenarios":"Calling sgl.Engine(**kwargs) (or srt.Engine) in a process where the SGLANG_RUST_SERVER environment variable is set to a truthy value, e.g. exported earlier for a `sglang serve` run and reused in the same shell/notebook for offline generation.","commonSituations":"Switching between serving and offline batch inference in the same environment; CI images that bake SGLANG_RUST_SERVER=1 in globally; docker exec sessions inheriting the variable from the server container.","solutions":["Unset the variable before creating the engine: `env -u SGLANG_RUST_SERVER python script.py` or `SGLANG_RUST_SERVER= python script.py`.","In Python, run `os.environ.pop(\"SGLANG_RUST_SERVER\", None)` before instantiating sgl.Engine.","If you actually want the Rust server path, use `sglang serve` (the HTTP entrypoint) instead of sgl.Engine.","Audit shell profiles, Dockerfiles, and CI env blocks for a globally exported SGLANG_RUST_SERVER."],"exampleFix":"# before\nimport sglang as sgl\nengine = sgl.Engine(model_path=\"...\")  # ValueError: SGLANG_RUST_SERVER set\n\n# after\nimport os\nos.environ.pop(\"SGLANG_RUST_SERVER\", None)\nimport sglang as sgl\nengine = sgl.Engine(model_path=\"...\")","handlingStrategy":"validation","validationCode":"import os, sglang as sgl\nassert not os.environ.get(\"SGLANG_RUST_SERVER\"), (\n    \"unset SGLANG_RUST_SERVER before using sgl.Engine\")\nengine = sgl.Engine(...)","typeGuard":null,"tryCatchPattern":"try:\n    engine = sgl.Engine(**kwargs)\nexcept ValueError as e:\n    if \"SGLANG_RUST_SERVER\" in str(e):\n        os.environ.pop(\"SGLANG_RUST_SERVER\", None)\n        engine = sgl.Engine(**kwargs)\n    else:\n        raise","preventionTips":["Keep separate shell profiles/scripts for `sglang serve` and offline sgl.Engine usage.","At the top of offline scripts, pop SGLANG_RUST_SERVER from os.environ defensively.","Scan CI env blocks for SGLANG_* overrides before adding offline-engine jobs."],"tags":["sglang","environment-variable","offline-engine","startup"],"backgroundTag":"invalid-env-var-combination","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}