All skills
avdlee avatar

/swift-concurrency

@35095d4

Diagnose Swift Concurrency issues, refactor callback-based code to async/await, and guide Swift 6 migration when working with tasks, actors, @MainActor, Sendable, data races, thread safety, or concurrency-related compiler and linter warnings.

Use this Skill: https://skilld.dev/gh/avdlee/swift-concurrency-agent-skill/swift-concurrency

This session only. Nothing lands on disk.

referencesglossary.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Glossary

Use this when:

  • You need a quick definition of a Swift Concurrency term.
  • You encounter unfamiliar terminology in other reference files.

Skip this file if:

  • You need implementation patterns, not definitions. Use the relevant reference file instead.

Actor isolation

A rule enforced by the compiler: actor-isolated state can only be accessed from the actor's executor. Cross-actor access requires await.

Global actor

A shared isolation domain applied via attributes like @MainActor or a custom @globalActor. Types/functions isolated to the same global actor can interact without crossing isolation.

Default actor isolation

A module/target-level setting that changes the default isolation of declarations. App targets often choose @MainActor as the default to reduce migration noise, but it changes behavior and diagnostics.

Strict concurrency checking

Compiler enforcement levels for Sendable and isolation diagnostics (minimal/targeted/complete). Raising the level typically reveals more issues and can trigger the “concurrency rabbit hole” unless migrated incrementally.

Sendable

A marker protocol that indicates a type is safe to transfer across isolation boundaries. The compiler verifies stored properties and captured values for thread-safety.

@Sendable

An annotation for function types/closures that can be executed concurrently. It tightens capture rules (captured values must be Sendable or safely transferred).

Suspension point

An await site where a task may suspend and later resume. After a suspension point, you must assume other work may have run and (for actors) state may have changed (reentrancy).

Reentrancy (actors)

While an actor is suspended at an await, other tasks can enter the actor and mutate state. Code after await must not assume actor state is unchanged.

nonisolated

Marks a declaration as not isolated to the surrounding actor/global actor. Use only when it truly does not touch isolated mutable state (typically immutable Sendable data).

nonisolated(nonsending) (Swift 6.2+ behavior)

An opt-out to prevent “sending” non-Sendable values across isolation while still allowing an async function to run in the caller’s isolation. Used to reduce Sendable friction when you do not need to hop executors.

@concurrent (Swift 6.2+ behavior)

An attribute used to explicitly opt a nonisolated async function into concurrent execution (i.e., not inheriting the caller’s actor). It is used during migration when enabling NonisolatedNonsendingByDefault. Also valid on Task { @concurrent in ... } to opt the task body out of the enclosing actor's isolation; pick this when the task's synchronous prefix (everything before the first await) does not need the main actor.

@preconcurrency

An annotation used to suppress Sendable-related diagnostics from a module that predates concurrency annotations. It reduces noise but shifts safety responsibility to you.

Region-based isolation / sending

Mechanisms that model ownership transfer so certain non-Sendable values can be moved between regions safely. The sending keyword enforces that a value is no longer used after transfer.

AsyncSequence

A protocol for types that provide asynchronous, sequential iteration over elements. Conforms to the for await loop pattern. Use for streaming data where elements arrive over time.

AsyncStream

A concrete implementation of AsyncSequence that bridges callback-based or delegate-based APIs to async/await. Provides yield() to emit values and finish() to complete the stream.

Continuation

A mechanism to bridge callback-based APIs to async/await. withCheckedContinuation and withCheckedThrowingContinuation provide safe bridging with runtime checks. withUnsafeContinuation variants skip checks for performance-critical code.

Task Local

Task-scoped storage that propagates values through the task hierarchy automatically. Declared with @TaskLocal and accessed via the wrapper's static property. Child tasks inherit parent task locals.

Cooperative thread pool

Swift's threading model where tasks run on a limited pool of threads managed by the runtime. Tasks yield cooperatively at suspension points, allowing other tasks to run. Avoid blocking operations that would starve the pool.

Executor

The scheduling mechanism that determines where and when actor code runs. MainActor uses the main thread executor. Custom actors use the default executor unless a custom executor is specified.

