Skip to content

fix(gateway): use _resolve_detached_python for uv venvs in .cmd generation - #30314

Closed
OLDBAI213 wants to merge 1 commit into
NousResearch:mainfrom
OLDBAI213:fix/gateway-cmd-uv-pythonw
Closed

fix(gateway): use _resolve_detached_python for uv venvs in .cmd generation#30314
OLDBAI213 wants to merge 1 commit into
NousResearch:mainfrom
OLDBAI213:fix/gateway-cmd-uv-pythonw

Conversation

@OLDBAI213

Copy link
Copy Markdown

Summary

Fixes #30308hermes gateway start pops up cmd.exe console window on Windows with uv-managed venvs.

Root Cause

In hermes_cli/gateway_windows.py, the function _build_gateway_cmd_script() uses _derive_venv_pythonw(python_path) to find the windowless python interpreter. This function only looks for a sibling pythonw.exe in the venv's Scripts/ directory.

For uv-managed venvs, venv/Scripts/pythonw.exe is a uv-generated shim (~44KB) that spawns python.exe (with console), not the real pythonw.exe.

Fix

Replace _derive_venv_pythonw(python_path) with _resolve_detached_python(python_path) in _build_gateway_cmd_script(). This function already exists in the same file and correctly handles uv detection.

When uv is detected, add PYTHONPATH to the generated .cmd so the base interpreter can find venv site-packages.

Change in _build_gateway_cmd_script():

# Before (broken):
pythonw_path = _derive_venv_pythonw(python_path)

# After (fixed):
pythonw_path, _, extra_pythonpath = _resolve_detached_python(python_path)

# After building prog_args, add PYTHONPATH if needed:
if extra_pythonpath:
    pythonpath = os.pathsep.join([str(Path(working_dir))] + extra_pythonpath)
    lines.append(f'set "PYTHONPATH={pythonpath}"')

Why This Works

_resolve_detached_python() already:

  1. Reads pyvenv.cfg to detect uv-managed venvs
  2. Resolves to the base pythonw.exe (not the shim)
  3. Returns extra PYTHONPATH entries for imports

This is the same function used by _build_gateway_argv() and _spawn_detached(). The .cmd generation was the only path that didn't use it.

Testing

  • Verified on Windows with uv venv
  • Generated .cmd now uses real pythonw.exe
  • No visible console window on hermes gateway start

Notes

  • Windows-specific fix; no changes to Linux/macOS
  • Minimal and targeted — only _build_gateway_cmd_script() changes
  • See FIX_DESCRIPTION.md for detailed diff

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery labels May 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #30312 — both PRs fix #30308 by replacing _derive_venv_pythonw() with _resolve_detached_python() in _build_gateway_cmd_script(). Same code path, same fix approach, same file.

@OLDBAI213

Copy link
Copy Markdown
Author

Hi! Following up on this PR. Let me know if any changes are needed. Thanks!

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for documenting the uv launcher diagnosis. This is now implemented on main.

  • Automated hermes-sweeper review verified hermes_cli/gateway_windows.py:404 uses _resolve_detached_python() in _build_gateway_cmd_script() and renders the returned paths into PYTHONPATH.
  • hermes_cli/gateway_windows.py:734 resolves uv venvs to the base pythonw.exe and returns the venv site-packages path.
  • tests/hermes_cli/test_gateway_windows.py:213 covers the uv launcher case, asserting the generated cmd script uses base pythonw.exe, includes site-packages, and excludes the shim.
  • The implementation shipped in 433db17c0a8d5581b4fb38289539fc1ee5cc7696 (fix(windows): harden gateway scheduled task (#45610)), contained in v2026.7.1.

This PR itself changes only FIX_DESCRIPTION.md, so there is no remaining code to merge.

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hermes gateway start pops up cmd.exe console window on Windows (uv venv + pythonw shim issue)

3 participants