Skip to content

Commit f91065c

Browse files
committed
Align max_running error wording and document the >= 1 constraint
Match the '>= 1, got N' phrasing used by OnlineEvaluator (pydantic#6267), note the constraint in the ConcurrencyLimit and ConcurrencyLimiter docstrings, and drop the stale 'before a run can hang' test wording.
1 parent d33c609 commit f91065c

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

pydantic_ai_slim/pydantic_ai/concurrency.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def _validate_max_running(max_running: int) -> None:
2626
if max_running < 1:
2727
raise UserError(
28-
f'max_running must be a positive integer, got {max_running}. Use None for no concurrency limiting.'
28+
f'max_running must be >= 1, got {max_running}. Use None for no concurrency limiting.'
2929
)
3030

3131

@@ -76,7 +76,7 @@ class ConcurrencyLimit:
7676
"""Configuration for concurrency limiting with optional backpressure.
7777
7878
Args:
79-
max_running: Maximum number of concurrent operations allowed.
79+
max_running: Maximum number of concurrent operations allowed. Must be >= 1.
8080
max_queued: Maximum number of operations waiting in the queue.
8181
If None, the queue is unlimited. If exceeded, raises `ConcurrencyLimitExceeded`.
8282
"""
@@ -107,11 +107,14 @@ def __init__(
107107
"""Initialize the ConcurrencyLimiter.
108108
109109
Args:
110-
max_running: Maximum number of concurrent operations.
110+
max_running: Maximum number of concurrent operations. Must be >= 1.
111111
max_queued: Maximum queue depth before raising ConcurrencyLimitExceeded.
112112
name: Optional name for this limiter, used for observability when sharing
113113
a limiter across multiple models or agents.
114114
tracer: OpenTelemetry tracer for span creation.
115+
116+
Raises:
117+
UserError: If `max_running` is less than 1.
115118
"""
116119
_validate_max_running(max_running)
117120
self._limiter = anyio.CapacityLimiter(max_running)

tests/test_concurrency.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ async def test_nowait_acquisition(self):
7070
@pytest.mark.parametrize('max_running', [0, -1, -5])
7171
async def test_invalid_max_running(self, max_running: int):
7272
"""Test that invalid concurrency limits are rejected before creating the limiter."""
73-
with pytest.raises(UserError, match=f'max_running must be a positive integer, got {max_running}'):
73+
with pytest.raises(UserError, match=f'max_running must be >= 1, got {max_running}'):
7474
ConcurrencyLimiter(max_running=max_running)
7575

7676
@pytest.mark.parametrize('max_running', [0, -1, -5])
7777
async def test_invalid_concurrency_limit_config(self, max_running: int):
7878
"""Test that invalid concurrency limit config values fail eagerly."""
79-
with pytest.raises(UserError, match=f'max_running must be a positive integer, got {max_running}'):
79+
with pytest.raises(UserError, match=f'max_running must be >= 1, got {max_running}'):
8080
ConcurrencyLimit(max_running=max_running)
8181

8282
async def test_waiting_count_tracking(self):
@@ -208,12 +208,12 @@ async def test_from_limiter_config(self):
208208

209209
async def test_from_invalid_limit(self):
210210
"""Test that invalid normalized concurrency limits fail eagerly."""
211-
with pytest.raises(UserError, match='max_running must be a positive integer, got 0'):
211+
with pytest.raises(UserError, match='max_running must be >= 1, got 0'):
212212
ConcurrencyLimiter.from_limit(0)
213213

214214
async def test_normalize_to_limiter_rejects_invalid_limit(self):
215215
"""Test that invalid normalized concurrency limits fail before use."""
216-
with pytest.raises(UserError, match='max_running must be a positive integer, got 0'):
216+
with pytest.raises(UserError, match='max_running must be >= 1, got 0'):
217217
normalize_to_limiter(0)
218218

219219
async def test_none_still_means_no_limit(self):
@@ -335,8 +335,8 @@ async def test_agent_with_limiter_concurrency(self):
335335

336336
@pytest.mark.parametrize('max_running', [0, -1])
337337
async def test_agent_invalid_int_concurrency_limit(self, max_running: int):
338-
"""Test that invalid agent concurrency limits fail before a run can hang."""
339-
with pytest.raises(UserError, match=f'max_running must be a positive integer, got {max_running}'):
338+
"""Test that invalid agent concurrency limits fail eagerly at construction."""
339+
with pytest.raises(UserError, match=f'max_running must be >= 1, got {max_running}'):
340340
Agent(TestModel(), max_concurrency=max_running)
341341

342342

0 commit comments

Comments
 (0)