Skip to content

Cap default httpx connection pool on the task-sdk Client#67506

Open
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:standardize-client-httpx-pool-limits
Open

Cap default httpx connection pool on the task-sdk Client#67506
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:standardize-client-httpx-pool-limits

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented May 25, 2026

Client.__init__ did not set explicit httpx.Limits, so each Client inherited httpx's defaults of max_connections=100 and max_keepalive_connections=10. The supervisor's own _ensure_client capped at max_connections=10, max_keepalive_connections=1 — so the two code paths that build a task-sdk Client diverged by an order of magnitude in their pool behaviour, with no documented reason and surprising resource use under high concurrency.

Reported as F-011 in the apache/tooling-agents L3 task-sdk sweep 0920c77.

Change

Standardise on a single bounded default at the Client level via kwargs.setdefault("limits", httpx.Limits(max_keepalive_connections=5, max_connections=20)). The supervisor's lower-cap path is unchanged (it sets limits explicitly before passing to the Client), and any caller that needs different limits can still pass limits=... via kwargs.

Choosing (5, 20) rather than (1, 10): a non-supervisor Client (e.g. instantiated directly by tests, CLI, or future callers) may handle higher per-instance concurrency than a single task subprocess, so the default sits between the supervisor's tight cap and httpx's untenably-high default.

Test plan

  • test_default_pool_limits_are_bounded — instantiates a real (non-mock-transport) Client and asserts pool._max_connections == 20 and pool._max_keepalive_connections == 5.
  • test_pool_limits_can_be_overriddenlimits=httpx.Limits(...) kwarg overrides the default.
  • prek run ruff clean.
  • prek run mypy-task-sdk clean.
  • Full test_client.py suite: 117 passed.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

``Client.__init__`` did not set explicit ``httpx.Limits``, so each
Client inherited httpx's defaults of ``max_connections=100`` and
``max_keepalive_connections=10``. The supervisor's own
``_ensure_client`` capped at ``max_connections=10,
max_keepalive_connections=1`` — so the two code paths that build a
task-sdk Client diverged by an order of magnitude in their pool
behaviour, with no documented reason and surprising resource use
under high concurrency.

Standardise on a single bounded default at the Client level:
``httpx.Limits(max_keepalive_connections=5, max_connections=20)``.
The supervisor's lower-cap path is unchanged (it sets ``limits``
explicitly), and any caller that needs different limits can still
pass ``limits=...`` via kwargs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant