Skip to content

fix(gateway): handle OSError/SystemError from os.kill on Windows#7552

Closed
Arcadia-1 wants to merge 3 commits into
NousResearch:mainfrom
Arcadia-1:fix/windows-os-kill-error
Closed

fix(gateway): handle OSError/SystemError from os.kill on Windows#7552
Arcadia-1 wants to merge 3 commits into
NousResearch:mainfrom
Arcadia-1:fix/windows-os-kill-error

Conversation

@Arcadia-1

@Arcadia-1 Arcadia-1 commented Apr 11, 2026

Copy link
Copy Markdown

Summary

Three Windows compatibility bugs that break core functionality:

  1. os.kill(pid, 0) crashes on Windows — raises OSError (WinError 87) or SystemError instead of ProcessLookupError for stale PIDs. Gateway cannot restart after non-clean shutdown.

  2. memory_tool.py fails to load on Windows — unconditional import fcntl at module level. Persistent memory (MEMORY.md / USER.md) is completely unavailable for all Windows users.

  3. vision_analyze fails on Windows with Git Bash paths — paths like /h/Hermes/file.png from terminal tool output are not valid Windows paths. Path.is_file() returns False, causing "Invalid image source" errors and agent loops.

Changes

os.kill exception handling (5 files, 6 call sites)

Added OSError and SystemError to except clauses:

File Function
gateway/status.py get_running_pid(), acquire_scoped_lock()
gateway/run.py start_gateway() — wait for old process exit
hermes_cli/gateway.py stop_profile_gateway() — wait for process exit
hermes_cli/profiles.py _check_gateway_running(), _stop_gateway_process()
tools/process_registry.py _is_pid_alive()

memory_tool fcntl → cross-platform (1 file)

  • Removed top-level import fcntl
  • _file_lock() now uses msvcrt.locking on Windows, fcntl.flock on Unix

vision_tools Git Bash path conversion (1 file)

  • Convert /x/... paths to X:\... on Windows before Path.is_file() check
  • Uses regex match for /drive-letter/rest pattern

Test plan

  • Windows 11 + Python 3.11: gateway restarts cleanly after non-clean shutdown
  • Windows 11: import tools.memory_tool succeeds
  • Windows 11: Git Bash path /h/Hermes/hermes-agent/AGENTS.md correctly resolves to H:\Hermes\hermes-agent\AGENTS.md
  • Verified hermes gateway connects to Feishu + Weixin with all tools available
  • Linux/macOS: no behavior change — path conversion only triggers on os.name == "nt"

🤖 Generated with Claude Code

Arcadia-1 and others added 3 commits April 11, 2026 13:15
On Windows, `os.kill(pid, 0)` for stale/exited PIDs raises `OSError`
(WinError 87: "The parameter is incorrect") or `SystemError` instead
of the Unix-standard `ProcessLookupError`. This causes gateway restart
failures after non-clean shutdowns, as stale PID/lock files cannot be
cleared.

Add `OSError` and `SystemError` to except clauses in all 6 call sites
across gateway/status.py, gateway/run.py, hermes_cli/gateway.py,
hermes_cli/profiles.py, and tools/process_registry.py.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…msvcrt

memory_tool.py imports fcntl unconditionally at module level, which
fails on Windows (no fcntl module). This prevents the entire memory
tool from loading, disabling persistent memory for all Windows users.

Replace the top-level fcntl import with a platform check: use
msvcrt.locking on Windows and fcntl.flock on Unix. The import is
deferred to the _file_lock context manager so neither module is
required at import time on the other platform.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On Windows with Git Bash terminals, file paths passed to vision_analyze
use Unix-style mount points (e.g. /h/Hermes/...) which Path.is_file()
cannot resolve. This causes "Invalid image source" errors and makes the
agent loop endlessly trying alternative approaches.

Convert /x/... paths to X:\... on Windows before the is_file() check.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery tool/memory Memory tool and memory providers tool/vision Vision analysis and image generation labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Addresses #5760 (os.kill Windows crash) and #8978 (gateway startup WinError 87). Competes with #5762 and #13198 for the os.kill fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists tool/memory Memory tool and memory providers tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants