fix(windows): stop persistent gateway console after update + close checker variable-argv blind spot - #53851
Closed
teknium1 wants to merge 1 commit into
Closed
fix(windows): stop persistent gateway console after update + close checker variable-argv blind spot#53851teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
…ecker variable-argv blind spot Two distinct Windows console bugs that survived #53791/#53810/#53829: 1. Persistent console after update that kills the gateway when closed. _spawn_gateway_restart_watcher rewrote the respawned gateway argv to windowless pythonw, but launched the WATCHER process itself with sys.executable — the venv console python.exe during `hermes update`. uv's venv launcher re-execs the base console interpreter, allocating a conhost that DETACHED_PROCESS/CREATE_NO_WINDOW can't suppress; the respawned gateway inherits it. Resolve the watcher interpreter to pythonw too (no-op on POSIX). 2. The AST footgun checker only resolved a flashing program when argv[0] was a string literal, so the update path's `git_cmd = ["git", ...]` then `subprocess.run(git_cmd + [...], capture_output=True)` calls were invisible and shipped unflagged — one console flash per call. Teach _argv_head to resolve variable and concat (BinOp Add) argv via a module-wide name->program map. Route the 39 newly-visible calls in main.py + 23 across 12 other files through the _subprocess_compat chokepoint (or creationflags=windows_hide_flags()). Also fixes a latent NameError: main.py called _subprocess_compat.run with no module import in scope — the update path would have crashed on Windows. Tests: checker 32/32, watcher/restart/detach 5/5. Update suite failures drop 29->7 (remaining 7 are pre-existing baseline failures).
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
run_agent.py:3014: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
Unchanged: 6070 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptoms (reported by a Windows desktop user)
Three prior PRs (#53791, #53810, #53829) targeted this class but closed neither real symptom. There were two distinct bugs:
Bug 1 — persistent console after update that kills the gateway
hermes_cli/gateway.py::_spawn_gateway_restart_watchercorrectly rewrote the respawned gateway argv to windowlesspythonw.exe(viawindowless_gateway_restart_spec), but launched the watcher process itself withsys.executable— the venv's consolepython.exeduringhermes update. uv's venv launcher re-execs the base console interpreter, allocating a conhost thatDETACHED_PROCESS/CREATE_NO_WINDOWcannot suppress. The respawned gateway becomes a child of that leftover console → persistent window; closing it kills the gateway.Fix: resolve the watcher's own interpreter to windowless
pythonw.exetoo (no-op on POSIX). Verified on a real Windows box:venv→ uv-managed pythonw,.venv→ system pythonw, both resolve and exist.Bug 2 — the flash storm (and a latent NameError)
The AST footgun checker (
scripts/check-windows-footguns.py) only recognized a flashing program whenargv[0]was a string literal. The entire update path buildsgit_cmd = ["git", "-c", …]once and passesgit_cmd + [...](variable/concat) to ~33subprocess.run(..., capture_output=True)calls — invisible to the checker, shipped unflagged, one console flash each.Fixes:
_argv_headto resolve variable and concat (BinOp Add) argv via a module-wide name→program map (_build_var_progs), plus[sys.executable, ...]→python.main.py(the update flow) + 23 across 12 other files the improved checker surfaced through the_subprocess_compatchokepoint (orcreationflags=windows_hide_flags()).NameError:main.pycalled_subprocess_compat.runwith no module import in scope — the update path would have crashed on Windows. Added the import.Verification (real Windows machine)
hermes_cli.mainimports cleanlytests/scripts/test_windows_footgun_subprocess_rule.py: 32/32 pass (incl. repo-clean invariant)main).16 files changed, +200/−87.