{"record":{"id":"c0e23fcdd8a393dd","repo":"sgl-project/sglang","slug":"crate-python-module-is-not-bundled-or-cached-an","errorCode":null,"errorMessage":"{crate.python_module} is not bundled or cached, and Rust extension build mode is 'never'","messagePattern":"(.+?) is not bundled or cached, and Rust extension build mode is 'never'","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/rust_extensions/loader.py","lineNumber":117,"sourceCode":"            \"start a new Python process\"\n        )\n\n    if workspace is None:\n        workspace = _RUST_WORKSPACE\n    crate = _discover_crate(workspace, python_module)\n    context = _build_context(crate)\n    cache_root = _cache_root(cache_dir)\n    extension_path = _cached_extension_path(cache_root, crate, context.fingerprint)\n    lock_path = (\n        cache_root / \"locks\" / f\"{crate.package}-{context.target_fingerprint}.lock\"\n    )\n\n    with _filesystem_lock(lock_path):\n        if mode != \"force\" and extension_path.is_file():\n            return _load_extension_from_path(crate.python_module, extension_path)\n\n        if mode == \"never\":\n            raise ModuleNotFoundError(\n                f\"{crate.python_module} is not bundled or cached, and Rust extension \"\n                \"build mode is 'never'\",\n                name=crate.python_module,\n            )\n\n        target_dir = cache_root / \"targets\" / context.target_fingerprint\n        artifact = _cargo_build(crate, target_dir)\n        if _source_digest(crate.workspace) != context.source_digest:\n            raise RuntimeError(\n                f\"Rust sources under {crate.workspace} changed during the build; \"\n                \"the result was not cached\"\n            )\n        _stage_atomically(artifact, extension_path)\n        return _load_extension_from_path(crate.python_module, extension_path)\n\n\ndef _import_bundled_extension(module_name: str) -> ModuleType | None:\n    try:","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/rust_extensions/loader.py#L99-L135","documentation":"ModuleNotFoundError raised when build mode is 'never', the extension is neither bundled with the wheel nor present in the on-disk cache, and building is forbidden. This is the explicit, controlled outcome of choosing 'never' in an environment lacking prebuilt artifacts (common in hermetic/air-gapped deployments).","triggerScenarios":"Setting SGLANG_RUST_BUILD_MODE=never (or passing mode=\"never\") on a source checkout without a prior build, or on a wheel that does not bundle the crate; after wiping the extension cache directory so extension_path.is_file() is False.","commonSituations":"Security/hermetic environments that forbid invoking Cargo; CI images built without the Rust extensions; accidentally enabling 'never' locally while developing from source.","solutions":["Pre-build the extension once with mode auto or force (or run the repo's build step) so the cache is populated, then use never","Install a wheel that bundles the extension","If building is acceptable in your environment, switch SGLANG_RUST_BUILD_MODE to auto"],"exampleFix":"# before\nexport SGLANG_RUST_BUILD_MODE=never  # source checkout, no cache -> ModuleNotFoundError\n# after\npython -c \"from sglang.srt.rust_extensions.loader import load_rust_extension; load_rust_extension(CRATE, mode='force')\"\nexport SGLANG_RUST_BUILD_MODE=never","handlingStrategy":"validation","validationCode":"from sglang.srt.rust_extensions.loader import load_rust_extension\ntry:\n    mod = load_rust_extension(crate, mode=\"never\")\nexcept ModuleNotFoundError:\n    raise RuntimeError(\"prebuild the extension (mode auto/force) before using 'never'\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-build extensions during image build so 'never' mode never needs Cargo","Install wheels that bundle the Rust extensions in hermetic environments","Verify the extension cache directory is populated before enabling 'never' mode"],"tags":["rust-extension","missing-module","build-cache","env-var","sglang"],"backgroundTag":"missing-prebuilt-extension","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}