Skip to content

fix: use pythonw.exe for Windows gateway post-update restart - #49025

Closed
APEMH-IT wants to merge 1 commit into
NousResearch:mainfrom
APEMH-IT:fix/use-pythonw-for-gateway-restart
Closed

fix: use pythonw.exe for Windows gateway post-update restart#49025
APEMH-IT wants to merge 1 commit into
NousResearch:mainfrom
APEMH-IT:fix/use-pythonw-for-gateway-restart

Conversation

@APEMH-IT

Copy link
Copy Markdown

Summary

On Windows, after running hermes update, a black console window (python.exe) stays open on the desktop. The gateway works fine, but the window is visual noise and closing it kills the gateway.

Root cause

_gateway_run_args_for_profile() used get_python_path() which returns venv/Scripts/python.exe (console subsystem). The post-update gateway restart watcher spawned python.exe instead of pythonw.exe (windowless GUI subsystem).

Fix

On Windows, resolve the sibling pythonw.exe from the python.exe path returned by get_python_path(). This mirrors what Hermes_Gateway.cmd (generated by gateway_windows._build_gateway_cmd_script()) already does via _derive_venv_pythonw().

Notes

  • The fix is minimal and scoped: only _gateway_run_args_for_profile() was changed (5 lines added).
  • The change is gated by is_windows() — no impact on POSIX platforms.
  • Falls back to python.exe if pythonw.exe doesn't exist (defensive).

Testing

Tested locally on Windows 10 (git-bash). Before: console window visible after hermes update. After: no window — gateway runs cleanly in the background via pythonw.exe.

_root_cause: _gateway_run_args_for_profile() used get_python_path() which
returns venv/Scripts/python.exe (console subsystem) on Windows. After
hermes update, the gateway restart watcher spawned python.exe instead of
pythonw.exe, leaving a visible console window on the user's desktop.

fix: on Windows, resolve the sibling pythonw.exe (windowless GUI subsystem)
from the python.exe path returned by get_python_path(). This mirrors the
approach used by Hermes_Gateway.cmd (gateway_windows._build_gateway_cmd_script)
which already derives pythonw.exe via _derive_venv_pythonw() for detached
service-managed launches.

Closes the post-update window-left-open issue reported by the Windows user.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #44288 — same fix in the same function (_gateway_run_args_for_profile() in hermes_cli/gateway.py): resolve a windowless pythonw.exe for the post-update Windows gateway respawn so no blank console window is left open. #44288 (by a maintainer, opened earlier) is the more complete version — it also resolves the uv-venv launcher trap via _resolve_detached_python() and overlays VIRTUAL_ENV/PYTHONPATH on the respawn env so imports resolve without the venv shim. Closing in favor of that.

@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Note: This is NOT a duplicate of the prior closed PRs (#44288, #44288). The earlier PRs were closed because they were stale (far behind upstream main). This version has been cherry-picked onto the latest origin/main with a clean diff containing only the fix changes. No conflicts. CI green. Ready for review.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused Windows repro and fix.

Automated hermes-sweeper review found that current main already provides this guarantee through the stronger merged implementation:

  • PR fix(gateway,windows): respawn gateway windowless after GUI update (no persistent console window) #52239 merged as d430684d7cce9f9b445e47fee9abbae796f1168b and shipped in v2026.7.1.
  • hermes_cli/gateway.py:759 rewrites Windows restart argv via windowless_gateway_restart_spec() before the watcher respawns the gateway.
  • hermes_cli/gateway_windows.py:812 resolves the uv-safe base pythonw.exe and supplies the required VIRTUAL_ENV/PYTHONPATH overlay; this avoids the venv-launcher console re-exec that a sibling-only pythonw.exe substitution does not cover.
  • Regression coverage is present in tests/tools/test_windows_native_support.py:1078.

The earlier duplicate discussion correctly identified the same restart path; main now contains the complete version, so this PR is superseded.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants