Skip to content

fix(gateway): import Windows gateway from PM's committed venv, not the pre-PM tree - #123841

Closed
Bifras wants to merge 1 commit into
NousResearch:mainfrom
Bifras:fix/windows-gateway-committed-pm-venv
Closed

Bifras wants to merge 1 commit into
NousResearch:mainfrom
Bifras:fix/windows-gateway-committed-pm-venv

Conversation

@Bifras

@Bifras Bifras commented Sep 26, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes the Windows gateway bootstrap so it loads Python dependencies from PM's committed environment instead of the hardcoded pre-PM in-tree venv/.

gateway/run.py::_ensure_windows_gateway_venv_imports() always appended project_root / "venv" to its candidate list before asking PM. On a migrated (PM-managed) install that in-tree tree is the pre-migration venv — built by whichever interpreter created it — so it was prepended ahead of the committed generation and its compiled modules shadowed the correct ones.

Related Issue

Behavioural regression on PM-migrated Windows installs (no issue filed; described below).

Observed before the fix

  • ModuleNotFoundError: No module named 'pydantic_core._pydantic_core' importing from the pre-PM tree, surfacing as:
    gateway.run: Supervised task hosted_room_worker died 5 times in rapid succession (each within 300s of restart) - giving up restarts
  • pywin32 was also loaded from the stale tree and failed: ImportError: DLL load failed while importing _win32sysloader.
  • The gateway's PYTHONPATH/VIRTUAL_ENV pointed at <repo>/venv (a 3.11 tree) even though the process runs the 3.14 store Python with a committed 3.14 generation available.

Root cause: the helper returns after the first candidate whose Lib/site-packages exists, and that candidate was the hardcoded <repo>/venv.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py: _ensure_windows_gateway_venv_imports() now resolves the committed generation via pm.environments.committed_venv(project_root) and uses it as the candidate. It falls back to the in-tree venv/ only when PM has no committed generation (legacy installs), preserving existing behaviour for pre-PM trees. Failure to import PM degrades to the old path.
  • tests/gateway/test_windows_gateway_venv_imports.py: @pytest.mark.platforms("windows") regression test asserting the committed venv becomes VIRTUAL_ENV, reaches sys.path, has addsitedir semantics applied (a .pth entry is processed — pywin32 needs this), and is advertised in PYTHONPATH.

The test is red on the previous code (it selects <repo>/venv) and green with the fix.

How to Test

  1. On Windows, from a PM-migrated install: scripts/run_tests.sh tests/gateway/test_windows_gateway_venv_imports.py.
    • With the fix: passes.
    • On the previous code: fails, because VIRTUAL_ENV ends up as <repo>/venv instead of the injected committed generation.
  2. Manual: restart the gateway and confirm PYTHONPATH / VIRTUAL_ENV point at the PM generation, and that gateway.log no longer shows hosted_room_worker dying with a pydantic_core._pydantic_core ModuleNotFoundError. pywintypes then resolves to the PM environment's pywin32_system32\pywintypes314.dll.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run the tests per the repo rule (scripts/run_tests.sh, not bare pytest) for the affected file, plus ruff check and python scripts/check-windows-footguns.py --all
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Windows 11 (Python 3.14.7, PM-managed generation)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) - or N/A (code comment added explaining the PM preference)
  • I've updated cli-config.yaml.example if I added/changed config keys - or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows - or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide - the change is inside a sys.platform == "win32" early-return helper, so non-Windows behaviour is untouched
  • I've updated tool descriptions/schemas if I changed tool behavior - or N/A

Screenshots / Logs

Live verification on the affected Windows host (PID values redacted):

  • New gateway after the fix: PYTHONPATH = <repo> ; <pm>\Lib\site-packages ; <repo> ; <pm>\Lib\site-packages (PM env only — the pre-PM tree is gone), VIRTUAL_ENV = <pm>.
  • import pywintypes → <pm>\Lib\site-packages\pywin32_system32\pywintypes314.dll
  • import pydantic_core._pydantic_core → <pm>\Lib\site-packages\pydantic_core\_pydantic_core.cp314-win_amd64.pyd
  • gateway.log: last ERROR predates the fix; zero ERROR lines after the restart.
  • GET /health → 200 {"status":"ok","platform":"hermes-agent","version":"0.21.5"}

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/windows area/install-update Installer, updater, packaging, wheels, doctor sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Sep 26, 2026
@Bifras

Bifras commented Sep 26, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate: same fix as #122768, #123149, #123550 and #122805 for issue #122183. Leaving it to the existing PRs to avoid adding noise. (Unique evidence kept: cp311 pywin32 in the pre-PM in-tree venv fails to load under the 3.14 store Python -> ImportError: DLL load failed while importing _win32sysloader.)

@Bifras Bifras closed this Sep 26, 2026
@alt-glitch alt-glitch added os/windows Native Windows behaviour or breakage: PowerShell install, Windows paths, cmd.exe, WSL-vs-native diff and removed platform/windows labels Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/install-update Installer, updater, packaging, wheels, doctor comp/gateway Gateway runner, session dispatch, delivery os/windows Native Windows behaviour or breakage: PowerShell install, Windows paths, cmd.exe, WSL-vs-native diff P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages 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.

2 participants