Skip to content

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

Merged
neubig merged 3 commits intoOpenHands:mainfrom
WolffM:fix/windows-fcntl-import-crash
Mar 2, 2026
Merged

fix(tools): guard Unix-only imports in terminal package for Windows#2096
neubig merged 3 commits intoOpenHands:mainfrom
WolffM:fix/windows-fcntl-import-crash

Conversation

@WolffM
Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor Author

WolffM commented Feb 16, 2026

tested it against my fork of openhands
image

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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.

@all-hands-bot
Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @WolffM, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

Copy link
Copy Markdown
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.

On second thought, let's get this in, thanks for the contribution!

@neubig neubig enabled auto-merge (squash) March 2, 2026 15:06
Copy link
Copy Markdown
Contributor

neubig commented Mar 2, 2026

This also fixes Linear ticket ALL-5247.

Fixes ALL-5247

@neubig neubig merged commit caf1b0b into OpenHands:main Mar 2, 2026
19 of 21 checks passed
zparnold added a commit to zparnold/software-agent-sdk that referenced this pull request Mar 5, 2026
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'

4 participants