concurrency-race-analysis
Skill0 starsChanged 5 months agoMITView on GitHub
Detects and reasons about data races, deadlocks, livelocks, and memory-ordering bugs in concurrent and parallel code. Use when reviewing multithreaded code, lock-free structures, async pipelines, or when symptoms include intermittent corruption, heisenbugs, hangs, or load-dependent failures.
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Treat every shared mutable location as a potential race until proven otherwise.
- Distinctive: line 12
Before reading the locking code, enumerate the actors and the shared state:
- Distinctive: line 14
Shared cells: every variable, field, or resource touched by >1 thread/task.
- Distinctive: line 26
Memory visibility: write on T1 never observed by T2 due to missing acquire/release.
- Distinctive: line 32
Run two writers simultaneously.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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 & Race Analysis
Treat every shared mutable location as a potential race until proven otherwise. The bug is almost never where the crash surfaces.
Build the interleaving model first
Before reading the locking code, enumerate the actors and the shared state:
- Shared cells: every variable, field, or resource touched by >1 thread/task. Mark read-only vs read-write.
- Happens-before edges: what establishes ordering? (lock acquire/release, channel send/recv, join, atomic with acquire/release, memory fence). Absence of an edge = reorderable.
- Atomicity scope: which groups of operations must be indivisible. Most bugs are "each op is atomic, but the composite isn't" (check-then-act, read-modify-write).
Failure-mode taxonomy (check each explicitly)
- Data race: unsynchronized access where ≥1 is a write. Under a relaxed memory model this is UB, not just a stale read.
- Atomicity violation: TOCTOU, lost update, double-checked locking without proper fences.
- Order violation: B assumes A already ran (init-before-use across threads).
- Deadlock: cyclic lock acquisition. Map the lock-order graph; any cycle is a latent deadlock.
- Livelock / starvation: progress without forward progress; unfair locks; backoff that resonates.
- ABA: pointer/counter reused between read and CAS. Needs tagged pointers or hazard pointers.
- Memory visibility: write on T1 never observed by T2 due to missing acquire/release.
Adversarial validation
For each shared cell, construct the worst interleaving by hand:
- Preempt the thread between a read and its dependent write.
- Run two writers simultaneously; is the result one of the inputs or garbage?
- Assume the compiler/CPU reorders any two operations not separated by a fence. Does an invariant break?
- For lock-free code: assume a thread stalls indefinitely mid-operation. Can others still make progress and stay correct?
Non-obvious traps
- A single
volatile/atomicmakes one access atomic but does not make a multi-step invariant atomic. - Holding a lock while calling out to unknown code (callbacks, virtual dispatch) invites lock-order inversion.
- "Mostly works under load testing" is the signature of a race, not evidence of correctness — interleavings are sampled, not exhausted.
- Fixing by adding sleeps/retries hides the race and shifts it under timing pressure.
Output structure
For each finding report: shared cell → unsynchronized access pattern → concrete interleaving that breaks it → invariant violated → minimal fix (narrow the critical section, pick the right atomic ordering, or redesign to eliminate sharing). Prefer eliminating shared mutable state over adding locks.
In this repository29 other files it gives its agents.
- adversarial-code-reviewSkill
- api-contract-designSkill
- attack-surface-mappingSkill
- authn-authz-design-reviewSkill
- benchmark-designSkill
- capacity-scalability-planningSkill
- data-consistency-modelingSkill
- data-exfiltration-analysisSkill
- distributed-consensus-designSkill
- error-handling-architectureSkill
- event-driven-architectureSkill
- experiment-designSkill
- hypothesis-falsificationSkill
- incident-rca-postmortemSkill
- legacy-refactoring-strategySkill
- literature-synthesisSkill
- metrics-designSkill
- multi-layer-caching-strategySkill
- mvp-scope-cuttingSkill
- performance-profilingSkill
- rate-limiting-designSkill
- requirements-disambiguationSkill
- secrets-management-auditSkill
- statistical-validity-analysisSkill
- supply-chain-risk-analysisSkill
- system-decomposition-synthesisSkill
- threat-modelingSkill
- tradeoff-decision-frameworkSkill
- user-failure-mode-mappingSkill
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.

