Skip to content

fix(cli): skip lazy-dep prompt when prompt_toolkit owns terminal (#40490)#40579

Closed
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-40490
Closed

fix(cli): skip lazy-dep prompt when prompt_toolkit owns terminal (#40490)#40579
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-40490

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Fixes #40490. When prompt_toolkit owns the terminal (e.g. the TUI/CLI mode), a bare input() in the lazy-dep install prompt deadlocks because keystrokes route to prompt_toolkit's event loop instead of stdin. This detects whether a prompt_toolkit app is running and skips the interactive confirmation when it is. Since lazy installs are gated by security.allow_lazy_installs, reaching this code path already means the user has opted in.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 6, 2026
@mohamedorigami-jpg

Copy link
Copy Markdown
Contributor

The get_app_or_none import is guarded by "prompt_toolkit.application.current" in sys.modules, which avoids importing prompt_toolkit if it hasn't been loaded yet. However, if the module IS in sys.modules but the import fails (e.g., a partially installed prompt_toolkit, or a version where get_app_or_none doesn't exist), the except Exception clause silently swallows it and _pt_active defaults to False. From there, the code falls through to the TTY check and the input() call -- which is the deadlock scenario this PR aims to prevent, just via a different failure mode. Consider adding a logger.debug or logger.warning inside the except clause so partial-install deadlocks don't go unnoticed. Also, _pt_active correctly checks getattr(_app, "is_running", False) rather than just truthiness of the app object -- nice defensive pattern.

@teknium1

teknium1 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #40901. Your prompt_toolkit-detection commit was cherry-picked onto current main with your authorship preserved in git log (commit d47f919). Your branch was stale against main, so we salvaged the single substantive commit rather than merging the branch directly.

On top of your fix we added two follow-ups: forcing prompt=False on the only two tool paths that still defaulted to prompt=True (vision + faster-whisper STT), which makes the deadlock-capable input() branch unreachable from any tool call; and promoting Pillow to a core dependency so the vision lazy-install path rarely fires at all. Thanks for the clean, well-documented fix.

@mohamedorigami-jpg

Copy link
Copy Markdown
Contributor

Thanks for cherry-picking that onto main. Appreciate you handling the stale-branch issue.

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 P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CLI input locks up unrecoverably on lazy-dep install prompt (lazy_deps.py uses bare input() under prompt_toolkit)

4 participants