Skip to content

fix(cli): suppress OSError EINVAL on macOS kqueue stdin registration#20482

Closed
CN-big-cabbage wants to merge 1 commit into
NousResearch:mainfrom
CN-big-cabbage:fix/macos-kqueue-einval-stdin
Closed

fix(cli): suppress OSError EINVAL on macOS kqueue stdin registration#20482
CN-big-cabbage wants to merge 1 commit into
NousResearch:mainfrom
CN-big-cabbage:fix/macos-kqueue-einval-stdin

Conversation

@CN-big-cabbage
Copy link
Copy Markdown

Problem

On macOS with uv-managed Python (cpython-3.11.11-macos-aarch64), Hermes crashes with a full traceback on exit:

Traceback (most recent call last):
  ...
  File "prompt_toolkit/input/vt100.py", line 165, in _attached_input
    loop.add_reader(fd, callback_wrapper)
  ...
OSError: [Errno 22] Invalid argument

Root cause: kqueue cannot register stdin (fd 0) for EVENT_READ and raises OSError with errno.EINVAL (22). The existing handler at cli.py:11937 only suppressed errno.EIO (5), so EINVAL fell through to else: raise.

Fix

Add errno.EINVAL to the suppressed errno set — same silent-pass treatment as EIO — since the root cause is the same uv/kqueue incompatibility already documented in the surrounding comment.

# Before
if isinstance(_stdin_err, OSError) and getattr(_stdin_err, "errno", None) == errno.EIO:

# After
if isinstance(_stdin_err, OSError) and getattr(_stdin_err, "errno", None) in (errno.EIO, errno.EINVAL):

Test plan

  • Run hermes on macOS with uv-managed Python (cpython-3.11.11-macos-aarch64)
  • Verify no traceback printed on normal exit
  • Verify existing behavior unchanged on Linux / Homebrew Python

🤖 Generated with Claude Code

On macOS with uv-managed Python (cpython-3.11.11-aarch64), kqueue
cannot register stdin (fd 0) for EVENT_READ and raises:
  OSError: [Errno 22] Invalid argument (errno.EINVAL)

The existing handler only suppressed errno.EIO (5), so EINVAL (22)
fell through to `else: raise`, printing a full traceback on exit.

Add errno.EINVAL to the suppressed set — same silent-pass treatment
as EIO — since the root cause is the same uv/kqueue incompatibility
already documented in the surrounding comment.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists labels May 6, 2026
@alt-glitch
Copy link
Copy Markdown
Collaborator

Duplicate of #13251 — this is the 7th+ competing PR for the macOS kqueue EINVAL stdin registration crash (#6393). Other existing PRs: #11253, #8796, #11866, #9996, #18363, #19501.

@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 duplicate This issue or pull request already exists 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