fix: create AsyncOpenAI lazily in trajectory_compressor to avoid closed event loop - #3696
Closed
binhnt92 wants to merge 1 commit into
Closed
Conversation
…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 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.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
AsyncOpenAIclient intrajectory_compressor.pyis created once at__init__time and stored asself.async_client. Whenprocess_directory()callsasyncio.run(), it creates a fresh event loop, runs async work, then closes the loop. On a second call toprocess_directory(), the cached client's internal httpx transport is still bound to the now-closed loop, raisingRuntimeError: Event loop is closed.This is the same pattern fixed by PR #3398 for the main agent loop's AsyncOpenAI client.
Changes Made
AsyncOpenAI(...)construction from_init_summarizer()_get_async_client()method that creates a fresh client on each call, binding it to the current running event loop_generate_summary_async()to use_get_async_client()How to Test
5 tests covering: client is None after init, lazy creation works, fresh instance per call, source verification (no eager creation, method exists).
Checklist