fix(cli): suppress RuntimeWarning from unawaited run_in_terminal in prompt_toolkit 3.0.52+#23317
fix(cli): suppress RuntimeWarning from unawaited run_in_terminal in prompt_toolkit 3.0.52+#23317Ninso112 wants to merge 2 commits into
Conversation
… 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
left a comment
There was a problem hiding this comment.
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:
- Adopting the
ensure_futurepattern from #23302, or - 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.
|
Closing as superseded by #23454. Triage notes (high confidence): 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.) |
Summary
RuntimeWarning: coroutine 'run_in_terminal.<locals>.run' was never awaitedthat appears when confirming/clear,/new,/reset, or/undoin the interactive CLIrun_in_terminal()to return anAwaitable. Four call sites incli.pyinvoke it fire-and-forget because the callback is scheduled on the already-running event loop and executes correctlywarnings.catch_warnings()since the callback semantics are unchangedAffected call sites
_prompt_text_input/clear,/newconfirmation prompts_run_curses_pickerhandle_ctrl_z(key binding)_cprint._scheduleFixes #23297.