Swift Concurrency Crash and Thread Safety Audit
Investigate complex Swift concurrency bugs, race conditions, and actor isolation crashes into a structured technical report.
Use this template when troubleshooting persistent EXC_BAD_ACCESS errors, actor reentrancy anomalies, or thread sanitizer failures in iOS apps. It guides the investigation through root-cause analysis to architectural remediation.
Role: Senior iOS Concurrency Specialist and Runtime Systems Debugger
Context
- Target Application: {{app_name}}
- Swift Language Version: {{swift_version}}
- Concurrency Architecture: {{concurrency_model}}
- Faulting Subsystem: {{affected_subsystem}}
- Crash Stack Trace or Log: {{crash_stack_trace}}
- Reproduction Frequency and Environment: {{reproduction_rate}}
Task
Produce an exhaustive technical diagnostic report that dissects the concurrency failure in {{app_name}}, identifies the exact race condition or actor violation, and provides concrete, thread-safe refactoring solutions.
Method
- Analyze the stack trace provided in {{crash_stack_trace}} alongside {{concurrency_model}} to identify thread transitions, lock contentions, or unsafe memory dereferences.
- Trace data flow across isolation boundaries within {{affected_subsystem}} to uncover non-Sendable type leaks.
- Evaluate actor reentrancy risks and potential deadlocks caused by unstructured Task hierarchies in {{swift_version}}.
- Reconstruct the failure timeline using {{reproduction_rate}} to isolate critical timing windows.
- Design an immutable or actor-isolated architectural fix that preserves UI responsiveness on the main dispatch queue.
- Formulate precise unit and Thread Sanitizer (TSan) test scenarios to prevent regression.
- Provide refactored Swift code samples demonstrating before-and-after thread safety guarantees.
Constraints
- MUST cite specific Swift concurrency rules and compiler guarantees relevant to {{swift_version}}.
- MUST NOT recommend deprecated GCD workarounds (such as
DispatchQueue.syncon main thread) to resolve actor issues. - Solutions MUST preserve UI responsiveness and adhere to strict concurrency checking.
- Refactored code examples must be compile-ready without placeholder symbols.
Output format
Generate a structured engineering report containing:
- Executive Incident Summary (max 150 words)
- Root Cause & Memory Timeline Analysis
- Concurrency Safety Breakdown (Isolation, Sendable, & Reentrancy)
- Architectural Remediation (with Before/After Code Snippets)
- Verification & TSan Test Plan
Self-review
- Confirm every variable in {{app_name}}, {{swift_version}}, and {{crash_stack_trace}} is addressed.
- Verify that proposed code eliminates data races without introducing deadlocks.
- Check that the report strictly separates diagnostic findings from preventative recommendations.
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.