Skip to content

fix(gateway): eliminate blank console window on Windows login - #37037

Closed
Weidows wants to merge 1 commit into
NousResearch:mainfrom
Weidows:fix/gateway-windows-blank-terminal-popup
Closed

fix(gateway): eliminate blank console window on Windows login#37037
Weidows wants to merge 1 commit into
NousResearch:mainfrom
Weidows:fix/gateway-windows-blank-terminal-popup

Conversation

@Weidows

@Weidows Weidows commented Jun 1, 2026

Copy link
Copy Markdown

Problem

When the Hermes gateway starts via Scheduled Task at Windows login, a blank terminal window flashes on screen. This happens because schtasks runs .cmd files through cmd.exe, which is a console-subsystem executable -- Windows must create a Console Window Host (conhost.exe) before it ever reaches pythonw.exe inside the script.

Root cause

cmd.exe is a console-subsystem binary. Windows allocates a new console (conhost.exe) for every console-mode process that doesn't inherit one. The .cmd wrapper launches pythonw.exe (GUI-subsystem, no console) almost immediately, but the console window is already created and visible before the child even starts.

Fix

Replace the cmd.exe -> .cmd -> pythonw.exe chain with wscript.exe -> .vbs -> pythonw.exe for the Scheduled Task /TR action.

wscript.exe is a GUI-subsystem executable built into every Windows install since Windows 98. It never creates a console, so no blank terminal window ever appears.

Changes

  1. _build_vbs_launcher() -- New function that generates CRLF-terminated VBScript content. The VBS script:

    • Creates a WScript.Shell COM object
    • Sets CurrentDirectory to the project root
    • Exports HERMES_HOME, PYTHONIOENCODING, VIRTUAL_ENV, HERMES_GATEWAY_DETACHED via WshShell.Environment("PROCESS")
    • Calls WshShell.Run(cmd, 0, False) where 0 = SW_HIDE (no window) and False = async (non-blocking)
  2. _write_vbs_launcher() -- Writes the .vbs file to <HERMES_HOME>/gateway-service/<task_name>.vbs, alongside the existing .cmd wrapper

  3. _install_scheduled_task() -- Signature changed from (task_name, script_path: Path) to (task_name, tr_command: str) so the caller passes the full already-quoted /TR command string (e.g. wscript.exe //B //Nologo "C:...\Hermes_Gateway.vbs")

  4. install() -- Now writes the .vbs launcher and builds the wscript.exe command for /TR. The .cmd wrapper is still written for manual use and the Startup-folder fallback.

  5. uninstall() -- Also removes the .vbs file during cleanup.

Testing

  • Python syntax verified (AST parse)
  • All functions import correctly
  • VBS launcher uses WshShell.Run with SW_HIDE and async
  • VBS quoting handles paths with spaces via subprocess.list2cmdline + VBS double-quote convention
  • uninstall() cleans up .vbs alongside .cmd

Notes

  • The existing .cmd wrapper is preserved for backward compatibility (manual hermes gateway start, debugging).
  • The Startup-folder fallback path still uses start /min cmd.exe -- that path is less common and users who hit it likely chose it intentionally. A follow-up could apply the same VBS approach there too.

@rodriguez46p-ui

Copy link
Copy Markdown

Hourly commander review note: this looks like the right direction for suppressing the login console flash (wscript.exe + pythonw.exe). One edge case to fix before merge: the scheduled-task /TR currently builds wscript.exe //B //Nologo {vbs_path} and then quotes the whole string. If HERMES_HOME / profile path contains spaces (e.g. C:\Users\Paul Rodriguez\...), wscript.exe will receive the .vbs path split across arguments because the script path itself is not quoted inside the command line.

Suggested shape:

tr_command = _quote_schtasks_arg(
    subprocess.list2cmdline(["wscript.exe", "//B", "//Nologo", str(vbs_path)])
)

I verified in an isolated worktree that hermes_cli/gateway_windows.py imports/py-compiles, and the existing gateway service test file is fully skipped on this non-Windows test substrate (pytest ... test_gateway_service.py exits 5 with 1 skipped).

Replace cmd.exe batch file with VBScript launcher for the Scheduled
Task action so the gateway never creates a Console Window Host
(conhost.exe) at login.

Root cause: schtasks runs .cmd files through cmd.exe, which is a
console-subsystem executable. Creating cmd.exe forces Windows to
allocate a console (conhost.exe blank terminal window) even though
the .cmd wrapper immediately delegates to pythonw.exe.

Fix: add _build_vbs_launcher() and _write_vbs_launcher() that
generate a .vbs file using wscript.exe (GUI-subsystem, built into
every Windows install since Win98). The VBS launcher sets env vars
via WshShell.Environment(PROCESS) and calls pythonw.exe with
SW_HIDE (0) and async (False).

Changes:
- Add _build_vbs_launcher() - generates CRLF-terminated VBS content
- Add _write_vbs_launcher() - writes <HERMES_HOME>/gateway-service/<name>.vbs
- Refactor _install_scheduled_task(task_name, script_path: Path)
  to _install_scheduled_task(task_name, tr_command: str)
- Update install() to write .vbs and use wscript.exe for /TR
- Update uninstall() to clean up .vbs alongside .cmd
@Weidows
Weidows force-pushed the fix/gateway-windows-blank-terminal-popup branch from b6c2ef9 to db23487 Compare June 2, 2026 01:30
@Weidows

Weidows commented Jun 2, 2026

Copy link
Copy Markdown
Author

Good catch on the space-in-path edge case. Fixed in db23487 — now uses subprocess.list2cmdline() to quote each argument individually before the outer _quote_schtasks_arg(), so a path like C:\Users\Paul Rodriguez\Hermes_Gateway.vbs survives both the schtasks parser and wscript.exe argv splitting.

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

Weidows commented Jul 1, 2026

Copy link
Copy Markdown
Author

Confirmed fixed in practice. Closing as the blank terminal window no longer appears on session start.

@Weidows Weidows closed this Jul 1, 2026
@Weidows

Weidows commented Jul 1, 2026

Copy link
Copy Markdown
Author

User confirmed the blank terminal no longer appears. The fix from this PR was incorporated upstream in #40909 (commit fc086da8b by teknium1) which rewrote the entire Windows gateway service layer with CREATE_NO_WINDOW flags and the VBS launcher approach — a superset of this change.

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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants