concurrency-check
Skill2 starsChanged 3 days agoMITView on GitHub
Audit and prove whether a FastAPI + PostgreSQL backend survives 2-20+ simultaneous users hitting the same endpoints at the exact same millisecond. Combines Python AST concurrency checks (event-loop blocks, Read-Modify-Write races, missing idempotency, multi-worker global state, BackgroundTasks session reuse, HTTP inside DB transactions) with a zero-dependency live asyncio parallel burst probe and async race test templates. Writes CONCURRENCY_REPORT.md.
In this repository3 other files it gives its agents.
- backend-reviewSkill
- fastapi-prod-readySkill
- migration-reviewSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Read-only by default: Do not edit production source files.
- Distinctive: line 16
Run the zero-dependency concurrency scan:
- Very specific: line 24
Read-Modify-Write race conditions (SELECT -> Python if -> UPDATE/commit without with_for_update(), atomic UPDATE ...
- Very specific: line 44
Verify that 2 simultaneous requests with the same Idempotency-Key do not create two distinct rows or double-charge a wallet.
- Very specific: line 46
If no server is running, state clearly in CONCURRENCY_REPORT.md that the live probe was skipped and provide the exact command for the user …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Concurrency check (read-only audit & test generator)
Goal: prove — with both AST evidence and live parallel-request measurements — what happens when 2, 10, or 20 users hit the backend at the exact same millisecond. Talk to the user in their language; write CONCURRENCY_REPORT.md in English.
Read-only by default. Do not edit production source files. Only write CONCURRENCY_REPORT.md (and optional tests/test_concurrency_*.py when the user asks to generate regression tests).
<kit> = <this skill's folder>/../fastapi-prod-ready. Read <kit>/CONCURRENCY-AND-ASYNC.md and <kit>/SQLALCHEMY-AND-POSTGRES.md before interpreting findings.
1. Static AST concurrency audit
Run the zero-dependency concurrency scan:
python <kit>/scripts/concurrency_probe.py --project <project> --out <report_dir> --no-failInspect every flagged file:line:
- Blocking sync calls inside
async def(requests,time.sleep, sync DB, sync password hashing). - Read-Modify-Write race conditions (
SELECT-> Pythonif->UPDATE/commitwithoutwith_for_update(), atomicUPDATE ... WHERE, orIntegrityError). - Critical
POSTendpoints lackingIdempotency-Key/ conflict deduplication. - Module-level mutable globals (
dict/list/set) that diverge across--workers > 1. Depends(get_db)session passed intoBackgroundTasks.add_task(...).- Outbound HTTP calls inside
async with db.begin():.
2. Live parallel burst probe (when a local/staging server is reachable)
Never probe a production system. The script enforces this: it refuses any host other than localhost / 127.0.0.1 / ::1 unless you pass --allow-remote (only for a staging server the user owns and names), and refuses POST/PUT/PATCH/DELETE or --idempotency-check unless you pass --allow-writes (only against a disposable test database). Ask the user before adding either flag. Against a local or staging server:
- Read / latency scaling probe (event-loop block detection):
Comparepython <kit>/scripts/concurrency_probe.py --project <project> --url http://127.0.0.1:8000/api/items --levels 2,10,20 --out <report_dir> --no-failN=1baseline latency againstN=10andN=20parallel median latency. IfN=10scales ~5–10× slower thanN=1, the event loop is blocked or the DB connection pool is saturated. - Double-click / idempotency burst probe (on a safe test
POSTendpoint):
Verify that 2 simultaneous requests with the samepython <kit>/scripts/concurrency_probe.py --url http://127.0.0.1:8000/api/orders --method POST --body '{"item_id": 1, "qty": 1}' --header "Authorization: Bearer <test-token>" --levels 2,10 --idempotency-check --allow-writes --out <report_dir> --no-failIdempotency-Keydo not create two distinct rows or double-charge a wallet.
If no server is running, state clearly in CONCURRENCY_REPORT.md that the live probe was skipped and provide the exact command for the user to run.
3. Optional pytest async race test generation
When the user asks for reproducible tests (or when an RMW / idempotency bug is confirmed), provide a self-contained pytest + asyncio.gather concurrency test template from <kit>/CONCURRENCY-AND-ASYNC.md that fires 10 simultaneous coroutines against a real PostgreSQL test database (never SQLite for locking tests) and asserts final balance/stock invariants.
4. Deliver CONCURRENCY_REPORT.md
Include:
- Verdict (
❌ NOT READY/⚠️ ALMOST READY/✅ READY). - Static AST findings (verified
file:line, dropped false alarms explained). - Live probe table (
N=1 / 2 / 10 / 20, wall ms, median, p95, scaling ratio, status codes) and double-click idempotency result (or explicit "live probe skipped" note). - Concrete fixes and pool sizing formula (
workers * (pool_size + max_overflow) < max_connections).
Reply in chat in 3–6 lines in the user's language with verdict, worst concurrency risk, single next step, and report path.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

