Skip to content

Fix Windows compatibility: /dev/tty fallback and process tree termination - #54933

Closed
PowerSynth-max wants to merge 1 commit into
NousResearch:mainfrom
PowerSynth-max:fix/windows-compat-tty-process-tree
Closed

Fix Windows compatibility: /dev/tty fallback and process tree termination#54933
PowerSynth-max wants to merge 1 commit into
NousResearch:mainfrom
PowerSynth-max:fix/windows-compat-tty-process-tree

Conversation

@PowerSynth-max

Copy link
Copy Markdown

What does this PR do?
Fix two Windows-specific compatibility issues that affect Hermes stability and resource management on Windows platforms.

Related Issue
No existing issue found. This PR addresses real-world Windows compatibility problems discovered during local development and testing.

Type of Change
[x] 🐛 Bug fix (non-breaking change that fixes an issue)
Changes Made
cli.py (line ~1144): Added platform check in _reset_terminal_input_modes() to use CON device on Windows instead of /dev/tty
tools/environments/local.py (line ~660): Changed Windows branch in _kill_process() to use taskkill /T /F /PID for terminating the entire process tree, with fallback to proc.terminate()
How to Test
Test 1 (cli.py): Redirect stdout and verify no FileNotFoundError on Windows when exiting TUI
Test 2 (local.py): Create a process with child processes, call _kill_process(), verify all child processes are terminated (no orphan processes remain)
Test 3: Run existing test suite on Windows to ensure no regressions
Checklist
Code
[x] I've read the Contributing Guide
[x] My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
[x] I searched for existing PRs to make sure this isn't a duplicate
[x] My PR contains only changes related to this fix/feature (no unrelated commits)
[ ] I've run pytest tests/ -q and all tests pass (Note: Full test suite not run due to environment limitations)
[ ] I've added tests for my changes (Note: Manual testing performed, automated tests not added)
[x] I've tested on my platform: Windows 11
Documentation & Housekeeping
[x] I've updated relevant documentation — or N/A
[x] I've updated cli-config.yaml.example if I added/changed config keys — or N/A
[x] I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
[x] I've considered cross-platform impact (Windows, macOS) per the compatibility guide
[x] I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Note: Some code was AI-assisted, reviewed and tested by human.

问题描述:
在 Windows 平台上发现两个兼容性问题,影响 Hermes 的稳定性和资源管理。

修复内容:

1. cli.py: 修复 Windows 上 /dev/tty 不存在的问题
   - 问题:_reset_terminal_input_modes() 函数在 stdout 被重定向时会尝试打开
     /dev/tty 来重置终端输入模式,但 Windows 上没有 /dev/tty 设备,导致
     FileNotFoundError
   - 修复:在 Windows 上使用 CON 设备(Windows 控制台设备)替代 /dev/tty
   - 影响:修复 TUI 退出时的终端状态重置,避免终端状态异常

2. tools/environments/local.py: 修复 Windows 上进程终止不彻底的问题
   - 问题:_kill_process() 在 Windows 分支中只调用 proc.terminate(),这只会
     终止父进程,子进程会变成孤儿进程继续运行,导致资源泄漏
   - 修复:使用 taskkill /T /F /PID 命令终止整个进程树(包括所有子进程),
     与 POSIX 分支的 os.killpg() 行为对齐
   - 影响:确保终止进程时不会留下孤儿进程,避免资源泄漏

测试验证:
- 测试1:确认 /dev/tty 在 Windows 上报 FileNotFoundError,使用 CON 后正常
- 测试2:确认 proc.terminate() 会留下孤儿进程,taskkill /T 能终止整个进程树

技术细节:
- cli.py 第 1144 行:添加平台判断,Windows 使用 "CON",其他平台使用 "/dev/tty"
- local.py 第 660-661 行:Windows 分支改用 subprocess.run 调用 taskkill /T,
  失败时 fallback 到 proc.terminate(),并等待进程退出

相关文件:
- cli.py
- tools/environments/local.py

注:部分代码由 AI 辅助生成,经人工审核和测试验证。
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard tool/terminal Terminal execution and process management backend/local Local shell execution platform/windows Native Windows-specific behavior or breakage P2 Medium — degraded but workaround exists sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows duplicate This issue or pull request already exists labels Jun 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #49460 (and competing with #54235): the tools/environments/local.py change here swaps the _IS_WINDOWS branch of _kill_process from proc.terminate() to taskkill /T /F /PID for whole-tree termination, which is byte-for-byte the same code site and mechanism as the earlier open #49460 (canonical) and #54235.

Note: this PR ALSO bundles a distinct, independently-useful fix in cli.py (_reset_terminal_input_modes_on_exit() opens CON instead of /dev/tty on Windows to avoid a FileNotFoundError on TUI exit) that the cluster PRs do not cover. A maintainer may want to salvage that cli.py hunk separately.

@PowerSynth-max

PowerSynth-max commented Jun 29, 2026 via email

Copy link
Copy Markdown
Author

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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants