Skip to content

fix(cli): install async exception filter on active loop - #69018

Open
steezkelly wants to merge 1 commit into
NousResearch:mainfrom
steezkelly:fix/cli-httpx-loop-handler
Open

fix(cli): install async exception filter on active loop#69018
steezkelly wants to merge 1 commit into
NousResearch:mainfrom
steezkelly:fix/cli-httpx-loop-handler

Conversation

@steezkelly

Copy link
Copy Markdown
Contributor

Summary

  • install the CLI asyncio exception filter from prompt_toolkit's pre_run callback, when its event loop is actually running
  • preserve prompt_toolkit's existing handler for non-benign exceptions
  • add regression coverage for handler behavior and Application.run() wiring

Root cause

HermesCLI.run() called asyncio.get_running_loop() synchronously before Application.run() started prompt_toolkit's loop. The resulting RuntimeError was swallowed, so the filter was never installed and benign late httpx/httpcore cleanup surfaced as an interactive "Event loop is closed" exception screen.

Verification

  • pytest tests/cli/test_cli_asyncio_exception_handler.py -q — 2 passed
  • pytest tests/cli tests/hermes_cli/test_suppress_eio_on_interrupt.py tests/test_model_tools_async_bridge.py -q -k "not test_session_not_found_goes_to_stdout_in_full_mode" — 1129 passed, 1 deselected
  • full selection has one known order-dependent baseline failure in test_session_not_found_goes_to_stdout_in_full_mode; it reproduces unchanged on the base checkout and passes in isolation
  • ruff check cli.py tests/cli/test_cli_asyncio_exception_handler.py — passed
  • git diff --check and py_compile — passed

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels Jul 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to merged #3398 and the original report #3436. The current diff repairs a regression in the earlier suppression path: the filter was previously installed before prompt_toolkit had a running event loop.

@teknium1 teknium1 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.

Thanks for tracing the installation-order failure. The premise is confirmed on current main: cli.py:17095 calls get_running_loop() before app.run() at cli.py:17106, then suppresses the resulting RuntimeError at cli.py:17097.

Problems

  • tests/cli/test_cli_asyncio_exception_handler.py:40 uses inspect.getsource(HermesCLI.run) and asserts an implementation string. AGENTS.md prohibits source-reading tests, and this assertion cannot establish that Application.run() receives and executes the callback.

Suggested changes

  • Replace that assertion with a behavioral wiring test that captures the pre_run passed to Application.run, invokes it from a live asyncio loop, and verifies the loop filter is installed.

The production approach is otherwise narrowly scoped to the affected CLI path. This is an automated hermes-sweeper review.


def test_cli_installs_exception_filter_after_prompt_toolkit_loop_starts():
source = inspect.getsource(HermesCLI.run)

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.

Please replace this source-inspection assertion with a behavioral test that captures Application.run(..., pre_run=...), invokes the callback inside a running loop, and verifies the handler. AGENTS.md prohibits tests that read production source text, and this does not prove the callback wiring executes.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/install-update Installer, updater, packaging, wheels, doctor labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/install-update Installer, updater, packaging, wheels, doctor comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants