Skip to content

fix(cli): pass --clear to uv venv in rebuild_venv to avoid Windows brick - #39044

Closed
teknium1 wants to merge 1 commit into
mainfrom
hermes/hermes-de8f5c66
Closed

fix(cli): pass --clear to uv venv in rebuild_venv to avoid Windows brick#39044
teknium1 wants to merge 1 commit into
mainfrom
hermes/hermes-de8f5c66

Conversation

@teknium1

@teknium1 teknium1 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

hermes update no longer bricks the install on Windows when it rebuilds the venv.

When the running interpreter lives inside the venv being rebuilt, Windows locks python.exe, so shutil.rmtree(..., ignore_errors=True) silently leaves a half-deleted directory (pyvenv.cfg gone, Scripts/python.exe still present). The subsequent uv venv then aborts with A directory already exists, leaving a broken venv → ModuleNotFoundError: hermes_cli.

Changes

  • hermes_cli/managed_uv.py: pass --clear to uv venv in rebuild_venv() so uv replaces any leftover directory rmtree couldn't fully remove.
  • tests/hermes_cli/test_managed_uv.py: 2 regression tests (--clear is passed; rebuild succeeds when rmtree leaves residue).

Validation

Before After
uv venv over leftover residue error: A directory already exists (brick) succeeds, valid pyvenv.cfg

Verified live with a real uv binary: no---clear returns exit 2 with the exact "A directory already exists" error; --clear returns 0 and produces a working venv. 17/17 test_managed_uv.py pass.

Fixes #37881.

Salvaged from #37895 by @jackjin1997 (clean implementation against current managed_uv.py); also supersedes @kyssta-exe's #37965 / #38051, which fixed the same bug from a stale fork base. Credit to both contributors.

Infographic

windows-venv-brick-fix

On Windows, `hermes update` can leave a half-deleted venv that bricks the
install. `rebuild_venv` calls `shutil.rmtree(venv_dir, ignore_errors=True)`
on the venv that hosts the currently running interpreter — `python.exe` is
locked by Windows, so `Scripts/python.exe` survives while `pyvenv.cfg` is
deleted. `uv venv` is then called without `--clear` and aborts with
"A directory already exists", leaving the venv unusable (no `pyvenv.cfg`)
and every subsequent `uv pip install -e .` failing with "No virtual
environment found". The CLI itself dies with `ModuleNotFoundError:
hermes_cli`.

Add `--clear` to the `uv venv` invocation so uv replaces the leftover
directory itself. `shutil.rmtree(ignore_errors=True)` is retained as a
defense-in-depth fast path for POSIX systems where it succeeds outright.

Fixes #37881
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-de8f5c66 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9802 on HEAD, 9802 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5086 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1

teknium1 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing as already fixed on main.

The Windows venv brick (#37881) was fixed in c136eb4 ("fix(update): harden venv rebuild + verify core deps after install"), which uses the same --clear mechanism you identified — implemented as a conditional retry (only retries with --clear when uv's stderr reports "already exists", so it doesn't mask real failures like disk-full or interpreter-download errors), plus a post-install dependency-verification pass as belt-and-suspenders.

Thanks for the clean fix and the precise root-cause writeup — you correctly diagnosed the locked-python.exe / rmtree interaction. Credit to you for independently landing on the right mechanism.

@teknium1 teknium1 closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: hermes update bricks the install on Windows — venv rebuild leaves a venv with no pyvenv.cfg, then ModuleNotFoundError: hermes_cli

2 participants