Skip to content

fix(cli): rebind interactive stdin to controlling tty#15720

Closed
huangsen365 wants to merge 1 commit into
NousResearch:mainfrom
huangsen365:fix/macos-interactive-stdin
Closed

fix(cli): rebind interactive stdin to controlling tty#15720
huangsen365 wants to merge 1 commit into
NousResearch:mainfrom
huangsen365:fix/macos-interactive-stdin

Conversation

@huangsen365
Copy link
Copy Markdown

Summary

  • Detect when interactive CLI stdin is not usable by prompt_toolkit (non-TTY or selector registration failure)
  • Rebind fd 0 to /dev/tty for interactive mode so macOS/kqueue does not crash with OSError: [Errno 22] Invalid argument
  • Add regression tests for non-TTY stdin, selector EINVAL, and /dev/tty rebinding

Root cause

When Hermes is launched from a piped installer/wrapper, fd 0 can remain connected to the pipe instead of the controlling terminal. The previous guard only checked os.fstat(0), so prompt_toolkit still attempted loop.add_reader(0, ...) and macOS kqueue could raise OSError(EINVAL). Linux tolerates this path more often, which is why the crash appeared macOS-specific.

Test Plan

  • scripts/run_tests.sh tests/cli/test_interactive_stdin.py -q
  • scripts/run_tests.sh tests/cli/ -q

@teknium1
Copy link
Copy Markdown
Contributor

Closing — superseded by #26077 (merged as commit d3d5916), which preventively probes kqueue at startup and falls back to SelectSelector when fd 0 cannot be registered. The widened except-clause matching EINVAL / EBADF / 'Invalid argument' — which most PRs in this cluster including yours added — is also included.

Thanks for the fix; closing as duplicate of the merged work.

@teknium1 teknium1 closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants