Skip to content

bug: /reload-mcp triggers RuntimeWarning from unawaited run_in_terminal coroutine #23009

@frannunpal

Description

@frannunpal

Description

Running /reload-mcp triggers a RuntimeWarning: coroutine "run_in_terminal.<locals>.run" was never awaited that gets caught in the process_loop exception handler and logged at cli.py:12433.

Root Cause

The bug is in _prompt_text_input() at cli.py:5876. When called from a background thread (the process_loop thread), it invokes prompt_toolkit.application.run_in_terminal() which returns a Future (via ensure_future(run())). Since _prompt_text_input is a synchronous method that does not await this Future, Python raises RuntimeWarning when the unretrieved Future/coroutine is garbage collected.

Steps to Reproduce

  1. Run Hermes CLI
  2. Type /reload-mcp
  3. Observe RuntimeWarning after responding to the confirmation prompt

Expected Behavior

No warnings. Confirmation prompts should work cleanly from any thread.

Fix

The sibling method _curses_single_select() (line ~5843) already has the correct pattern:

in_main_thread = threading.current_thread() is threading.main_thread()
if self._app and in_main_thread:
    run_in_terminal(...)
else:
    ...  # direct call

The fix adds the same in_main_thread guard to _prompt_text_input(). When run_in_terminal would be called from a background thread, it falls through to the synchronous input() path instead.

Patch

Applied locally. Key change in _prompt_text_input():

-        if self._app:
+        in_main_thread = threading.current_thread() is threading.main_thread()
+
+        if self._app and in_main_thread:
             from prompt_toolkit.application import run_in_terminal

Environment

  • prompt_toolkit 3.0.52
  • Hermes Agent latest (git main)

/label bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/cliCLI entry point, hermes_cli/, setup wizardtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions