Skip to content

fix(windows): make gateway install lifecycle idempotent#26488

Closed
nekwo wants to merge 3 commits into
NousResearch:mainfrom
nekwo:fix/windows-gateway-install-lifecycle-only
Closed

fix(windows): make gateway install lifecycle idempotent#26488
nekwo wants to merge 3 commits into
NousResearch:mainfrom
nekwo:fix/windows-gateway-install-lifecycle-only

Conversation

@nekwo

@nekwo nekwo commented May 15, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes Windows gateway install/start behavior so repeated hermes gateway install, hermes gateway start, and setup flows are idempotent and do not create duplicate gateway processes or leave visible console windows behind. Interactive window y/n on starting profile gateway after profile gateway installation, incorporating UAC priveledge escalation if need be

This PR addresses several Windows-native gateway lifecycle issues:

  • Re-running gateway install should reconcile the Scheduled Task instead of preserving stale restart/repeat settings.
  • Setup should respect the user's start now and start on login choices.
  • Starting an already-running gateway should no-op instead of launching another poller.
  • Scheduled Task / Startup fallback behavior should be explicit and safe.
  • UAC/elevation should only be used after normal per-user Scheduled Task creation fails with access denied.
  • Detached Windows gateway starts should use pythonw.exe / hidden subprocess flags to avoid flashing or stuck console windows.

The implementation keeps the normal Scheduled Task path as the preferred Windows login-start mechanism, uses schtasks /Create /F to replace stale task definitions without deleting the old task first, and falls back to the Startup folder only when Scheduled Task creation is unavailable or declined.

It also adds regression tests for the Windows gateway lifecycle behavior, including no duplicate start, UAC handoff, Startup fallback, direct detached spawn, and generated wrapper behavior.

Related Issue

#26487

Fixes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Security fix
  • Documentation update
  • Tests (adding or improving test coverage)
  • Refactor (no behavior change)
  • New skill (bundled or hub)

Changes Made

  • hermes_cli/gateway_windows.py

    • Makes Windows gateway install/start behavior idempotent.
    • Uses schtasks /Create /F to reconcile the Scheduled Task definition.
    • Tries normal per-user Scheduled Task creation before UAC/fallback.
    • Prompts for UAC only when Scheduled Task creation/removal is blocked by access denied.
    • Uses Startup-folder fallback only when appropriate.
    • Avoids spawning duplicate gateways when a gateway process is already running.
    • Uses pythonw.exe and hidden process flags for detached gateway starts.
  • hermes_cli/gateway.py

    • Passes setup choices through to Windows install.
    • Avoids double-starting Windows gateway from setup.
    • Honors start/startup choices in Linux systemd install path.
    • Avoids installing macOS launchd when login auto-start is declined.
  • hermes_cli/main.py

    • Adds hidden internal flags used for elevated Windows install handoff:
      • --start-now
      • --no-start-now
      • --start-on-login
      • --no-start-on-login
      • --elevated-handoff
  • tools/environments/local.py

    • Applies Windows no-window subprocess creation flags for local terminal commands.
  • tools/process_registry.py

    • Applies Windows no-window subprocess creation flags for background terminal processes.
  • tests/hermes_cli/test_gateway_windows.py

    • Adds Windows gateway lifecycle regression coverage.
  • tests/hermes_cli/test_gateway.py

    • Updates setup/systemd tests for the explicit start/startup lifecycle choices.

How to Test

Targeted tests:

pytest tests/hermes_cli/test_gateway_windows.py tests/hermes_cli/test_gateway.py -q

Expected result:

45 passed

Additional checks:

git diff --check upstream/main..HEAD
# passed

security scan
# findings=0

Manual Windows behavior to verify:

  1. Run hermes gateway install.
  2. Confirm it asks whether to start now and whether to start on login.
  3. Confirm declining login auto-start does not create a Scheduled Task.
  4. Confirm re-running install does not create duplicate gateway processes.
  5. Confirm hermes gateway start no-ops when the gateway is
  6. Confirm no visible cmd.exe, powershell.exe, or hermes.exe windows flash/stick during gateway start or background subprocesses.

Checklist

Code

Documentation & Housekeeping

  • I've updated relevant documentation — N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact: Windows, Linux systemd, macOS launchd
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard backend/local Local shell execution labels May 15, 2026
@nekwo nekwo force-pushed the fix/windows-gateway-install-lifecycle-only branch from 8850525 to c88d716 Compare May 16, 2026 17:09
nekwo added 2 commits May 16, 2026 13:22
Preserve Windows profile install decisions across UAC handoff, avoid visible console windows by launching via pythonw, make repeated install/start idempotent, recreate stale Scheduled Tasks, and separate start-now from login auto-start behavior. Add Windows gateway regression coverage and systemd setup tests for the shared install flow.
Apply Windows CREATE_NO_WINDOW flags to foreground local terminal subprocesses and tracked background processes so Hermes operations do not flash or steal focus with extra console windows.
@nekwo nekwo force-pushed the fix/windows-gateway-install-lifecycle-only branch from c88d716 to 0f8ce0b Compare May 16, 2026 17:23
@nekwo

nekwo commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

had a very dirty tree just updated the rest of the code

  1. 9abd92e6b fix(gateway): harden Windows gateway install lifecycle

    Included missing code/tests around:

    • Windows gateway install lifecycle
    • pythonw.exe gateway launch to avoid visible console windows
    • no --replace for service-managed starts
    • idempotent repeated install/start
    • Scheduled Task recreate instead of stale /Change
    • UAC handoff flags
    • start-now vs start-on-login separation
    • Startup-folder fallback behavior
    • Windows gateway regression tests
    1. c88d7161c fix(windows): hide local subprocess consoles

    Included missing code around:

    • hiding local terminal subprocess consoles on Windows
    • hiding tracked background process consoles on Windows
    • using windows_hide_flags() in:
      • tools/environments/local.py
      • tools/process_registry.py

Apply CREATE_NO_WINDOW flags when the cron scheduler launches job scripts on Windows so gateway-managed no-agent cron jobs do not flash cmd or python console windows every tick.
@nekwo

nekwo commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

It's mostly so far the cron jobs, i just patched it more, those shell windows flash like maniacs randomly

(seizure inducing) I think i caught them all but maybe your ai can do a deep audit @alt-glitch

@nekwo

nekwo commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

i can fix it too if you'd like in another pull request i found it's across a bunch of modules but i don't want to stomp over everything and everyone

@teknium1

Copy link
Copy Markdown
Contributor

Salvaged onto current main via PR #28874 (your 3 commits cherry-picked with your authorship preserved in git log; one tiny cross-platform test fixup added on top). Original branch was 23 commits behind main with conflicts in cron/scheduler.py + tools/process_registry.py + the test file, so rebasing in-place would have been messy — thanks for the work, the Windows lifecycle fix has shipped. Closes #26487.

@teknium1 teknium1 closed this May 19, 2026
@nekwo nekwo deleted the fix/windows-gateway-install-lifecycle-only branch May 28, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants