agentleFS
tuvatechvalleytuvatechvalley/fastapi-prod-ready/skills/concurrency-check/SKILL.md

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.

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
  1. Very specific:

    Read-only by default: Do not edit production source files.

    line 10
  2. Distinctive:

    Run the zero-dependency concurrency scan:

    line 16
  3. Very specific:

    Read-Modify-Write race conditions (SELECT -> Python if -> UPDATE/commit without with_for_update(), atomic UPDATE ...

    line 24
  4. Very specific:

    Verify that 2 simultaneous requests with the same Idempotency-Key do not create two distinct rows or double-charge a wallet.

    line 44
  5. Very specific:

    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 …

    line 46

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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-fail

Inspect every flagged file:line:

  • Blocking sync calls inside async def (requests, time.sleep, sync DB, sync password hashing).
  • Read-Modify-Write race conditions (SELECT -> Python if -> UPDATE/commit without with_for_update(), atomic UPDATE ... WHERE, or IntegrityError).
  • Critical POST endpoints lacking Idempotency-Key / conflict deduplication.
  • Module-level mutable globals (dict/list/set) that diverge across --workers > 1.
  • Depends(get_db) session passed into BackgroundTasks.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:

  1. Read / latency scaling probe (event-loop block detection):
    python <kit>/scripts/concurrency_probe.py --project <project> --url http://127.0.0.1:8000/api/items --levels 2,10,20 --out <report_dir> --no-fail
    Compare N=1 baseline latency against N=10 and N=20 parallel median latency. If N=10 scales ~5–10× slower than N=1, the event loop is blocked or the DB connection pool is saturated.
  2. Double-click / idempotency burst probe (on a safe test POST endpoint):
    python <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-fail
    Verify that 2 simultaneous requests with the same Idempotency-Key do 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:

  1. Verdict (❌ NOT READY / ⚠️ ALMOST READY / ✅ READY).
  2. Static AST findings (verified file:line, dropped false alarms explained).
  3. 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).
  4. 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.