Skip to content

Commit 2fbc46e

Browse files
Guard vLLM repair actions with uv lock
1 parent 3e95047 commit 2fbc46e

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

‎routes/cookbook_routes.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
safe_chmod,
3232
which_tool,
3333
)
34-
from routes.shell_routes import TMUX_LOG_DIR
34+
from routes.shell_routes import TMUX_LOG_DIR, _normalize_ulysses_vllm_install
3535
from src.host_docker_access import (
3636
HOST_DOCKER_ACCESS_HINT,
3737
HOST_DOCKER_SOCKET_PATH,
@@ -2032,6 +2032,10 @@ async def model_serve(request: Request, req: ServeRequest):
20322032
local=not bool(req.remote_host),
20332033
in_venv=sys.prefix != sys.base_prefix,
20342034
)
2035+
req.cmd, managed_vllm_reconcile = _normalize_ulysses_vllm_install(
2036+
req.cmd,
2037+
remote_host=req.remote_host,
2038+
)
20352039
is_pip_install = bool(req.cmd and "pip install" in req.cmd)
20362040
if is_pip_install:
20372041
# Keep big dependency wheel builds (vLLM, …) off the home filesystem's
@@ -2205,6 +2209,11 @@ async def model_serve(request: Request, req: ServeRequest):
22052209
runner_lines.append(_safe_env_prefix(req.env_prefix))
22062210
else:
22072211
runner_lines.append("deactivate 2>/dev/null; hash -r")
2212+
if managed_vllm_reconcile:
2213+
runner_lines.append(
2214+
'echo "[ulysses] Replacing an unconstrained vLLM/Torch/Triton '
2215+
'repair with the configured exact uv lock."'
2216+
)
22082217
_append_venv_nvidia_library_path_lines(runner_lines, cmd=req.cmd)
22092218
if "sglang.launch_server" in req.cmd or "mlx_lm.server" in req.cmd or re.search(r"\bvllm\s+serve\b", req.cmd or ""):
22102219
_append_openai_port_preflight_lines(runner_lines, cmd=req.cmd, expected_model=req.repo_id)

‎routes/shell_routes.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def _reject_cross_site(request: Request):
8787
"torchvision",
8888
"triton",
8989
)
90+
_ULYSSES_VLLM_MUTATION_RE = re.compile(
91+
r"(?<![A-Za-z0-9_.-])(?:vllm|torch|torchaudio|torchvision|triton)"
92+
r"(?=$|[\s<>=!~,\[\]])",
93+
re.IGNORECASE,
94+
)
9095

9196

9297
def _ulysses_vllm_lock_contract(*, remote_host: str | None = None) -> dict | None:
@@ -143,6 +148,39 @@ def _ulysses_vllm_lock_contract(*, remote_host: str | None = None) -> dict | Non
143148
}
144149

145150

151+
def _normalize_ulysses_vllm_install(
152+
command: str,
153+
*,
154+
remote_host: str | None = None,
155+
) -> tuple[str, bool]:
156+
"""Route local vLLM/Torch/Triton pip mutations through the exact uv lock.
157+
158+
This is the server-side guard for both current and stale browser bundles:
159+
Dependencies, Reinstall, and crash-diagnosis actions all pass through the
160+
same model-serve task endpoint.
161+
"""
162+
contract = _ulysses_vllm_lock_contract(remote_host=remote_host)
163+
if (
164+
not contract
165+
or "pip install" not in (command or "")
166+
or not _ULYSSES_VLLM_MUTATION_RE.search(command)
167+
):
168+
return command, False
169+
managed = shlex.join(
170+
[
171+
"uv",
172+
"pip",
173+
"install",
174+
"--python",
175+
contract["python"],
176+
"-r",
177+
contract["lock_path"],
178+
"--strict",
179+
]
180+
)
181+
return managed, managed != command
182+
183+
146184
def _ssh_base_argv(host: str, ssh_port: str | None) -> list[str]:
147185
"""Build an ssh argv prefix for remote probes without local-shell parsing."""
148186
if not host or not str(host).strip() or str(host).lstrip().startswith("-"):

‎tests/test_shell_routes.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
_docker_row_status,
2121
_package_installed_from_probe,
2222
_package_pip_update_status,
23+
_normalize_ulysses_vllm_install,
2324
_ulysses_vllm_lock_contract,
2425
_package_probe_script,
2526
_package_status_note,
@@ -419,6 +420,33 @@ def test_vllm_uv_lock_contract_requires_complete_exact_lock(self, tmp_path, monk
419420
assert contract["venv"] == str(venv.resolve())
420421
assert _ulysses_vllm_lock_contract(remote_host="gpu@example") is None
421422

423+
normalized, changed = _normalize_ulysses_vllm_install(
424+
f"{python} -m pip install -U vllm transformers"
425+
)
426+
assert changed is True
427+
assert normalized == (
428+
f"uv pip install --python {python} -r {lock.resolve()} --strict"
429+
)
430+
431+
torch_normalized, torch_changed = _normalize_ulysses_vllm_install(
432+
f"{python} -m pip install -U torch"
433+
)
434+
assert torch_changed is True
435+
assert torch_normalized == normalized
436+
437+
generic, generic_changed = _normalize_ulysses_vllm_install(
438+
f"{python} -m pip install diffusers"
439+
)
440+
assert generic_changed is False
441+
assert generic.endswith("pip install diffusers")
442+
443+
remote, remote_changed = _normalize_ulysses_vllm_install(
444+
"python -m pip install -U vllm",
445+
remote_host="gpu@example",
446+
)
447+
assert remote_changed is False
448+
assert remote == "python -m pip install -U vllm"
449+
422450
def test_llama_cpp_is_installed_when_native_llama_server_exists(self):
423451
probe = {
424452
"modules": {"llama_cpp": {"found": False, "real_module": False}},

0 commit comments

Comments
 (0)