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
- Run Hermes CLI
- Type
/reload-mcp
- 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
Description
Running
/reload-mcptriggers aRuntimeWarning: coroutine "run_in_terminal.<locals>.run" was never awaitedthat gets caught in theprocess_loopexception handler and logged atcli.py:12433.Root Cause
The bug is in
_prompt_text_input()atcli.py:5876. When called from a background thread (theprocess_loopthread), it invokesprompt_toolkit.application.run_in_terminal()which returns aFuture(viaensure_future(run())). Since_prompt_text_inputis a synchronous method that does notawaitthis Future, Python raisesRuntimeWarningwhen the unretrieved Future/coroutine is garbage collected.Steps to Reproduce
/reload-mcpRuntimeWarningafter responding to the confirmation promptExpected 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:The fix adds the same
in_main_threadguard to_prompt_text_input(). Whenrun_in_terminalwould be called from a background thread, it falls through to the synchronousinput()path instead.Patch
Applied locally. Key change in
_prompt_text_input():Environment
/label bug