Skip to content

fix: create AsyncOpenAI lazily in trajectory_compressor to avoid closed event loop - #4013

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b2abefdf
Mar 30, 2026
Merged

fix: create AsyncOpenAI lazily in trajectory_compressor to avoid closed event loop#4013
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b2abefdf

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

The AsyncOpenAI client in trajectory_compressor.py was created eagerly at init. When process_directory() calls asyncio.run() (creates+closes a loop), a second call crashes with RuntimeError: Event loop is closed because the cached client's httpx transport is bound to the dead loop.

Same class of bug as PR #3398 (main agent's event loop fix), different code path.

E2E verified:

  • Before fix: AsyncOpenAI() called 1 time at init, same stale instance reused across loops ❌
  • After fix: async_client=None at init, _get_async_client() creates fresh instance per loop ✅

5 tests pass including source verification.

Cherry-picked from PR #3696 by @binhnt92 with authorship preserved.

…ed event loop

The AsyncOpenAI client was created once at __init__ and stored as an
instance attribute. process_directory() calls asyncio.run() which creates
and closes a fresh event loop. On a second call, the client's httpx
transport is still bound to the closed loop, raising RuntimeError:
"Event loop is closed" — the same pattern fixed by PR #3398 for the
main agent loop.

Create the client lazily in _get_async_client() so each asyncio.run()
gets a client bound to the current loop.
@teknium1
teknium1 merged commit ed9af6e into main Mar 30, 2026
2 of 3 checks passed
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…ed event loop (NousResearch#4013)

The AsyncOpenAI client was created once at __init__ and stored as an
instance attribute. process_directory() calls asyncio.run() which creates
and closes a fresh event loop. On a second call, the client's httpx
transport is still bound to the closed loop, raising RuntimeError:
"Event loop is closed" — the same pattern fixed by PR NousResearch#3398 for the
main agent loop.

Create the client lazily in _get_async_client() so each asyncio.run()
gets a client bound to the current loop.

Co-authored-by: binhnt92 <binhnt.ht.92@gmail.com>
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…ed event loop (NousResearch#4013)

The AsyncOpenAI client was created once at __init__ and stored as an
instance attribute. process_directory() calls asyncio.run() which creates
and closes a fresh event loop. On a second call, the client's httpx
transport is still bound to the closed loop, raising RuntimeError:
"Event loop is closed" — the same pattern fixed by PR NousResearch#3398 for the
main agent loop.

Create the client lazily in _get_async_client() so each asyncio.run()
gets a client bound to the current loop.

Co-authored-by: binhnt92 <binhnt.ht.92@gmail.com>
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…ed event loop (NousResearch#4013)

The AsyncOpenAI client was created once at __init__ and stored as an
instance attribute. process_directory() calls asyncio.run() which creates
and closes a fresh event loop. On a second call, the client's httpx
transport is still bound to the closed loop, raising RuntimeError:
"Event loop is closed" — the same pattern fixed by PR NousResearch#3398 for the
main agent loop.

Create the client lazily in _get_async_client() so each asyncio.run()
gets a client bound to the current loop.

Co-authored-by: binhnt92 <binhnt.ht.92@gmail.com>
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…ed event loop (NousResearch#4013)

The AsyncOpenAI client was created once at __init__ and stored as an
instance attribute. process_directory() calls asyncio.run() which creates
and closes a fresh event loop. On a second call, the client's httpx
transport is still bound to the closed loop, raising RuntimeError:
"Event loop is closed" — the same pattern fixed by PR NousResearch#3398 for the
main agent loop.

Create the client lazily in _get_async_client() so each asyncio.run()
gets a client bound to the current loop.

Co-authored-by: binhnt92 <binhnt.ht.92@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants