Repository navigation
fix(codex-auth-helper): serve async clients on successive event loops; support Pydantic AI 2.66 (1.13.0) - #81
Merged
Merged
Conversation
…; support Pydantic AI 2.66 (1.13.0) The HTTP clients the helper owns for the Codex API and for token refresh kept connections bound to the first event loop. A request on a later loop, such as a second asyncio.run, reused one and failed with 'Event loop is closed'. Both are now replaced once the loop they last ran on has stopped, as Pydantic AI does for the clients its providers own. The SDK client is built with the public DefaultAsyncHttpxClient, whose lack of a closing finalizer keeps a replaced client from closing on the wrong loop. Pydantic AI support widens to 2.66.0 and Harness to 0.66.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
Fix:
codex-auth-helperasync clients now work on successive event loops.The HTTP clients the helper owns (the Codex API client and the token-refresh client) kept their pooled connections bound to the first event loop. A request on a later loop, for example a second
asyncio.run, or a host such as Kedi that closes its shared loop between runs, reused one of those connections and failed withRuntimeError: Event loop is closed. Closing the client afterwards reported the same error.Pydantic AI already refreshes the clients its providers own in this situation, but never a client passed in through
OpenAIProvider(openai_client=...), which is howcreate_codex_responses_modelbuilds the model. So the fix belongs here:DefaultAsyncHttpxClient. The SDK's default wrapper closes itself from its finalizer on whatever loop runs then, so a replaced client would have tried to close on the wrong loop.close()skips a client whose loop has stopped; its connections went with that loop.http_client=,auth_http_client=) are never replaced or closed, as before.Pydantic AI 2.66. Support widens to
pydantic-ai-slim<=2.66.0, and Harness moves to0.66.0. The CI and Makefile matrices add 2.64.0, 2.65.0 and 2.66.0. Versions are bumped to 1.13.0.Testing
tests/codex_auth_helper/test_event_loops.pyruns real keep-alive HTTP requests across successiveasyncio.runcalls and fails onmainfor both the SDK client and the token refresh client.make tests,check,check-formatted,check-coverage,docs-build,release-checkandcheck-langchain-stackpass.run_main()twice on one runtime, a second runtime closed in between, then a cleanaclose().🤖 Generated with Claude Code