fix(cli): also suppress OSError EINVAL from kqueue stdin register (#6393)#13251
Closed
tumbleweedlabs wants to merge 1 commit into
Closed
fix(cli): also suppress OSError EINVAL from kqueue stdin register (#6393)#13251tumbleweedlabs wants to merge 1 commit into
tumbleweedlabs wants to merge 1 commit into
Conversation
…usResearch#6393) The existing NousResearch#6393 guard only caught the `KeyError: "0 is not registered"` and `OSError: Bad file descriptor` flavors of the prompt_toolkit startup crash. When launched from a terminal whose PTY is a char device that macOS kqueue refuses to register for EVFILT_READ (observed with some non-Apple terminal emulators on macOS 26), prompt_toolkit's `add_reader(0, ...)` raises `OSError: [Errno 22] Invalid argument` and the except block's string match ("is not registered" / "Bad file descriptor") did not hit — so the user still saw a raw traceback. Detect unusable stdin by errno (EBADF / EINVAL) in addition to the substring checks, both in the asyncio loop exception handler and in the outer `except (KeyError, OSError)` around `app.run()`. Broaden the user-facing message to mention terminal-emulator compatibility and suggest Terminal.app / iTerm2 as a workaround. Reproduced original crash, verified new guard produces the friendly message instead of a traceback on macOS 26.4.1 / cPython 3.11.15.
Collaborator
This was referenced Apr 24, 2026
This was referenced May 1, 2026
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the EINVAL variant of the prompt_toolkit stdin-register crash filed as #6393. The existing guard already caught
KeyError: "0 is not registered"andOSError: Bad file descriptor, but it was a substring match — soOSError: [Errno 22] Invalid argumentslipped through and the user still got a raw traceback.What changed
cli.py, inHermesCLI.run():_suppress_closed_loop_errors) — now also suppressesOSErrorwhoseerrnoisEBADForEINVAL.except (KeyError, OSError)aroundapp.run()— detects unusable stdin by errno (EBADF/EINVAL) in addition to the existing substring checks.Why
Reported by a user hitting the exact traceback in #6393 on macOS 26.4.1:
Verified against that user's environment:
os.fstat(0)succeeds (so the existingfstat()guard passes)os.isatty(0)returns Truecontrol([kev], 0, 0)withEVFILT_READon fd 0 returnsEINVAL— the fd is a char device but not one kqueue will watch for read.The error string is
"[Errno 22] Invalid argument", which doesn't contain"is not registered"or"Bad file descriptor", so the existing handler re-raised.Why errno instead of broader string match
errnocomparisons are robust across Python versions and localizedstrerroroutput. I kept the existing string checks as a belt-and-suspenders for cases where errno is missing (e.g. the KeyError path, or a re-wrapped exception).How to test
Can't easily script the EINVAL case since it depends on the terminal emulator's PTY behavior, but the code path is easy to verify by injecting a synthetic exception:
With this change, that now prints the friendly diagnostic instead of re-raising.
Also verified
python3 -m py_compile cli.pypasses, and that hermes still launches cleanly in a working Terminal.app window.Tested on
Related
🤖 Generated with Claude Code