Skip to content

fix: suppress unawaited Future warning in _schedule_run_in_terminal#22851

Closed
danbedford wants to merge 1 commit into
NousResearch:mainfrom
danbedford:fix/suppress-unawaited-future-warning-cli
Closed

fix: suppress unawaited Future warning in _schedule_run_in_terminal#22851
danbedford wants to merge 1 commit into
NousResearch:mainfrom
danbedford:fix/suppress-unawaited-future-warning-cli

Conversation

@danbedford

Copy link
Copy Markdown

Summary

In prompt_toolkit 3.0.52, run_in_terminal() is a regular function that returns an asyncio.Future (via ensure_future). Discarding the return value lets Python GC it without ever calling result(), which in Python 3.12+ fires "coroutine was never awaited" RuntimeWarnings that bubble into process_loop exception handler and get logged as process_loop unhandled error.

Root Cause

_schedule_run_in_terminal() checked asyncio.iscoroutinefunction(run_in_terminal) — which is False for pt 3.0.52 (it is a sync function that internally wraps a coroutine). So the else branch called run_in_terminal(callback) and discarded the returned Future.

The callback did execute (it was already scheduled via ensure_future), but the discarded Future triggered the GC warning.

Fix

Capture the return value from run_in_terminal(callback) and, if it is an asyncio.Future, attach a no-op done_callback so the Future is properly collected without warnings.

Impact

  • Eliminates the "coroutine was never awaited" warning and the subsequent "process_loop unhandled error" log message
  • No behavioral change — the callback still executes as before
  • Affects /new, /clear, /reset, and any other slash command that triggers cross-thread printing via _cprint() during session transitions

In prompt_toolkit 3.0.52, run_in_terminal() is a regular function that
returns an asyncio.Future (via ensure_future). Discarding the return
value lets Python GC it without calling result(), which in Python 3.12+
fires 'coroutine was never awaited' warnings that bubble into
process_loop's exception handler.

Fix: capture the return value and attach a no-op done_callback so the
Future is properly collected. The callback itself still executes normally
(the Future was already scheduled on the event loop via ensure_future).
@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 9, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as already fixed on main.

Triage notes (medium confidence):
Main's _cprint _schedule helper at cli.py:2056-2076 already wraps the awaitable returned by run_in_terminal via _aio.ensure_future and only falls through when the result is non-awaitable — the unawaited-Future warning this PR targets is already resolved on main.

If you still see this on the latest version, please reopen with reproduction steps.

(Bulk-closed during a CLI triage sweep.)

@teknium1 teknium1 closed this May 24, 2026
@danbedford danbedford deleted the fix/suppress-unawaited-future-warning-cli branch May 24, 2026 11:29
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.

3 participants