Skip to content

fix(tools): guard Unix-only imports in terminal package for Windows#2096

Open
WolffM wants to merge 2 commits intoOpenHands:mainfrom
WolffM:fix/windows-fcntl-import-crash
Open

fix(tools): guard Unix-only imports in terminal package for Windows#2096
WolffM wants to merge 2 commits intoOpenHands:mainfrom
WolffM:fix/windows-fcntl-import-crash

Conversation

@WolffM
Copy link

@WolffM WolffM commented Feb 16, 2026

Summary

Fixes OpenHands/OpenHands#12781

  • Guard SubprocessTerminal and TmuxTerminal imports in terminal/terminal/__init__.py behind platform.system() != "Windows" so the package loads cleanly on Windows
  • Add an explicit raise ImportError guard in subprocess_terminal.py before the Unix-only fcntl/pty/select imports, replacing the opaque ModuleNotFoundError

Fixes the crash where import openhands.tools.terminal immediately fails on Windows with ModuleNotFoundError: No module named 'fcntl' before factory.py can raise its NotImplementedError("Windows is not supported yet").

Context

The import chain was:

openhands.tools.terminal → terminal/__init__.py → subprocess_terminal.py → import fcntl → crash

factory.py already had platform awareness (raises NotImplementedError on Windows), but it never got a chance to run because __init__.py eagerly imported the Unix-only backends at module level.

@WolffM WolffM force-pushed the fix/windows-fcntl-import-crash branch 2 times, most recently from 5846231 to 67d176c Compare February 16, 2026 19:23
…#12781)

The terminal package eagerly imported SubprocessTerminal and TmuxTerminal
in __init__.py, which triggered `import fcntl` on Windows and crashed
before factory.py could raise NotImplementedError.

Guard the imports behind platform.system() checks so the package loads
cleanly on Windows.

Co-Authored-By: Rb <rubenwolff@gmail.com>
@WolffM WolffM force-pushed the fix/windows-fcntl-import-crash branch from 67d176c to 6f2b723 Compare February 16, 2026 19:25
@WolffM
Copy link
Author

WolffM commented Feb 16, 2026

tested it against my fork of openhands
image

Copy link
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

Please let me note that we have another here:

and in that line there's a bit of an alternative way to do this, separating Windows a bit better within the codebase.

The fix in your PR is normal but unfortunately, there is more to Windows support than not crashing on imports. That actually poses a problem for us, on how to support Windows, and I admit I heavily prefer a more modular approach if we can.

@enyst enyst requested a review from neubig February 16, 2026 19:44
@WolffM
Copy link
Author

WolffM commented Feb 16, 2026

Thank you for the PR!

Please let me note that we have another here:

* [Windows terminal](https://github.com/OpenHands/software-agent-sdk/pull/1012/changes#diff-b1eac84c61a55b8e78ac0bf8eb58368d0fb9e1a370d13b9b1973aff5e0551fe4R15)

and in that line there's a bit of an alternative way to do this, separating Windows a bit better within the codebase.

The fix in your PR is normal but unfortunately, there is more to Windows support than not crashing on imports. That actually poses a problem for us, on how to support Windows, and I admit I heavily prefer a more modular approach if we can.

Thanks for the quick reply!

I was thinking this PR could serve as a short-term fix until the Windows terminal backend (#1012) is ready. I don't think it conflicts with that work. Right now openhands serve crashes immediately on Windows with an opaque fcntl import error, this fix lets the package actually load so the existing error handling in factory.py can kick in properly. Not sure how many people are hitting this right now, but it would unblock them.

Copy link
Contributor

@neubig neubig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I'm going to prioritize getting #1012 in ASAP (maybe test tomorrow), but I can revisit after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ModuleNotFoundError: No module named 'fcntl'

3 participants

Comments