sgl-project/sglang · error · RuntimeError
Rust sources under {crate.workspace} changed during the buil
Error message
Rust sources under {crate.workspace} changed during the build; the result was not cached What it means
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.
Source
Thrown at python/sglang/srt/rust_extensions/loader.py:126
lock_path = (
cache_root / "locks" / f"{crate.package}-{context.target_fingerprint}.lock"
)
with _filesystem_lock(lock_path):
if mode != "force" and extension_path.is_file():
return _load_extension_from_path(crate.python_module, extension_path)
if mode == "never":
raise ModuleNotFoundError(
f"{crate.python_module} is not bundled or cached, and Rust extension "
"build mode is 'never'",
name=crate.python_module,
)
target_dir = cache_root / "targets" / context.target_fingerprint
artifact = _cargo_build(crate, target_dir)
if _source_digest(crate.workspace) != context.source_digest:
raise RuntimeError(
f"Rust sources under {crate.workspace} changed during the build; "
"the result was not cached"
)
_stage_atomically(artifact, extension_path)
return _load_extension_from_path(crate.python_module, extension_path)
def _import_bundled_extension(module_name: str) -> ModuleType | None:
try:
return importlib.import_module(module_name)
except ModuleNotFoundError as exc:
if exc.name == module_name:
return None
raise
def _discover_crate(workspace: Path, python_module: str) -> _CrateSpec:
workspace = Path(workspace).resolve()View on GitHub (pinned to 0132848349)
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
Defensive patterns
Strategy: retry
Try / catch
try:
mod = load_rust_extension(module, workspace)
except RuntimeError as e:
if "changed during the build" in str(e):
mod = load_rust_extension(module, workspace) # retry once after edits settle
else:
raise Prevention
- Don't run formatters/codegen on the Rust workspace during extension builds
- Snapshot or freeze sources before building in CI
When it happens
Trigger: Calling load_rust_extension while Rust sources under the crate workspace are being modified (editor auto-format, codegen, git checkout) concurrently with the build.
Common situations: 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.
Related errors
- Rust workspace for {python_module} was not found at {workspa
- {lockfile} is required for reproducible `cargo build --locke
- {manifest} declares python-module {python_module!r} but must
- failed to build {crate.python_module} with Cargo
- Cargo completed but did not produce the expected artifact {a
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5af5e3985a9c84bf.
Report an issue: GitHub.