Skip to content

fix(cli): suppress RuntimeWarning from unawaited run_in_terminal in prompt_toolkit 3.0.52+#23317

Closed
Ninso112 wants to merge 2 commits into
NousResearch:mainfrom
Ninso112:fix/cli-run-in-terminal-warning
Closed

fix(cli): suppress RuntimeWarning from unawaited run_in_terminal in prompt_toolkit 3.0.52+#23317
Ninso112 wants to merge 2 commits into
NousResearch:mainfrom
Ninso112:fix/cli-run-in-terminal-warning

Conversation

@Ninso112

Copy link
Copy Markdown
Contributor

Summary

  • Fixes RuntimeWarning: coroutine 'run_in_terminal.<locals>.run' was never awaited that appears when confirming /clear, /new, /reset, or /undo in the interactive CLI
  • prompt_toolkit 3.0.52+ changed run_in_terminal() to return an Awaitable. Four call sites in cli.py invoke it fire-and-forget because the callback is scheduled on the already-running event loop and executes correctly
  • Suppresses the warning at each call site with warnings.catch_warnings() since the callback semantics are unchanged

Affected call sites

Function Trigger
_prompt_text_input /clear, /new confirmation prompts
_run_curses_picker curses-based pickers
handle_ctrl_z (key binding) Ctrl+Z suspend
_cprint._schedule background thread print

Fixes #23297.

Ninso112 added 2 commits May 10, 2026 18:43
… platforms

Gateway auto-title generation is fire-and-forget housekeeping. When it
fails (e.g. auxiliary provider HTTP 401/402), the error was surfaced as
a user-visible chat message via _emit_auxiliary_failure. Failures are
already logged at WARNING level in generate_title() and visible in
gateway.log, so operators can still diagnose issues.

Fixes NousResearch#23246.
…rompt_toolkit 3.0.52+

prompt_toolkit 3.0.52+ changed run_in_terminal() to return an
Awaitable. Four call sites in cli.py invoke it fire-and-forget because
the callback is scheduled on the already-running event loop and executes
correctly. Without awaiting, Python 3.10+ emits a RuntimeWarning that
gets caught by the process_loop error handler and logged as noise.

Suppress the warning at each call site with warnings.catch_warnings()
since the callback semantics are unchanged — the function still runs
on the event loop thread.

Fixes NousResearch#23297.

@liuhao1024 liuhao1024 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The warnings.catch_warnings approach suppresses the RuntimeWarning but does not actually run the callback — the coroutine returned by run_in_terminal is still never awaited, so _pt_print(_PT_ANSI(text)) never executes.

filterwarnings("ignore", ...) only hides the diagnostic; it doesn't schedule the coroutine on the event loop. When the coroutine is garbage-collected (likely outside the catch_warnings block), the warning may also reappear.

There is already a correct fix for the same root cause in PR #23302 (by @Bartok9) which uses asyncio.ensure_future:

import asyncio as _aio
coro = run_in_terminal(lambda: _pt_print(_PT_ANSI(text)))
_aio.ensure_future(coro)

This properly schedules the awaitable on the running event loop so the callback actually fires. I'd suggest either:

  1. Adopting the ensure_future pattern from #23302, or
  2. If #23302 merges first, rebasing this PR to avoid the conflict.

The gateway auto-title fix (failure_callback=None) is a clean separate concern — consider splitting it to its own PR for independent review.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels May 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #22851 — same issue (RuntimeWarning from unawaited run_in_terminal in prompt_toolkit 3.0.52+). Also see #22987 for alternative fix approach.

@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded by #23454.

Triage notes (high confidence):
Main cli.py:2070 uses inspect.isawaitable + asyncio.ensure_future to properly drive run_in_terminal coroutines, and _prompt_text_input has a thread-aware fallback (PR #23454 merged 2026-05-10). PR's warning suppression approach is obsolete.

Thanks for the contribution — the underlying problem this PR addresses has been resolved by the linked PR on current main. If you believe this was closed in error, please comment and we'll reopen.

(Bulk-closed during a CLI PR triage sweep.)

@teknium1 teknium1 closed this May 24, 2026
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 P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RuntimeWarning “run_in_terminal... was never awaited” when confirming /clear or /new in CLI

4 participants