Agent skill
race-condition-audit
Systematic identification of race conditions, concurrency bugs, and thread-safety issues across codebases. Use when asked to find race conditions, audit concurrent code, debug non-deterministic behavior, review thread safety, find data races, or analyze async/parallel code. Supports TypeScript, JavaScript, Python, Go, Rust, and C++.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/development/race-condition-audit-vultuk-coding-agent-skills
SKILL.md
Race Condition Audit
Systematic process for finding concurrency bugs that cause data corruption, deadlocks, or non-deterministic behavior.
Process
Step 1: Map Concurrency Entry Points
Find where concurrent execution begins:
# TypeScript/JavaScript
grep -rn "async \|Promise\|Worker\|fork" --include="*.ts" --include="*.js"
# Python
grep -rn "threading\|asyncio\|async def" --include="*.py"
# Go
grep -rn "go func\|go \w\+(" --include="*.go"
# Rust
grep -rn "thread::spawn\|tokio::spawn\|async fn" --include="*.rs"
# C++
grep -rn "std::thread\|std::async\|pthread" --include="*.cpp" --include="*.hpp"
Step 2: Identify Shared Mutable State
For each entry point, trace:
- What variables/state are accessed?
- Are any accessed from multiple concurrent contexts?
- Is the state mutable?
Step 3: Verify Synchronization
For each shared mutable state:
- Is there a lock/mutex/atomic protecting it?
- Is protection held for the entire critical section?
- Are ALL access paths protected, including error paths?
Step 4: Check for Anti-Patterns
Scan for these categories (see language references for specific patterns):
| Category | What to Find |
|---|---|
| Check-Then-Act | if (x) use(x) where x can change between check and use |
| Read-Modify-Write | counter++ or x = x + 1 without atomics |
| Lazy Init | Double-checked locking, memoization races |
| Publication | Object shared before fully constructed |
| Deadlock | Inconsistent lock ordering, lock held across await |
| Collection Mutation | Iterating while modifying, concurrent map access |
| Async Races | Missing await, Promise.all with shared state |
| Resource Lifecycle | Use after close, double close |
| Memory Ordering | Missing barriers (C++), false sharing |
Step 5: Report Findings
Use this format:
## [RC-001] Brief Title
**File:** `path/to/file.ext:line`
**Category:** Check-Then-Act
**Severity:** Critical | High | Medium | Low
**Code:**
[snippet]
**Bug:** [one sentence explanation]
**Scenario:** [how this manifests]
**Fix:**
[corrected code]
Severity Criteria
- Critical: Security bypass, data corruption with financial/legal impact, crashes
- High: Data corruption, deadlocks, payment/transaction races
- Medium: Non-deterministic tests, resource leaks under contention
- Low: Theoretical races, deprecated code, performance issues
Language References
Load the appropriate reference based on codebase languages:
- TypeScript/JavaScript: See references/typescript-javascript.md
- Python: See references/python.md
- Go: See references/go.md
- Rust: See references/rust.md
- C++: See references/cpp.md
Each reference contains language-specific anti-patterns with buggy/fixed code examples.
Quick Detection Commands
# Go: Run race detector
go test -race ./...
# C++: Compile with ThreadSanitizer
clang++ -fsanitize=thread -g source.cpp
# Find non-atomic increments (JS/TS)
grep -rn "++" --include="*.ts" | grep -v "for\|while\|i++"
# Find Python threading without locks
grep -rn "threading.Thread" --include="*.py" -A5 | grep -v Lock
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?