Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(migrations): keep the toolchain heal from raising on an unreadable nodeenv cache (#35986)

Yassin Kortamde0065536381
diff --git a/.github/workflows/image-scan.yml b/.github/workflows/image-scan.yml
index 23aa6114f08..4d0acb0b6e5 100644
--- a/.github/workflows/image-scan.yml
+++ b/.github/workflows/image-scan.yml
@@ -11,7 +11,8 @@ on:
- docker/Dockerfile.non_root
- migrations/Dockerfile
- migrations/run.py
- - tests/proxy_migration_tests/test_offline_image_migration.py
+ - litellm-proxy-extras/**
+ - tests/proxy_migration_tests/**
- uv.lock
- ui/litellm-dashboard/package-lock.json
- .github/workflows/image-scan.yml
diff --git a/litellm-proxy-extras/litellm_proxy_extras/prisma_toolchain.py b/litellm-proxy-extras/litellm_proxy_extras/prisma_toolchain.py
index 76c22d0f8ce..f3b55fd4d96 100644
--- a/litellm-proxy-extras/litellm_proxy_extras/prisma_toolchain.py
+++ b/litellm-proxy-extras/litellm_proxy_extras/prisma_toolchain.py
@@ -121,9 +121,13 @@ def heal_incomplete_nodeenv_cache() -> bool:
Prisma invocation reinstalls it instead of failing on a missing binary.
"""
cache_dir = nodeenv_cache_dir()
- if cache_dir is None or not cache_dir.is_dir():
+ if cache_dir is None:
return False
- if node_binary_path(cache_dir).exists():
+ try:
+ if not cache_dir.is_dir() or node_binary_path(cache_dir).exists():
+ return False
+ except OSError as e:
+ logger.warning("Could not inspect the Node toolchain at %s: %s", cache_dir, e)
return False
logger.warning(
"Node toolchain at %s has no %s, so a previous install was interrupted. "
diff --git a/tests/proxy_migration_tests/test_prisma_toolchain.py b/tests/proxy_migration_tests/test_prisma_toolchain.py
index e68ec57028c..d12a2c4dd4e 100644
--- a/tests/proxy_migration_tests/test_prisma_toolchain.py
+++ b/tests/proxy_migration_tests/test_prisma_toolchain.py
@@ -119,6 +119,32 @@ def test_absent_toolchain_is_not_an_error(toolchain_env: tuple[Path, Path]) -> N
assert not cache_dir.exists()
+_CAN_DENY_ACCESS = os.name != "nt" and hasattr(os, "geteuid") and os.geteuid() != 0
+
+
+ not _CAN_DENY_ACCESS, reason="root and Windows do not honour a 0o000 directory"
+)
+def test_unreadable_cache_dir_is_not_an_error(
+ toolchain_env: tuple[Path, Path],
+) -> None:
+ """A cache dir this process cannot stat means nothing to heal, not a crash.
+
+ Images bake the cache under the build user's home, and a container started
+ under any other uid cannot search that directory. `Path.is_dir()` only
+ swallows ENOENT-shaped errnos, so it raises `PermissionError` there and
+ kills the migration before Prisma is ever invoked.
+ """
+ cache_dir, _ = toolchain_env
+ _make_incomplete_cache(cache_dir)
+ cache_dir.parent.chmod(0o000)
+
+ try:
+ assert heal_incomplete_nodeenv_cache() is False
+ finally:
+ cache_dir.parent.chmod(0o700)
+
+
def test_bootstrap_clears_the_cache_before_invoking_prisma(
toolchain_env: tuple[Path, Path],
) -> None: