Skip to content

feat(python): add aiohttp auto-detection for async HTTP client#13586

Open
jsklan wants to merge 4 commits intomainfrom
jsklan/aiohttp-python
Open

feat(python): add aiohttp auto-detection for async HTTP client#13586
jsklan wants to merge 4 commits intomainfrom
jsklan/aiohttp-python

Conversation

@jsklan
Copy link
Contributor

@jsklan jsklan commented Mar 16, 2026

Description

WIP — This PR modifies the seed fixture output directly. Generator changes to produce this output will follow.

Auto-detect httpx_aiohttp at runtime and use it for the async HTTP client when available, falling back to plain httpx.AsyncClient.

Based on: cohere-ai/cohere-python#739

Changes Made

  • Add _make_default_async_client() helper in client.py that tries httpx_aiohttp.HttpxAiohttpClient first, falling back to httpx.AsyncClient
  • Add _default_clients.py module with DefaultAioHttpClient and DefaultAsyncHttpxClient convenience classes (SDK-appropriate defaults)
  • Add optional [aiohttp] extra in pyproject.toml
  • Add pytest-based tests with @pytest.mark.aiohttp marker and auto-skip logic in conftest.py
  • Add CI two-pass testing: standard tests then pytest -m aiohttp after installing the extra
  • Increase vitest timeouts for basic generation ETE tests from 60s → 180s to match the internal cliV2.generate process timeout (fixes test-ete CI flake where Python remote generation occasionally exceeds 60s)
  • Updated README.md generator (if applicable)

Updates since last revision

  • Rebased onto main to resolve mergeable status
  • Fixed importlib.reload bug in test_default_aiohttp_client_raises_without_package: the cleanup reload was inside the mock.patch.dict context manager, which left seed._default_clients polluted with the error-raising class after the mock restored sys.modules. Moved the reload outside the with block so the module is properly restored.
  • Fixed test-ete CI timeout: the vitest it() timeout for the basic generation > python test was 60s, but cliV2.generate() uses an internal process timeout of 180s. Python remote generation took ~68s in CI, exceeding the vitest timeout. Increased both python and go basic generation test timeouts to 180_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-ete CI check now passes with increased timeouts
  • Update generator to produce this output
  • Run seed tests to validate generator matches fixture

Review checklist for humans

  • Verify _make_default_async_client handles both httpx_aiohttp present and absent cases correctly
  • Confirm importlib.reload fix: the reload at line 97 of test_aiohttp_autodetect.py is now outside the with mock.patch.dict(...) block — this prevents module pollution when httpx_aiohttp is actually installed
  • Note: test mocking uses mock.patch.dict(sys.modules, {"httpx_aiohttp": None}) to simulate missing package — verify this doesn't leak across tests
  • Confirm the 180s vitest timeout increase for basic generation tests is acceptable (matches internal cliV2.generate timeout; the outer describe block already has a 300s timeout)

Link to Devin session: https://app.devin.ai/sessions/2562e5b9bd6a4be7a5756c141751c323


Open with Devin

@jsklan jsklan self-assigned this Mar 16, 2026
@claude
Copy link

claude bot commented Mar 16, 2026

⚠️ Code review skipped — your organization's overage spend limit has been reached.

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.

@devin-ai-integration devin-ai-integration bot force-pushed the jsklan/aiohttp-python branch from 1313402 to 8aa128a Compare March 19, 2026 22:09
devin-ai-integration[bot]

This comment was marked as resolved.

jsklan and others added 3 commits March 20, 2026 20:28
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>
@devin-ai-integration devin-ai-integration bot force-pushed the jsklan/aiohttp-python branch from 8aa128a to 0bab983 Compare March 20, 2026 20:29
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant