{"record":{"id":"5af5e3985a9c84bf","repo":"sgl-project/sglang","slug":"rust-sources-under-crate-workspace-changed-durin","errorCode":null,"errorMessage":"Rust sources under {crate.workspace} changed during the build; the result was not cached","messagePattern":"Rust sources under (.+?) changed during the build; the result was not cached","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/rust_extensions/loader.py","lineNumber":126,"sourceCode":"    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:\n        return importlib.import_module(module_name)\n    except ModuleNotFoundError as exc:\n        if exc.name == module_name:\n            return None\n        raise\n\n\ndef _discover_crate(workspace: Path, python_module: str) -> _CrateSpec:\n    workspace = Path(workspace).resolve()","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/rust_extensions/loader.py#L108-L144","documentation":"Raised by load_rust_extension after a Cargo build completes when the digest of the Rust workspace sources changed while cargo was running, meaning the produced artifact may not match the sources. The loader refuses to cache a possibly stale artifact.","triggerScenarios":"Calling load_rust_extension while Rust sources under the crate workspace are being modified (editor auto-format, codegen, git checkout) concurrently with the build.","commonSituations":"Building the Rust extension in a repo that is being actively edited, or a build tool/IDE touches Cargo.toml/sources mid-build; git operations running in parallel.","solutions":["Ensure no process modifies the Rust workspace during the build (stop formatters, codegen, git operations)","Retry the load after the concurrent modification finishes","If persistent, verify no watcher (e.g. cargo watch, dev server) rewrites sources; clean and rebuild"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    mod = load_rust_extension(module, workspace)\nexcept RuntimeError as e:\n    if \"changed during the build\" in str(e):\n        mod = load_rust_extension(module, workspace)  # retry once after edits settle\n    else:\n        raise","preventionTips":["Don't run formatters/codegen on the Rust workspace during extension builds","Snapshot or freeze sources before building in CI"],"tags":["rust","build-cache","concurrency","cargo"],"backgroundTag":"build-artifact-cache-invalidation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}