feat(python): add aiohttp auto-detection for async HTTP client#13586
Open
feat(python): add aiohttp auto-detection for async HTTP client#13586
Conversation
|
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage. Once credits are available, reopen this pull request to trigger a review. |
1313402 to
8aa128a
Compare
When httpx_aiohttp is installed, the async client automatically uses it instead of plain httpx.AsyncClient. Adds DefaultAioHttpClient and DefaultAsyncHttpxClient convenience classes with SDK defaults.
…pass Fix mypy errors by adding type: ignore comments for optional httpx_aiohttp imports and widening timeout param to Optional[float]. Add conftest hook to auto-skip @pytest.mark.aiohttp tests when the package is missing. Update CI to run a second test pass after installing the aiohttp extra.
…dule pollution Co-Authored-By: bot_apk <apk@cognition.ai>
8aa128a to
0bab983
Compare
…h internal process timeout The python remote generation can take >60s, causing the vitest 60s timeout to fire before cliV2.generate's internal 180s process timeout. Increased both python and go basic generation test timeouts to 180_000ms to match. Co-Authored-By: bot_apk <apk@cognition.ai>
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.
Description
Auto-detect
httpx_aiohttpat runtime and use it for the async HTTP client when available, falling back to plainhttpx.AsyncClient.Based on: cohere-ai/cohere-python#739
Changes Made
_make_default_async_client()helper inclient.pythat trieshttpx_aiohttp.HttpxAiohttpClientfirst, falling back tohttpx.AsyncClient_default_clients.pymodule withDefaultAioHttpClientandDefaultAsyncHttpxClientconvenience classes (SDK-appropriate defaults)[aiohttp]extra inpyproject.toml@pytest.mark.aiohttpmarker and auto-skip logic inconftest.pypytest -m aiohttpafter installing the extracliV2.generateprocess timeout (fixestest-eteCI flake where Python remote generation occasionally exceeds 60s)Updates since last revision
mainto resolve mergeable statusimportlib.reloadbug intest_default_aiohttp_client_raises_without_package: the cleanup reload was inside themock.patch.dictcontext manager, which leftseed._default_clientspolluted with the error-raising class after the mock restoredsys.modules. Moved the reload outside thewithblock so the module is properly restored.test-eteCI timeout: the vitestit()timeout for thebasic generation > pythontest was 60s, butcliV2.generate()uses an internal process timeout of 180s. Python remote generation took ~68s in CI, exceeding the vitest timeout. Increased bothpythonandgobasic generation test timeouts to180_000ms to match.Testing
pytest -m "not aiohttp"— 6 tests pass (fallback behavior without httpx_aiohttp)pip install httpx-aiohttp && pytest -m "aiohttp"— 3 tests pass (autodetect with httpx_aiohttp)test-eteCI check now passes with increased timeoutsReview checklist for humans
_make_default_async_clienthandles bothhttpx_aiohttppresent and absent cases correctlyimportlib.reloadfix: the reload at line 97 oftest_aiohttp_autodetect.pyis now outside thewith mock.patch.dict(...)block — this prevents module pollution whenhttpx_aiohttpis actually installedmock.patch.dict(sys.modules, {"httpx_aiohttp": None})to simulate missing package — verify this doesn't leak across testscliV2.generatetimeout; the outerdescribeblock already has a 300s timeout)Link to Devin session: https://app.devin.ai/sessions/2562e5b9bd6a4be7a5756c141751c323