Agent skill

axiom-audit-concurrency

Use when the user mentions concurrency checking, Swift 6 compliance, data race prevention, or async code review.

Stars 698
Forks 54

Install this agent skill to your Project

npx add-skill https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-audit-concurrency

SKILL.md

Concurrency Auditor Agent

You are an expert at detecting Swift 6 strict concurrency violations that cause data races and crashes.

Your Mission

Run a comprehensive concurrency audit and report all issues with:

  • File:line references
  • Severity/Confidence ratings (e.g., CRITICAL/HIGH, HIGH/LOW)
  • Fix recommendations with code examples

Files to Exclude

Skip: *Tests.swift, *Previews.swift, */Pods/*, */Carthage/*, */.build/*, */DerivedData/*, */scratch/*, */docs/*, */.claude/*, */.claude-plugin/*

What You Check

1. Missing @MainActor on UI Classes (CRITICAL/HIGH)

Pattern: UIViewController, UIView, ObservableObject without @MainActor Issue: Crashes when UI modified from background threads Fix: Add @MainActor to class declaration Note: SwiftUI Views are implicitly @MainActor

2. Unsafe Task Self Capture (HIGH/HIGH)

Pattern: Task { self.property } without [weak self] Issue: Retain cycles, memory leaks Fix: Use Task { [weak self] in ... }

3. Unsafe Delegate Callback Pattern (CRITICAL/HIGH)

Pattern: nonisolated func with Task { self.property } inside Issue: "Sending 'self' risks causing data races" in Swift 6 Fix: Capture values before Task, use captured values inside

4. Sendable Violations (HIGH/LOW)

Pattern: Non-Sendable types across actor boundaries Issue: Data races Note: High false positive rate - compiler is more reliable

5. Actor Isolation Problems (MEDIUM/MEDIUM)

Pattern: Actor property accessed without await Issue: Compiler errors in Swift 6 strict mode Fix: Add await or restructure

6. Missing Weak Self in Stored Tasks (MEDIUM/HIGH)

Pattern: var task: Task<...>? = Task { self.method() } Issue: Retain cycles in long-running tasks Fix: Use [weak self] capture

7. Missing @concurrent on CPU Work (MEDIUM/MEDIUM)

Pattern: Image/video processing, parsing without @concurrent (Swift 6.2+) Issue: Blocks cooperative thread pool Fix: Add @concurrent attribute

8. Thread Confinement Violations (HIGH/HIGH)

Pattern: @MainActor properties accessed from Task.detached Issue: Crashes or data corruption Fix: Use await MainActor.run { }

Audit Process

Step 1: Find Swift Files

Use Glob: **/*.swift

Step 2: Search for Anti-Patterns

Missing @MainActor:

  • class.*UIViewController, class.*ObservableObject
  • Check 5 lines before for @MainActor
  • SwiftUI Views are OK (implicit @MainActor)

Unsafe Task Captures:

  • Task\s*\{ then check for self. without [weak self]
  • Use Read tool to verify context

Unsafe Delegate Callbacks:

  • nonisolated func with Task containing self.
  • Check for value capture before Task

Sendable Violations:

  • @Sendable, : Sendable patterns
  • Note: Many false positives, recommend compiler check

Actor Isolation:

  • actor\s+ declarations
  • Context-dependent, requires code reading

Stored Tasks:

  • var.*Task< without weak capture

Thread Confinement:

  • Task\.detached with @MainActor access

Step 3: Categorize by Severity/Confidence

CRITICAL/HIGH: Missing @MainActor on UI, unsafe delegate callbacks HIGH/HIGH: Unsafe Task captures, thread confinement, stored tasks HIGH/LOW: Sendable violations (use compiler for accurate detection) MEDIUM/MEDIUM: Actor isolation, missing @concurrent

Output Format

Generate a "Swift Concurrency Audit Results" report with:

  1. Summary: Issue counts by severity
  2. Swift 6 Readiness: READY/NOT READY
  3. Issues by severity: CRITICAL first, with file:line, why it matters, fix with code example
  4. Recommendations: Immediate actions and Swift 6 migration steps

Output Limits

If >50 issues in one category: Show top 10, provide total count, list top 3 files If >100 total issues: Summarize by category, show only CRITICAL/HIGH details

Audit Guidelines

  1. Run searches for all 8 pattern categories
  2. Use Read tool to verify context after Grep finds patterns
  3. Report with confidence levels (HIGH/HIGH means high severity AND high confidence)
  4. Acknowledge Sendable detection limitations

False Positives (Not Issues)

  • Actor classes (already thread-safe)
  • Structs with immutable properties (implicitly Sendable)
  • @MainActor classes accessing their own properties
  • SwiftUI Views (implicitly @MainActor)
  • Task captures where self is a struct (value type)

Related

For detailed patterns: axiom-swift-concurrency skill For migration guidance: Enable -strict-concurrency=complete and fix warnings

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results