Structured concurrency

A pattern where child tasks have a well-defined relationship to parent tasks. Child tasks must complete before the parent scope exits. Provides automatic cancellation propagation and prevents orphaned tasks. Implemented via async let and TaskGroup.

Isolation domain

A boundary that protects mutable state from concurrent access. Each actor instance defines its own isolation domain. The @MainActor global actor defines a shared isolation domain for UI work. Code must cross isolation boundaries explicitly via await.

Task priority

A hint to the runtime about the relative importance of a task. Priorities include .high, .medium, .low, .userInitiated, .utility, and .background. Higher priority tasks are scheduled before lower priority ones. Priority can escalate when a high-priority task awaits a low-priority one.

Cancellation

A cooperative mechanism to signal that a task should stop. Check Task.isCancelled or call Task.checkCancellation() (throws) in long-running work. Cancellation propagates to child tasks in structured concurrency.

Debounce

Wait for a period of inactivity before emitting a value. Used to reduce API calls for rapid inputs like search fields. Implemented as debounce(for:tolerance:clock:) in AsyncAlgorithms.

Throttle

Emit at most one value per time interval, discarding intermediate values. Used to prevent excessive calls from repeated actions like button taps. Implemented as throttle(for:clock:reducing:) in AsyncAlgorithms.

Merge (AsyncAlgorithms)

Combine multiple asynchronous sequences into one, emitting values as they arrive from any source. Order is interleaved based on emission timing. Stable operator.

CombineLatest (AsyncAlgorithms)

Combine multiple asynchronous sequences, emitting a tuple whenever any source emits a new value. Always uses the latest value from each sequence. Stable operator.

Zip (AsyncAlgorithms)

Combine multiple asynchronous sequences by pairing elements in order. Waits for all sequences to emit before producing a tuple. Stable operator.

AsyncChannel

An AsyncSequence with backpressure sending semantics. Allows multiple producers to send values safely to multiple consumers with flow control. Stable operator.

AsyncThrowingChannel

Like AsyncChannel but can emit errors through the stream. Stable operator.

AsyncTimerSequence

An AsyncSequence that emits a value at regular intervals. Replaces timer-based publishers and manual sleep loops. Stable operator.

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides comprehensive instructions and reference material for diagnosing and fixing Swift Concurrency issues. It includes detailed guidance on Swift 6 migration, actor isolation, and task management. No security risks or malicious patterns were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    1/16 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 35095d4. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago
  • swift
  • concurrency
  • async-await
  • actors
  • sendable
  • main-actor
  • swift-6
  • migration
  • data-races
  • thread-safety

README badge

README badge for avdlee/swift-concurrency-agent-skill

Diagnose and fix Swift Concurrency issues including data races, isolation violations, and Sendable conformance problems. Refactors callback-based code to async/await and guides Swift 6 migration by analyzing project settings, determining isolation boundaries, and applying the smallest safe changes.

Generated from the current SKILL.md.

Does this skill help with Swift 6 migration?
Yes. The skill guides Swift 6 migration by analyzing language mode and strict concurrency settings from Package.swift or .pbxproj, then walking through diagnostics related to tasks, actors, @MainActor, Sendable, and data races.
What project settings does this skill check?
The skill analyzes Swift language mode, strict concurrency level, default isolation, and upcoming features from both SwiftPM (Package.swift) and Xcode (.pbxproj) to determine the correct fix for each diagnostic.
Does this skill refactor callback-based code to async/await?
Yes. The skill helps refactor legacy callback patterns to async/await, and routes to references/migration.md for detailed closure-to-async conversion strategies.
Will this skill recommend @MainActor as a blanket fix?
No. The skill requires justification for @MainActor isolation and avoids recommending it unless the code is truly UI-bound; it also favors structured concurrency over unstructured tasks.
Does this skill handle Core Data concurrency issues?
Yes. The skill addresses NSManagedObject sendability warnings and crossing context/actor boundaries, with routes to references/core-data.md for detailed solutions.

Generated from the current SKILL.md. These answers refresh after source changes.