ios-concurrency-audit
Skill1 starsChanged 16 days agoMITView on GitHub
Audit or fix Swift Concurrency problems in this iOS codebase — actor isolation, MainActor violations, Sendable conformance, task cancellation, single-flight work and data races. Use when a crash or warning involves threading, when state updates from the wrong thread, when something happens twice that should happen once, when adopting stricter concurrency checking, or when asked to review async code.
In this repository37 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ios-accessibility-auditSkill
- ios-api-contract-migrationSkill
- ios-api-endpointSkill
- ios-app-intents-siriSkill
- ios-bug-triageSkill
- ios-build-configurationSkill
- ios-cloudkit-syncSkill
- ios-combine-patternsSkill
- ios-commit-and-prSkill
- ios-commitSkill
- ios-coreml-apple-intelligenceSkill
- ios-deep-linkingSkill
- ios-dependency-assessmentSkill
- ios-design-fixSkill
- ios-feature-moduleSkill
- ios-knowledge-baseSkill
- ios-latest-os-adoptionSkill
- ios-localizationSkill
- ios-offline-writeSkill
- ios-performance-tuningSkill
- ios-port-from-androidSkill
- ios-port-to-androidSkill
- ios-precommitSkill
- ios-privacy-complianceSkill
- ios-push-and-background-tasksSkill
- ios-refactorSkill
- ios-release-prepSkill
- ios-sdk-upgradeSkill
- ios-secure-reviewSkill
- ios-storekit-subscriptionsSkill
- ios-swift6-concurrency-migrationSkill
- ios-swiftdataSkill
- ios-swift-testing-migrationSkill
- ios-swiftui-screenSkill
- ios-unit-testsSkill
- ios-widgetkit-live-activitiesSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 1 is distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
@MainActor: all views and view models. - Very specific: line 21
No Combine, no completion handlers, no DispatchQueue in feature code.
- Very specific: line 26
Every ObservableObject view model is @MainActor.
- Very specific: line 36
Check that "only one at a time" invariants survive interleaving.
- Very specific: line 39
Ask of any new actor method: what happens if this runs twice, concurrently, with the second call arriving mid-await?
- Very specific: line 45
After an await in a long operation, Task.isCancelled is checked before publishing results.
- Very specific: line 47
Every catch checks error.isCancellation and returns silently.
- Very specific: line 51
No unstructured Task { } that outlives the object that started it and then touches its state.
- Very specific: line 55
Prefer async let or a task group over several detached tasks.
- Distinctive: line 60
No reference type shared across actors without either immutability, an actor, or a documented lock.
- Very specific: line 73
Do not use sleeps to create overlap.
- Very specific: line 82
Read actor state with await in assertions, never by reaching into it synchronously.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Audit concurrency
This project uses Swift Concurrency exclusively. Build setting is
SWIFT_STRICT_CONCURRENCY = targeted, so the compiler does not catch everything
— the checks below are the ones a reviewer must do by hand.
The intended model
@MainActor: all views and view models. Published state mutates nowhere else, by construction.actor: anything owning mutable state that several tasks reach —AuthSessionStore,FileCacheStore,FileOutbox.Sendablevalue types cross boundaries.@unchecked Sendableappears only where a type is immutable in practice (LiveAPIClient, repositories) or is a lock-protected test double, and each use carries a comment saying why.- No Combine, no completion handlers, no
DispatchQueuein feature code.
What to check
- MainActor integrity
- Every
ObservableObjectview model is@MainActor. - No
nonisolatedmethod mutates published state. - No
DispatchQueue.main.asyncused to "fix" an isolation error — that hides the problem rather than solving it. (One exception exists inLoginViewfor a delayed notice clear; anything new needs a better reason.)
- Every
- Actor re-entrancy — the subtle one. Every
awaitinside an actor method is a suspension point at which another caller can enter and change state. So:- Re-read state after an
awaitrather than trusting a value captured before it. - Check that "only one at a time" invariants survive interleaving. The pattern
to copy is
AuthSessionStore.performRefresh: store the in-flightTask, have later callers await it, clear it in both success and failure paths. - Ask of any new actor method: what happens if this runs twice, concurrently,
with the second call arriving mid-
await?
- Re-read state after an
- Cancellation
- Work that a view can trigger repeatedly (search, reload, paging) is held in a
Taskhandle and cancelled before being replaced. - After an
awaitin a long operation,Task.isCancelledis checked before publishing results. - Every catch checks
error.isCancellationand returns silently. Task.sleepfailures are treated as cancellation, not as errors to report.
- Work that a view can trigger repeatedly (search, reload, paging) is held in a
- Task lifetime
- No unstructured
Task { }that outlives the object that started it and then touches its state. Capture[weak self]in long-lived tasks. - Fire-and-forget tasks that perform writes are suspicious: who observes the failure?
- Prefer
async letor a task group over several detached tasks.
- No unstructured
- Sendable
- Closures crossing isolation boundaries are
@Sendableand capture onlySendablevalues (seeAuthSessionStore.setStateHandler). - No reference type shared across actors without either immutability, an actor, or a documented lock.
@unchecked Sendablehas a comment justifying it. If you cannot write the justification, the design is wrong.
- Closures crossing isolation boundaries are
- Duplicated work
- Anything expensive and idempotent that several callers can trigger at once
(token refresh, outbox drain, cache warm) needs the single-flight pattern:
an in-flight
Taskstored and shared.SyncCoordinator.drain()andAuthSessionStoreboth do this — copy them.
- Anything expensive and idempotent that several callers can trigger at once
(token refresh, outbox drain, cache warm) needs the single-flight pattern:
an in-flight
Testing concurrency
Do not use sleeps to create overlap. Inject a delay into the double instead
(SpyAuthenticationAPI.setRefreshDelay) and drive concurrent callers with a task
group, then assert on the count:
let count = await api.refreshCount
XCTAssertEqual(count, 1, "Ten concurrent callers must cause exactly one refresh")Read actor state with await in assertions, never by reaching into it
synchronously.
Verification
- No published state mutated off the main actor.
- Every new actor method reasoned about for re-entrancy, in a comment where the answer is non-obvious.
- Repeatable work is cancelled before being replaced.
- Every
@unchecked Sendablejustified in a comment. - Concurrency behaviour has a test that would fail if the invariant broke.
Thread SanitizerandMain Thread Checkerwere run, or say plainly that they were not.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

