Skip to content

The agent that grows with you

fix(gateway): a non-interactive Windows `gateway start` never installs login auto-start

teknium1ff6b9f722d44
diff --git a/hermes_cli/gateway_windows.py b/hermes_cli/gateway_windows.py
index 56eae9a9fd7..9bafd6f4621 100644
--- a/hermes_cli/gateway_windows.py
+++ b/hermes_cli/gateway_windows.py
@@ -785,7 +785,7 @@ def install(
_start_or_report_running()
else:
print("ℹ Gateway not started and no auto-start service installed.")
- print(" Run later with: hermes gateway start")
+ print(" Run in the foreground later with: hermes gateway run")
return
task_name = get_task_name()
@@ -1493,17 +1493,24 @@ def start() -> None:
return
if not is_task_registered() and not is_startup_entry_installed():
- from hermes_cli.setup import prompt_yes_no
+ # Login persistence is a lasting system change: a bare ``start`` installs it only on an explicit
+ # answer — the HERMES_GATEWAY_INSTALL_START_ON_LOGIN override or a real TTY prompt — never on a
+ # non-TTY default (#113977). Declining still starts the gateway; the command is ``start``.
+ start_on_login = _install_choice_from_env("HERMES_GATEWAY_INSTALL_START_ON_LOGIN")
+ if start_on_login is None:
+ from hermes_cli.setup import is_interactive_stdin, is_noninteractive, prompt_yes_no
- print("✗ Gateway service is not installed")
- if not prompt_yes_no(" Install it now so the gateway starts on login?", True):
- print(" Run: hermes gateway install")
- return
- install(force=False)
- if not is_task_registered() and not is_startup_entry_installed():
- print("⚠ Gateway install did not complete in this process.")
- print(" If a UAC prompt opened, approve it, then run: hermes gateway start")
+ print("✗ Gateway service is not installed")
+ if is_noninteractive() or not is_interactive_stdin():
+ start_on_login = False
+ else:
+ start_on_login = prompt_yes_no(" Install it now so the gateway starts on login?", True)
+ if start_on_login:
+ # install() starts the gateway itself (start_now) and reports the outcome — including a UAC
+ # hand-off to an elevated child — so there is nothing left to spawn or to warn about here.
+ install(force=False, start_now=True, start_on_login=True)
return
+ print("ℹ Login auto-start not installed; add it later with: hermes gateway install")
elif is_task_registered():
reconcile_scheduled_task(get_task_name()) # like systemd's regenerate-on-stale before a start
diff --git a/tests/hermes_cli/test_gateway_windows.py b/tests/hermes_cli/test_gateway_windows.py
index b0e1117742d..a997492149c 100644
--- a/tests/hermes_cli/test_gateway_windows.py
+++ b/tests/hermes_cli/test_gateway_windows.py
@@ -481,6 +481,53 @@ def test_reconcile_scheduled_task_reregisters_only_on_drift(monkeypatch, tmp_pat
assert not any(c[0] in ("/Delete", "/Create") for c in calls)
+def _arrange_uninstalled_start(monkeypatch):
+ """start() with no Scheduled Task / Startup entry; returns (install_calls, spawn_count)."""
+ installs, spawns = [], []
+ monkeypatch.delenv("HERMES_GATEWAY_INSTALL_START_ON_LOGIN", raising=False)
+ monkeypatch.delenv("HERMES_NONINTERACTIVE", raising=False)
+ monkeypatch.setattr(gateway_windows, "_assert_windows", lambda: None)
+ monkeypatch.setattr(gateway_windows, "_print_start_attestation_warning", lambda: None)
+ monkeypatch.setattr(gateway_windows, "_gateway_pids", lambda: [])
+ monkeypatch.setattr(gateway_windows, "is_task_registered", lambda: False)
+ monkeypatch.setattr(gateway_windows, "is_startup_entry_installed", lambda: False)
+ monkeypatch.setattr(gateway_windows, "install", lambda **kwargs: installs.append(kwargs))
+ monkeypatch.setattr(gateway_windows, "_spawn_detached", lambda: spawns.append(1) or 4242)
+ monkeypatch.setattr(gateway_windows, "_report_gateway_start", lambda via: None)
+ return installs, spawns
+
+
+def test_start_without_tty_starts_the_gateway_but_never_installs_login_persistence(monkeypatch, capsys):
+ """`hermes gateway start < /dev/null` must not answer the persistence question with a default Yes
+ (#113977); it starts the gateway once and points at the explicit install command."""
+ installs, spawns = _arrange_uninstalled_start(monkeypatch)
+ monkeypatch.setattr(setup, "is_interactive_stdin", lambda: False)
+ monkeypatch.setattr(setup, "prompt_yes_no", lambda *a, **k: pytest.fail("no prompt without a TTY"))
+
+ gateway_windows.start()
+
+ assert installs == [] and spawns == [1]
+ out = capsys.readouterr().out
+ assert "hermes gateway install" in out and "did not complete" not in out
+
+
+def test_start_on_tty_hands_both_answers_to_install_and_honours_the_env_opt_out(monkeypatch):
+ """Yes → one install() carrying start_now+start_on_login (install spawns; start() must not spawn
+ again). HERMES_GATEWAY_INSTALL_START_ON_LOGIN=0 → no question, no install, a plain start."""
+ installs, spawns = _arrange_uninstalled_start(monkeypatch)
+ monkeypatch.setattr(setup, "is_interactive_stdin", lambda: True)
+ monkeypatch.setattr(setup, "prompt_yes_no", lambda *a, **k: True)
+
+ gateway_windows.start()
+ assert installs == [{"force": False, "start_now": True, "start_on_login": True}] and spawns == []
+
+ installs.clear()
+ monkeypatch.setenv("HERMES_GATEWAY_INSTALL_START_ON_LOGIN", "0")
+ monkeypatch.setattr(setup, "prompt_yes_no", lambda *a, **k: pytest.fail("env override must skip the prompt"))
+ gateway_windows.start()
+ assert installs == [] and spawns == [1]
+
+
diff --git a/website/docs/user-guide/windows-native.md b/website/docs/user-guide/windows-native.md
index 42d26afea10..e895e5822ba 100644
--- a/website/docs/user-guide/windows-native.md
+++ b/website/docs/user-guide/windows-native.md
@@ -186,7 +186,7 @@ Flags used when spawning: `DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | CREATE_
```powershell
hermes gateway status # Merged view: schtasks + Startup folder + running PID
-hermes gateway start # Starts the scheduled task now
+hermes gateway start # Starts the gateway in the background (asks about login auto-start only on a TTY when nothing is installed)
hermes gateway stop # Writes the planned-stop marker, waits for the gateway to drain (≤ agent.restart_drain_timeout, capped at 30 s), then force-kills only if it is still alive
hermes gateway restart # Same drain-first stop, then a fresh start
hermes gateway uninstall # Removes schtasks entry, Startup shortcut, pid file
@@ -194,6 +194,8 @@ hermes gateway uninstall # Removes schtasks entry, Startup shortcut, pid file
`hermes gateway status` is idempotent — call it a thousand times in a row and it will never accidentally kill the gateway. (Pre-PR #21561 it silently did, via `os.kill(pid, 0)` colliding with `CTRL_C_EVENT` at the C level — see "process management internals" below if you care about the story.)
+Login auto-start is only ever installed on an explicit answer: `hermes gateway install`, a `Y` on a real terminal, or `HERMES_GATEWAY_INSTALL_START_ON_LOGIN=1`. A scripted or piped `hermes gateway start` (no TTY, or `HERMES_NONINTERACTIVE=1`) starts the gateway without touching the Scheduled Task or the Startup folder; set `HERMES_GATEWAY_INSTALL_START_ON_LOGIN=0` to skip the question on a terminal too.
+
### Why not a Windows Service?
Services require admin rights to install and tie the gateway's lifecycle to machine boot, not user login. The typical Hermes user wants: log in → gateway available, log out → gateway gone. Scheduled Tasks do exactly that without elevation. If you genuinely want a service, use `nssm` or `sc create` manually — but you probably don't.