Fix Windows CLI startup when tunnel imports fail#516
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fa3d62924
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| """Start a tunnel to expose a local port.""" | ||
|
|
||
| async def run_tunnel(): | ||
| from prime_tunnel import Tunnel |
There was a problem hiding this comment.
Defer all tunnel package imports until command execution
Moving Tunnel into run_tunnel() does not actually stop startup-time tunnel imports, because this module still imports prime_tunnel at import time (TunnelClient and tunnel exceptions at the top), and importing prime_tunnel.core.client executes prime_tunnel/__init__.py, which in turn imports prime_tunnel.tunnel (packages/prime-tunnel/src/prime_tunnel/__init__.py:15). That means prime --help can still fail before dispatch whenever tunnel package import fails, so the Windows startup fix remains incomplete for the failure mode this patch is trying to isolate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The initial patch fixed the concrete Windows failure we reproduced (ModuleNotFoundError: No module named 'fcntl'), but it did not fully defer tunnel-module imports at CLI startup.
What the initial patch did:
- guarded the
fcntlimport inprime_tunnel.tunnelso the package no longer crashed on Windows for that specific import-time failure - moved
Tunnelusage insideprime tunnel start - added a Windows startup regression test around the missing-
fcntlpath
What was still incomplete:
prime_cli.commands.tunnelstill importedprime_tunnel.core.client- importing
prime_tunnel.core.clientstill loaded the parent package prime_tunnel.__init__still eagerly importedprime_tunnel.tunnel- so CLI startup was still coupled to importing the tunnel module
What I changed after the codex review:
- removed the eager
from prime_tunnel.tunnel import Tunnelfromprime_tunnel.__init__ - lazy-load
Tunnelviaprime_tunnel.__getattr__instead - added a stronger regression test that fails if
prime_tunnel.tunnelis imported duringprime --help
So the branch now covers both:
- the original Windows
fcntlfailure mode, and - the broader startup-import coupling codex pointed out
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7fa3d62. Configure here.

What changed
Tunneleagerly fromprime_tunnel.__init__.Tunnelonly whenprime tunnel startexecutes, so unrelated commands do not importprime_tunnel.tunnelat CLI startup.fcntlimport inprime_tunnel.tunnelso the module can be imported on non-POSIX platforms.fcntlpath and the requirement thatprime --helpnot importprime_tunnel.tunnel.Why
primecould fail withModuleNotFoundError: No module named 'fcntl'before command dispatch.prime_cli.main, which importedprime_tunnel, which imported Unix-onlyfcntlat module import time.pods,availability, or even--help.Impact
prime tunnel startis invoked, instead of breaking the entire CLI at startup.Validation
uv run pytest packages/prime/tests/test_windows_cli.py packages/prime-tunnel/tests/test_tunnel.py -qNote
Low Risk
Low risk import-time compatibility change; main risk is accidentally breaking
Tunnelexports or tunnel startup due to the new lazy-import path.Overview
Fixes Windows CLI startup by removing eager tunnel imports:
prime_tunnel.Tunnelis now lazy-exported via__getattr__, and theprime tunnel startcommand importsTunnelonly when invoked.Makes
prime_tunnel.tunnelimportable on non-POSIX platforms by guarding thefcntlimport, and adds regression tests ensuringprime --helpworks whenfcntlis unavailable and that CLI help does not importprime_tunnel.tunnel.Reviewed by Cursor Bugbot for commit 958e7d8. Bugbot is set up for automated code reviews on this repo. Configure here.