Skip to content

Commit 866531c

Browse files
Pin Ulysses vLLM installs to verified uv lock
1 parent 00b139a commit 866531c

6 files changed

Lines changed: 255 additions & 13 deletions

File tree

‎.env.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ SEARXNG_INSTANCE=http://localhost:8080
9494
# ULYSSES_COLIBRI_HY3_MODEL=/home/your-user/colibri-models/UnderstandLing--Hy3-colibri-int4
9595
# ULYSSES_COLIBRI_GLM_PORT=8642
9696
# ULYSSES_COLIBRI_HY3_PORT=8643
97+
#
98+
# Optional exact vLLM/CUDA environment contract. When this absolute local path
99+
# points to a complete uv-compiled requirements lock, Cookbook replaces generic
100+
# "pip install -U vllm" controls with an idempotent uv Reconcile action. Remote
101+
# SSH targets keep their own normal package flow.
102+
# ULYSSES_VLLM_LOCK=/home/your-user/Odysseus/Ulysses-state/locks/ulysses-vllm-cuda13.lock
97103

98104
# ============================================================
99105
# Auth & Security

‎routes/cookbook_helpers.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ def _pip_install_no_cache(cmd: str) -> str:
189189
Disabling the cache for these one-off installs keeps them off the home disk
190190
(the maintainer's suggested ``PIP_CACHE_DIR=`` workaround, made the default).
191191
Idempotent; leaves non-pip-install commands untouched."""
192-
if not cmd or "pip install" not in cmd or "--no-cache-dir" in cmd:
192+
if not cmd or "pip install" not in cmd:
193+
return cmd
194+
if re.search(r"(?:^|\s)uv\s+pip\s+install(?:\s|$)", cmd):
195+
if "--no-cache" in cmd:
196+
return cmd
197+
return cmd.replace("pip install", "pip install --no-cache", 1)
198+
if "--no-cache-dir" in cmd:
193199
return cmd
194200
return cmd.replace("pip install", "pip install --no-cache-dir", 1)
195201

@@ -611,7 +617,7 @@ def _bash_squote(v: str) -> str:
611617
"vllm", "llama-server", "llama-server.exe", "llama_server", "llama.cpp", "ollama",
612618
"python", "python3",
613619
"sglang", "lmdeploy",
614-
"node", "npx",
620+
"node", "npx", "uv",
615621
}
616622

617623

@@ -732,6 +738,13 @@ def _check_serve_binary(seg: str) -> None:
732738
f"cmd binary '{base or '(empty)'}' is not allowed. Must start with one of: "
733739
f"{', '.join(sorted(_SERVE_CMD_ALLOWLIST))}",
734740
)
741+
if base == "uv":
742+
uv_index = tokens.index(first)
743+
if tokens[uv_index + 1:uv_index + 3] != ["pip", "install"]:
744+
raise HTTPException(
745+
400,
746+
"uv is allowed here only for a direct 'uv pip install' dependency task.",
747+
)
735748

736749

737750
def _is_safe_serve_subshell(subshell: str) -> bool:

‎routes/shell_routes.py‎

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,67 @@ def _reject_cross_site(request: Request):
7777

7878
_SSH_PORT_RE = re.compile(r"^\d{1,5}$")
7979
_SAFE_VENV_RE = re.compile(r"^[A-Za-z0-9_./~-]+$")
80+
_LOCKED_REQUIREMENT_RE = re.compile(
81+
r"^([A-Za-z0-9][A-Za-z0-9._-]*)==([^\s;\\]+)(?:\s*;.*)?$"
82+
)
83+
_ULYSSES_VLLM_LOCK_PACKAGES = (
84+
"vllm",
85+
"torch",
86+
"torchaudio",
87+
"torchvision",
88+
"triton",
89+
)
90+
91+
92+
def _ulysses_vllm_lock_contract(*, remote_host: str | None = None) -> dict | None:
93+
"""Describe the configured, exact Ulysses vLLM environment contract.
94+
95+
The lock belongs to this Ulysses host. A selected SSH target keeps the
96+
upstream generic package flow because a local absolute path has no meaning
97+
on another machine.
98+
"""
99+
if (remote_host or "").strip():
100+
return None
101+
import sys
102+
103+
# A managed lock must never target the base interpreter. Ulysses owns only
104+
# the inner environment from which the app is currently running.
105+
if sys.prefix == sys.base_prefix:
106+
return None
107+
python_path = Path(sys.executable).resolve()
108+
venv_path = Path(sys.prefix).resolve()
109+
if not python_path.is_file() or not (venv_path / "pyvenv.cfg").is_file():
110+
return None
111+
configured = os.getenv("ULYSSES_VLLM_LOCK", "").strip()
112+
if not configured:
113+
return None
114+
lock_path = Path(configured).expanduser()
115+
if not lock_path.is_absolute() or not lock_path.is_file():
116+
return None
117+
118+
versions: dict[str, str] = {}
119+
try:
120+
for raw_line in lock_path.read_text(encoding="utf-8").splitlines():
121+
match = _LOCKED_REQUIREMENT_RE.fullmatch(raw_line.strip())
122+
if match:
123+
versions[match.group(1).lower().replace("_", "-")] = match.group(2)
124+
except OSError:
125+
return None
126+
127+
required = {
128+
name: versions.get(name)
129+
for name in _ULYSSES_VLLM_LOCK_PACKAGES
130+
}
131+
if any(version is None for version in required.values()):
132+
return None
133+
return {
134+
"mode": "uv-lock",
135+
"lock_path": str(lock_path.resolve()),
136+
"python": str(python_path),
137+
"venv": str(venv_path),
138+
"versions": required,
139+
"exact": True,
140+
}
80141

81142

82143
def _ssh_base_argv(host: str, ssh_port: str | None) -> list[str]:
@@ -314,6 +375,24 @@ def _package_pip_update_status(
314375
"", # Note is empty because IT DOES allow for updates outside of PIP.
315376
)
316377

378+
managed_install = pkg.get("managed_install")
379+
if (
380+
pkg.get("name") == "vllm"
381+
and isinstance(managed_install, dict)
382+
and managed_install.get("mode") == "uv-lock"
383+
):
384+
versions = managed_install.get("versions") or {}
385+
pinned = versions.get("vllm")
386+
return PackageUpdateStatus(
387+
False,
388+
(
389+
f"Managed by the Ulysses uv lock (vLLM {pinned}); "
390+
"Reconcile reapplies the verified CUDA stack without upgrading to latest."
391+
if pinned
392+
else "Managed by the Ulysses uv lock; generic pip upgrades are disabled."
393+
),
394+
)
395+
317396
if pkg.get("kind") == "system" or not pkg.get("pip"):
318397
return PackageUpdateStatus(
319398
False, "Update this system dependency outside Odysseus."
@@ -1307,7 +1386,7 @@ async def list_packages(
13071386
{
13081387
"name": "vllm",
13091388
"pip": "vllm",
1310-
"desc": "Great for high-throughput multi-GPU inference",
1389+
"desc": "Great for high-throughput GPU inference",
13111390
"category": "LLM",
13121391
"target": "remote",
13131392
},
@@ -1579,7 +1658,15 @@ async def list_packages(
15791658
if not target_os_id and platform_l in {"darwin", "macos", "mac"}:
15801659
target_os_id = "macos"
15811660

1661+
managed_vllm = _ulysses_vllm_lock_contract(remote_host=host)
15821662
for pkg in packages:
1663+
if pkg["name"] == "vllm" and managed_vllm:
1664+
pkg["managed_install"] = managed_vllm
1665+
versions = managed_vllm["versions"]
1666+
pkg["desc"] = (
1667+
f"Verified CUDA stack: vLLM {versions['vllm']}, "
1668+
f"Torch {versions['torch']}, Triton {versions['triton']}"
1669+
)
15831670
if pkg.get("name") in {"mflux", "boogu_image_mlx", "mlx_vlm", "mlx_lama_swift", "mlx_ddcolor_swift"}:
15841671
is_apple_target = target_os_id == "macos" or (
15851672
not host and IS_APPLE_SILICON
@@ -1824,6 +1911,17 @@ async def install_package(request: Request):
18241911
}
18251912
if pip_name not in known:
18261913
return {"ok": False, "error": f"Unknown package: {pip_name}"}
1914+
if pip_name == "vllm":
1915+
managed_vllm = _ulysses_vllm_lock_contract()
1916+
if managed_vllm:
1917+
return {
1918+
"ok": False,
1919+
"error": (
1920+
"vLLM is managed by the configured Ulysses uv lock. "
1921+
"Use the asynchronous Install/Reconcile action in Cookbook."
1922+
),
1923+
"managed_install": managed_vllm,
1924+
}
18271925
cmd = [_sys.executable, "-m", "pip", "install", pip_name]
18281926
proc = await asyncio.create_subprocess_exec(
18291927
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE

‎static/js/cookbook.js‎

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,13 @@ async function _fetchDependencies() {
12771277
// so the user can watch the pip install in the Running tab.
12781278
let _rebuildBtn = '';
12791279
if (pkg.name === 'vllm' && pkg.installed) {
1280-
_rebuildBtn = `<button type="button" class="cookbook-dep-tag cookbook-dep-rebuild cookbook-dep-reinstall" data-reinstall-pkg="vllm" title="Force-reinstall vLLM (pulls a matching torch). Runs as a tmux task in the Running tab.">Reinstall</button>`;
1280+
const managed = pkg.managed_install?.mode === 'uv-lock';
1281+
const managedData = managed
1282+
? ` data-managed-install-mode="uv-lock" data-managed-lock="${esc(pkg.managed_install.lock_path || '')}" data-managed-python="${esc(pkg.managed_install.python || '')}" data-managed-venv="${esc(pkg.managed_install.venv || '')}"`
1283+
: '';
1284+
_rebuildBtn = managed
1285+
? `<button type="button" class="cookbook-dep-tag cookbook-dep-rebuild cookbook-dep-reinstall" data-reinstall-pkg="vllm"${managedData} title="Reconcile the exact uv-locked CUDA/vLLM stack in Ulysses' inner .venv.">Reconcile</button>`
1286+
: `<button type="button" class="cookbook-dep-tag cookbook-dep-rebuild cookbook-dep-reinstall" data-reinstall-pkg="vllm" title="Force-reinstall vLLM (pulls a matching torch). Runs as a tmux task in the Running tab.">Reinstall</button>`;
12811287
} else if (pkg.name === 'sglang' && pkg.installed) {
12821288
_rebuildBtn = `<button type="button" class="cookbook-dep-tag cookbook-dep-rebuild cookbook-dep-reinstall" data-reinstall-pkg="sglang" title="Force-reinstall SGLang (pulls a matching torch). Runs as a tmux task in the Running tab.">Reinstall</button>`;
12831289
}
@@ -1312,7 +1318,8 @@ async function _fetchDependencies() {
13121318
+ `<button type="button" class="cookbook-dep-tag cookbook-dep-cmd-copy" data-dep-cmd-copy="${esc(_gpuWheelCmd)}" title="Copy command to clipboard">Copy command</button>`
13131319
+ `</div>`
13141320
: '';
1315-
return `<div class="cookbook-dep-row${winBlocked ? ' cookbook-dep-blocked' : ''}" data-pkg-name="${esc(pkg.name)}" data-dep-pip="${esc(pkg.pip || '')}" data-dep-target="${isLocal ? 'local' : 'remote'}" data-dep-kind="${esc(pkg.kind || 'python')}">`
1321+
const managed = pkg.managed_install || {};
1322+
return `<div class="cookbook-dep-row${winBlocked ? ' cookbook-dep-blocked' : ''}" data-pkg-name="${esc(pkg.name)}" data-dep-pip="${esc(pkg.pip || '')}" data-dep-target="${isLocal ? 'local' : 'remote'}" data-dep-kind="${esc(pkg.kind || 'python')}" data-managed-install-mode="${esc(managed.mode || '')}" data-managed-lock="${esc(managed.lock_path || '')}" data-managed-python="${esc(managed.python || '')}" data-managed-venv="${esc(managed.venv || '')}">`
13161323
+ `<div class="cookbook-dep-info">`
13171324
+ `<div class="memory-item-title">${_depGlyphHtml(pkg.name)}${esc(pkg.name)}</div>`
13181325
+ `<div class="memory-item-meta" style="font-size:10px;opacity:0.5;margin-top:2px;">${esc(pkg.desc)}</div>`
@@ -1624,7 +1631,7 @@ async function _fetchDependencies() {
16241631
// Shared install/update routine — used by the Install button and the
16251632
// "Update" item in an installed package's ⋮ menu. `upgrade` adds pip -U;
16261633
// `statusEl`, when given, shows "Installing…/Updating…" and is disabled.
1627-
async function _installDep(pipName, pkgName, isLocalOnly, upgrade, statusEl) {
1634+
async function _installDep(pipName, pkgName, isLocalOnly, upgrade, statusEl, managedInstall = null) {
16281635
let targetServer = null;
16291636
if (isLocalOnly) {
16301637
_envState.remoteHost = '';
@@ -1639,7 +1646,17 @@ async function _fetchDependencies() {
16391646
}
16401647
const targetHost = isLocalOnly ? 'this server' : ((targetServer?.host || _envState.remoteHost) || 'local');
16411648
let targetEnv = isLocalOnly ? 'none' : (targetServer?.env || _envState.env || 'none');
1642-
const targetEnvPath = isLocalOnly ? '' : (targetServer?.envPath || _envState.envPath || '');
1649+
let targetEnvPath = isLocalOnly ? '' : (targetServer?.envPath || _envState.envPath || '');
1650+
const _managedVllm = (
1651+
pipName === 'vllm'
1652+
&& managedInstall?.mode === 'uv-lock'
1653+
&& !targetServer?.host
1654+
&& !_envState.remoteHost
1655+
);
1656+
if (_managedVllm) {
1657+
targetEnv = 'venv';
1658+
targetEnvPath = managedInstall.venv || targetEnvPath;
1659+
}
16431660
if (!isLocalOnly && targetEnvPath && (!targetEnv || targetEnv === 'none')) {
16441661
targetEnv = /(?:^|\/)(?:\.?venv|env)(?:\/|$)|\/bin\/activate$/i.test(targetEnvPath) ? 'venv' : targetEnv;
16451662
}
@@ -1673,7 +1690,10 @@ async function _fetchDependencies() {
16731690
.map(_shellQuote)
16741691
.join(' ');
16751692
const depTaskId = String(pkgName || pipName || 'dependency').trim().replace(/\s+/g, '_');
1676-
const cmd = `${_py} -m pip install${upgrade ? ' -U' : ''}${_pipFlags} ${pipArgs}`;
1693+
if (_managedVllm && managedInstall.python) _py = managedInstall.python;
1694+
const cmd = _managedVllm
1695+
? `uv pip install --python ${_shellQuote(_py)} -r ${_shellQuote(managedInstall.lock)} --strict`
1696+
: `${_shellQuote(_py)} -m pip install${upgrade ? ' -U' : ''}${_pipFlags} ${pipArgs}`;
16771697
let envPrefix = '';
16781698
if (_isWindows()) {
16791699
if (targetEnv === 'venv' && targetEnvPath) {
@@ -1722,8 +1742,9 @@ async function _fetchDependencies() {
17221742
// model) so the running-task card doesn't offer a "Serve →" button.
17231743
const payload = { repo_id: depTaskId, _cmd: cmd, remote_host: targetRemoteHost || '', _dep: true, env_path: targetEnvPath || '', platform: targetPlatform || '' };
17241744
_addTask(data.session_id, 'pip ' + pkgName, 'download', payload);
1725-
if (statusEl) { statusEl.textContent = upgrade ? 'Updating...' : 'Installing...'; statusEl.disabled = true; }
1726-
uiModule.showToast(`${upgrade ? 'Updating' : 'Installing'} ${pkgName} on ${targetHost}...`);
1745+
const verb = _managedVllm ? 'Reconciling' : (upgrade ? 'Updating' : 'Installing');
1746+
if (statusEl) { statusEl.textContent = `${verb}...`; statusEl.disabled = true; }
1747+
uiModule.showToast(`${verb} ${pkgName} on ${targetHost}...`);
17271748
} catch (err) {
17281749
uiModule.showToast('Install failed: ' + err.message, {
17291750
duration: 20000,
@@ -1738,8 +1759,17 @@ async function _fetchDependencies() {
17381759
btn.addEventListener('click', async (e) => {
17391760
e.stopPropagation();
17401761
const pipName = btn.dataset.depPip;
1741-
const pkgName = btn.closest('.cookbook-dep-row')?.querySelector('.memory-item-title')?.textContent || pipName;
1742-
await _installDep(pipName, pkgName, btn.dataset.depTarget === 'local', !!btn.dataset.upgrade, btn);
1762+
const row = btn.closest('.cookbook-dep-row');
1763+
const pkgName = row?.querySelector('.memory-item-title')?.textContent || pipName;
1764+
const managedInstall = row?.dataset.managedInstallMode === 'uv-lock'
1765+
? {
1766+
mode: 'uv-lock',
1767+
lock: row.dataset.managedLock || '',
1768+
python: row.dataset.managedPython || '',
1769+
venv: row.dataset.managedVenv || '',
1770+
}
1771+
: null;
1772+
await _installDep(pipName, pkgName, btn.dataset.depTarget === 'local', !!btn.dataset.upgrade, btn, managedInstall);
17431773
});
17441774
});
17451775

@@ -2075,7 +2105,15 @@ async function _fetchDependencies() {
20752105
it.addEventListener('click', async (e) => {
20762106
e.stopPropagation();
20772107
close();
2078-
await _installDep(pipName, pkgName, isLocalOnly, true, null);
2108+
const managedInstall = row.dataset.managedInstallMode === 'uv-lock'
2109+
? {
2110+
mode: 'uv-lock',
2111+
lock: row.dataset.managedLock || '',
2112+
python: row.dataset.managedPython || '',
2113+
venv: row.dataset.managedVenv || '',
2114+
}
2115+
: null;
2116+
await _installDep(pipName, pkgName, isLocalOnly, true, null, managedInstall);
20792117
});
20802118
dropdown.appendChild(it);
20812119
if (rowPkgName === 'llama_cpp') {
@@ -2459,6 +2497,25 @@ function _wireTabEvents(body) {
24592497
if (sel) _applyServerSelection(sel.value);
24602498
const host = _envState.remoteHost || '';
24612499
const where = host || 'this server';
2500+
const managed = btn.dataset.managedInstallMode === 'uv-lock';
2501+
if (managed) {
2502+
const lock = btn.dataset.managedLock || '';
2503+
const python = btn.dataset.managedPython || '';
2504+
const venv = btn.dataset.managedVenv || '';
2505+
if (!lock || !python || !venv || host) {
2506+
uiModule.showToast('Managed vLLM reconcile is available only for this Ulysses host and its configured inner .venv.', 9000);
2507+
return;
2508+
}
2509+
if (!confirm(`Reconcile the verified vLLM/CUDA stack in ${venv}?\n\nThis uses uv and the configured exact lock. It will not upgrade to latest.`)) return;
2510+
_envState.env = 'venv';
2511+
_envState.envPath = venv;
2512+
_launchServeTask(
2513+
'reconcile-vllm',
2514+
'uv-lock-reconcile',
2515+
`uv pip install --python ${_shellQuote(python)} -r ${_shellQuote(lock)} --strict`,
2516+
);
2517+
return;
2518+
}
24622519
if (!confirm(`Reinstall ${pkg} on ${where}?\n\nRuns "pip install --force-reinstall --no-deps ${pkg}" as a tmux task. Watch progress in the Running tab.`)) return;
24632520
const _venvPy = (_envState.env === 'venv' && _envState.envPath)
24642521
? `${_envState.envPath.replace(/\/+$/, '')}/bin/python3`

‎tests/test_cookbook_helpers.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,12 @@ def test_pip_install_no_cache_injects_flag():
875875
"python -m pip install --no-cache-dir vllm"
876876
assert _pip_install_no_cache("pip install -q huggingface-hub") == \
877877
"pip install --no-cache-dir -q huggingface-hub"
878+
assert _pip_install_no_cache(
879+
"uv pip install --python /srv/Ulysses/.venv/bin/python -r /srv/vllm.lock"
880+
) == (
881+
"uv pip install --no-cache --python /srv/Ulysses/.venv/bin/python "
882+
"-r /srv/vllm.lock"
883+
)
878884

879885

880886
def test_pip_install_no_cache_is_idempotent_and_scoped():
@@ -885,6 +891,18 @@ def test_pip_install_no_cache_is_idempotent_and_scoped():
885891
# not a pip install -> unchanged
886892
assert _pip_install_no_cache("vllm serve --model x") == "vllm serve --model x"
887893
assert _pip_install_no_cache("") == ""
894+
uv_already = "uv pip install --no-cache --python /tmp/.venv/bin/python -r /tmp/vllm.lock"
895+
assert _pip_install_no_cache(uv_already) == uv_already
896+
897+
898+
def test_validate_serve_cmd_accepts_only_uv_pip_install():
899+
cmd = (
900+
"uv pip install --python /srv/Ulysses/.venv/bin/python "
901+
"-r /srv/Ulysses-state/locks/vllm.lock --strict"
902+
)
903+
assert _validate_serve_cmd(cmd) == cmd
904+
with pytest.raises(HTTPException, match="only for a direct"):
905+
_validate_serve_cmd("uv run arbitrary.py")
888906

889907

890908
def test_cached_model_scan_runs_additional_hf_cache(tmp_path):

0 commit comments

Comments
 (0)