mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-07-03 14:05:26 +02:00
afaf50a972
Adds max_concurrency cap to GlobalRateLimiter using asyncio.Semaphore. A request now waits for a concurrency slot before the sliding window rate limit check, so at most N streams are open to the provider simultaneously, even when the rate window would allow more. Changes: - providers/rate_limit.py: max_concurrency param, _concurrency_sem, concurrency_slot() asynccontextmanager - providers/openai_compat.py: pass max_concurrency to limiter; wrap execute_with_retry + stream iteration in concurrency_slot() - providers/base.py: max_concurrency field on ProviderConfig - config/settings.py: provider_max_concurrency setting (PROVIDER_MAX_CONCURRENCY env var, default None = unlimited) - api/dependencies.py: pass provider_max_concurrency into all three provider ProviderConfig instantiations - .env.example: document PROVIDER_MAX_CONCURRENCY (commented out) - tests/providers/test_provider_rate_limit.py: 5 new tests covering concurrency limit enforcement, slot release on exception, noop when unconfigured - tests/api/test_dependencies.py: add provider_max_concurrency=None to mock settings helper https://claude.ai/code/session_014mrF1WMNgmNjtPBuoQHsbg