hermes-bsd/hermes_cli
Zhekinmaksim 4a1840e683 fix(async): replace get_event_loop() with get_running_loop() in async contexts
Follow-up to PR #21293 (cli.py), which fixed the same anti-pattern.
`asyncio.get_event_loop()` is documented as effectively "always returns
the running loop when called from a coroutine" and emits
DeprecationWarning/RuntimeWarning in some interpreter configurations.
The Python docs explicitly recommend get_running_loop() inside coroutines.

Replaces the remaining 9 call sites that are unconditionally inside
async def bodies:

- tools/browser_cdp_tool.py — _cdp_call() (4 sites): deadline + remaining
  computations inside the async websockets.connect context manager.
- hermes_cli/web_server.py — get_status, _start_device_code_flow,
  submit_oauth_code (3 sites): all FastAPI async endpoints offloading
  blocking httpx / PKCE work to run_in_executor.
- environments/agent_loop.py — HermesAgentLoop (1 site): tool dispatch
  inside the async rollout loop.
- environments/benchmarks/terminalbench_2/terminalbench2_env.py —
  rollout_and_score_eval (1 site): test verification thread offload.

All 9 sites are unconditionally inside async def bodies, so a running
loop is guaranteed and no try/except RuntimeError fallback is needed
(unlike the cli.py case in #21293, which ran from a background thread).

Behavior is identical on supported Python versions; aligns the codebase
with the post-#21293 idiom and avoids future warnings as the deprecation
hardens.

Salvaged from PR #21930 by @Zhekinmaksim onto current main (the
original branch was 109 commits behind and carried unintended
stale-branch reverts of unrelated landed changes — _tail_lines
encoding=utf-8 and the Windows PTY bridge guard). Only the 9 swaps
from the PR's intended scope are applied here.
2026-05-09 02:34:19 -07:00
..
__init__.py
_parser.py
_subprocess_compat.py
auth.py
auth_commands.py
azure_detect.py
backup.py
banner.py
browser_connect.py
callbacks.py
checkpoints.py
claw.py
cli_output.py
clipboard.py
codex_models.py
colors.py
commands.py
completion.py
config.py
copilot_auth.py
cron.py
curator.py
curses_ui.py
debug.py
default_soul.py
dingtalk_auth.py
doctor.py
dump.py
env_loader.py
fallback_cmd.py
gateway.py
gateway_windows.py
goals.py
hooks.py
kanban.py
kanban_db.py
kanban_diagnostics.py
kanban_specify.py
logs.py
main.py
mcp_config.py
memory_setup.py
model_catalog.py
model_normalize.py
model_switch.py
models.py
nous_subscription.py
oneshot.py
pairing.py
platforms.py
plugins.py
plugins_cmd.py
profile_distribution.py
profiles.py
providers.py
pt_input_extras.py
pty_bridge.py
relaunch.py
runtime_provider.py
setup.py
skills_config.py
skills_hub.py
skin_engine.py
slack_cli.py
status.py
stdio.py
timeouts.py
tips.py
tools_config.py
uninstall.py
vercel_auth.py
voice.py
web_server.py
webhook.py