Skip to content

fix(gateway): guard faulthandler.enable() against sys.stderr=None on Windows - #72158

Closed
brantleyjill wants to merge 1 commit into
NousResearch:mainfrom
brantleyjill:fix/windows-gateway-faulthandler-stderr
Closed

fix(gateway): guard faulthandler.enable() against sys.stderr=None on Windows#72158
brantleyjill wants to merge 1 commit into
NousResearch:mainfrom
brantleyjill:fix/windows-gateway-faulthandler-stderr

Conversation

@brantleyjill

Copy link
Copy Markdown

Problem

faulthandler.enable() crashes with RuntimeError: sys.stderr is None when the gateway is spawned as a subprocess without a TTY on Windows. This happens because faulthandler defaults to writing to sys.stderr, which is None in that context.

This breaks two scenarios:

  • hermes gateway start — spawns the gateway as a child process, crashes immediately with exit code 1
  • Desktop app backend launch (hermes serve spawned by Electron) — same crash, producing "Could not connect to hermes gateway" in the UI

The crash happens at gateway/run.py:7821.

Fix

Wrap faulthandler.enable() with a if sys.stderr is not None: guard. This preserves the faulthandler behavior on platforms where sys.stderr is available (Linux, macOS, Windows with TTY) while preventing the crash on headless child processes.

Verification

  • Windows 10, gateway spawned as child process: before fix, crashes <1s; after fix, runs indefinitely
  • Desktop app connects and loads successfully after reboot
  • Feishu messaging gateway stable for 30+ minutes and responding to messages
  • hermes gateway start returns success and process stays running
  • No impact on Linux/macOS (sys.stderr is always available there)

…Windows

faulthandler.enable() crashes with RuntimeError('sys.stderr is None')
when the gateway is spawned as a subprocess without a TTY on Windows,
because faulthandler defaults to writing to sys.stderr which is None
in that context.

This breaks 'hermes gateway start' (direct spawn) and desktop-app
backend launch ('hermes serve' spawned by Electron), producing
exit code 1 and 'Could not connect to hermes gateway' in the UI.

Fix: guard with 'if sys.stderr is not None:' before calling
faulthandler.enable().
@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 Native Windows-specific behavior or breakage duplicate This issue or pull request already exists 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 labels Jul 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #71671: both guard the same gateway/run.py faulthandler.enable() call when sys.stderr is None. #71671 is the broader open fix with fallback logging and regression coverage.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the fix — this was a real bug and your guard was correct. It landed via PR #72304, which salvaged #71671 (the same fix submitted ~18h earlier, with a file-fallback so faulthandler stack dumps still work when stderr is missing, plus a regression test). Closing this one as a duplicate; appreciate the report and the diff.

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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage 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.

3 participants