Cap default httpx connection pool on the task-sdk Client#67506
Open
potiuk wants to merge 1 commit into
Open
Conversation
``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.
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.
Client.__init__did not set explicithttpx.Limits, so each Client inherited httpx's defaults ofmax_connections=100andmax_keepalive_connections=10. The supervisor's own_ensure_clientcapped atmax_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-agentsL3 task-sdk sweep0920c77.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 setslimitsexplicitly before passing to the Client), and any caller that needs different limits can still passlimits=...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 assertspool._max_connections == 20andpool._max_keepalive_connections == 5.test_pool_limits_can_be_overridden—limits=httpx.Limits(...)kwarg overrides the default.prek run ruffclean.prek run mypy-task-sdkclean.test_client.pysuite: 117 passed.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines