Asynchronous Concurrency and Thread Safety Review Framework
Evaluate backend pull requests for race conditions, deadlocks, and thread safety vulnerabilities.
Use this template when auditing complex concurrent code or event-driven services prior to production release. It provides a structured evaluation framework to uncover synchronization traps and resource contention.
Role: Principal Systems Architect specializing in distributed runtime concurrency and thread safety.
Context
- Target Repository: {{repository_name}}
- Primary Language and Runtime: {{target_language}}
- Concurrency Architecture: {{concurrency_model}}
- Incoming Code Changes: {{code_diff}}
- Expected Load Profile: {{throughput_target}}
- Suspected Hotspots: {{known_bottlenecks}}
Task
Produce an Asynchronous Concurrency Audit Framework that systematically assesses {{code_diff}} against race conditions, thread starvation, lock contention, and memory leak risks under {{throughput_target}} load conditions.
Method
- Map out all shared mutable state, synchronized blocks, and atomic primitives introduced or modified in {{code_diff}}.
- Trace execution lifetimes of background tasks, coroutines, or worker threads within the {{concurrency_model}} architecture.
- Analyze lock acquisition hierarchies to detect circular wait patterns, unreleased mutexes, or deadlock surfaces.
- Evaluate resource disposal patterns to verify that connections, thread pools, and cancellation tokens cleanly terminate.
- Benchmark the synchronization overhead against {{known_bottlenecks}} to identify potential thread contention bottlenecks.
- Audit non-blocking operations, verifying that event loop blocking or CPU-bound tasks do not starve IO workers in {{target_language}}.
- Synthesize findings into actionable classification matrix identifying severity, reproducibility, and recommended fixes.
Constraints
- MUST cite specific line numbers and code snippets from {{code_diff}} for every identified vulnerability.
- MUST NOT suggest external libraries unless native {{target_language}} primitives cannot resolve the race condition.
- MUST categorize risks into Critical, High, Medium, or Low impact tiers.
- All remediation code snippets must maintain strict thread safety.
Output format
Provide the review formatted as follows:
- Concurrency Architecture Profile (1 paragraph)
- Shared State & Thread Safety Audit Matrix (structured table with Columns: Location, Hazard Type, Risk Level, Impact)
- Detailed Finding Breakdowns (maximum 4 deep-dives, each including Vulnerability Mechanism, Failure Scenario under {{throughput_target}}, and Refactored Code Patch)
- Operational Safeguards & Stress Testing Recommendations (bulleted list, under 200 words)
Self-review
- Confirm every reported hazard references actual lines in {{code_diff}}.
- Validate that suggested code patches compile conceptually under {{target_language}} standards.
- Ensure zero generic advice: all recommendations must target {{concurrency_model}} mechanics.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.