Skip to content

The agent that grows with you

fix(update): keep .venv installs whole through ZIP fallback and venv repair

teknium1659f5ae94fb5
diff --git a/apps/desktop/electron/venv-blocker-scan.test.ts b/apps/desktop/electron/venv-blocker-scan.test.ts
index 8641f061997..367e5f8760c 100644
--- a/apps/desktop/electron/venv-blocker-scan.test.ts
+++ b/apps/desktop/electron/venv-blocker-scan.test.ts
@@ -61,23 +61,6 @@ describe('resolveVenvPython', () => {
}
})
- it('uses the Windows Scripts interpreter in a uv-default .venv', () => {
- const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-vt-'))
- const platform = Object.getOwnPropertyDescriptor(process, 'platform')
-
- try {
- const dir = path.join(sandbox, '.venv', 'Scripts')
- fs.mkdirSync(dir, { recursive: true })
- const pyPath = path.join(dir, 'python.exe')
- fs.writeFileSync(pyPath, '', { mode: 0o755 })
- Object.defineProperty(process, 'platform', { value: 'win32' })
- assert.equal(resolveVenvPython(sandbox), pyPath)
- } finally {
- if (platform) Object.defineProperty(process, 'platform', platform)
- fs.rmSync(sandbox, { recursive: true, force: true })
- }
- })
-
it('keeps legacy venv precedence when both supported layouts exist', () => {
const sandbox = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-vt-'))
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index df18ca45741..b5186b5a246 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -617,7 +617,7 @@ def _repair_venv_on_current_checkout(
venv_python_missing = not venv_python_path(venv_dir, windows=_m()._is_windows()).exists()
if venv_python_missing and repair_uv:
print("→ Recreating virtual environment...")
- subprocess.run([repair_uv, "venv", "venv"], cwd=_m().PROJECT_ROOT, check=False)
+ subprocess.run([repair_uv, "venv", venv_dir.name], cwd=_m().PROJECT_ROOT, check=False)
repair_prefix, repair_env = _pip_install_prefix(repair_uv)
_m()._install_python_dependencies_with_optional_fallback(repair_prefix, env=repair_env, group="all")
_m()._refresh_active_lazy_features(repair_prefix, env=repair_env, features=active_lazy_features)
diff --git a/hermes_cli/update_cmd_deps.py b/hermes_cli/update_cmd_deps.py
index a3d1b881704..f86352acae6 100644
--- a/hermes_cli/update_cmd_deps.py
+++ b/hermes_cli/update_cmd_deps.py
@@ -951,7 +951,7 @@ def _refuse_update_if_venv_foreign_owned(project_root) -> None:
See #83529.
"""
- foreign = _venv_foreign_owned_paths(Path(project_root) / "venv")
+ foreign = _venv_foreign_owned_paths(project_venv_dir(project_root) or Path(project_root) / "venv")
if not foreign:
return
print("\n✗ Update stopped: this install's venv contains files owned by another user.")
diff --git a/hermes_cli/update_cmd_zip.py b/hermes_cli/update_cmd_zip.py
index f8f73072838..dfc219f217d 100644
--- a/hermes_cli/update_cmd_zip.py
+++ b/hermes_cli/update_cmd_zip.py
@@ -22,7 +22,7 @@ logger = logging.getLogger("hermes_cli.update_cmd")
_ZIP_STAGING_ARTIFACT_SUFFIXES = ".hermes-update-staging", ".hermes-update-old"
# Single source of truth for entries the ZIP swap preserves — used by the dirty-tree filter and the swap loop.
-_ZIP_PRESERVED_TOP_LEVEL = {"venv", "node_modules", ".git", ".env"}
+_ZIP_PRESERVED_TOP_LEVEL = {"venv", ".venv", "node_modules", ".git", ".env"}
_STASH_HINT = " Stash or commit your changes, then rerun `hermes update`."
diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1
index 56b508011ff..0dfdb9bb600 100644
--- a/scripts/desktop-update/windows.ps1
+++ b/scripts/desktop-update/windows.ps1
@@ -1545,7 +1545,7 @@ try {
# Something still maps the venv. --force-ing past it guarantees a
# half-updated venv (the exact 2026-08-09 Access-denied brick).
$finalCode = 5
- $finalMsg = "Update aborted: another process is still holding the Hermes install open (venv\Scripts\hermes.exe locked after 20s). Nothing was changed. Close other Hermes windows/terminals and try again."
+ $finalMsg = "Update aborted: another process is still holding the Hermes install open ($shim locked after 20s). Nothing was changed. Close other Hermes windows/terminals and try again."
Write-HandoffLog $finalMsg
exit $finalCode
}
diff --git a/tests/hermes_cli/test_update_venv_health.py b/tests/hermes_cli/test_update_venv_health.py
index 5e034f907b0..71dbf4c6cf5 100644
--- a/tests/hermes_cli/test_update_venv_health.py
+++ b/tests/hermes_cli/test_update_venv_health.py
@@ -121,8 +121,10 @@ def test_detect_venv_python_prefetches_only_cheap_process_fields(_winp, tmp_path
@patch.object(cli_main, "_is_windows", return_value=True)
def test_detect_venv_python_matches_uv_default_dotvenv(_winp, tmp_path):
+ """#112958: the venv-prefix arm must see a uv-default ``.venv`` interpreter. A kernel-runner child has
+ no ``hermes_cli.main`` in its cmdline, so only that arm can match it — the guard was blind to it."""
venv_py = str(tmp_path / ".venv" / "Scripts" / "python.exe")
- holder = _proc(104, venv_py, "python.exe", [venv_py, "-m", "hermes_cli.main", "serve"])
+ holder = _proc(104, venv_py, "python.exe", [venv_py, str(tmp_path / "tools" / "hermes_kernel_runner.py")])
me = MagicMock()
me.parents.return_value = []
fake_psutil = types.SimpleNamespace(
diff --git a/tests/hermes_cli/test_update_zip_fallback_guards.py b/tests/hermes_cli/test_update_zip_fallback_guards.py
index e68cf66a6f1..c72ecc407ac 100644
--- a/tests/hermes_cli/test_update_zip_fallback_guards.py
+++ b/tests/hermes_cli/test_update_zip_fallback_guards.py
@@ -276,7 +276,7 @@ def test_zip_overlay_flag_is_valid_against_real_git(tmp_path):
ignored user files.
"""
subprocess.run(["git", "init", "-q", str(tmp_path)], check=True)
- (tmp_path / ".gitignore").write_text("*.local\nvenv/\n")
+ (tmp_path / ".gitignore").write_text("*.local\nvenv/\n.venv/\n")
subprocess.run(
["git", "-C", str(tmp_path), "add", ".gitignore"], check=True
)
@@ -299,6 +299,11 @@ def test_zip_overlay_flag_is_valid_against_real_git(tmp_path):
(tmp_path / "venv").mkdir()
(tmp_path / "venv" / "lib.py").write_text("x")
assert update_cmd._zip_overlay_block_reason(tmp_path) is None
+ # uv-default ``.venv`` is a supported layout (#112958): the ignored dir is the live runtime,
+ # not user data the overlay would destroy — refusing here made ZIP fallback impossible.
+ (tmp_path / ".venv").mkdir()
+ (tmp_path / ".venv" / "lib.py").write_text("x")
+ assert update_cmd._zip_overlay_block_reason(tmp_path) is None
def test_zip_overlay_requests_ignored_files_from_git(tmp_path, monkeypatch):