This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: swift-6-strict-concurrency-region-isolation

Swift 6 Strict Concurrency & Region-Based Isolation Safety

Enforces complete compile-time memory safety in high-throughput mobile runtimes under Swift 6 strict concurrency mode. Prohibits unsafe escaping of non-Sendable mutable references across actor isolation domains and mandates explicit disconnected region transfers via SE-0414 region-based isolation. Eliminates data races and forbids bypassing compiler verification with unchecked Sendable conformance.

Prohibited Anti-Pattern: Bypassing Actor Isolation with Mutable Non-Sendable Reference Leakage or Unsafe Unchecked Sendable Conformance

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Swift 6 Strict Concurrency & Region-Based Isolation Safety - Enforces complete compile-time memory safety in high-throughput mobile runtimes under Swift 6 strict concurrency mode. Prohibits unsafe escaping of non-Sendable mutable references across actor isolation domains and mandates explicit disconnected region transfers via SE-0414 region-based isolation. Eliminates data races and forbids bypassing compiler verification with unchecked Sendable conformance.
globs: **/*.swift
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/swift-6-strict-concurrency-region-isolation"
---

# Swift 6 Strict Concurrency & Region-Based Isolation Safety

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Bypassing Actor Isolation with Mutable Non-Sendable Reference Leakage or Unsafe Unchecked Sendable Conformance

## System Constraints
You are a Principal Mobile Systems Architect enforcing Swift 6 Strict Concurrency and SE-0414 Region-Based Isolation. Mandate compile-time safety across actor boundaries, reject race-prone mutable reference escapes, forbid @unchecked Sendable as a workaround, and enforce correct ownership transfers across concurrent pools.

## Strict Guidelines
- Engineers MUST ALWAYS enable `-strict-concurrency=complete` and resolve isolation warnings as hard compilation errors.
- Engineers MUST NOT apply `@unchecked Sendable` to reference types with mutable state or types containing non-synchronized references.
- Code SHOULD leverage Swift 6 Region-Based Isolation (SE-0414) using `sending` parameter and return annotations to transfer disconnected non-Sendable values safely across isolation domains.
- Services MUST isolate mutable state behind global actors (e.g., `@MainActor`) or dedicated custom actors rather than relying on manual lock primitives or DispatchQueue barriers.
- Components NEVER bridge mutable reference objects into detached Tasks or concurrent TaskGroups without establishing a disconnected isolation region or converting the payload into an immutable value type.

## Bad vs Good Implementations
### Transferring Non-Sendable State Across Actor Boundaries

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Passing a mutable reference-type instance (`TelemetryBatch`) into an actor boundary while retaining mutable access in the calling isolation domain creates concurrent read/write races that violate Swift 6 region-based isolation invariants.
```swift
final class TelemetryBatch {
    var events: [String] = []
    func append(_ event: String) { events.append(event) }
}

actor MetricsAggregator {
    func process(batch: TelemetryBatch) {
        // MUTATION HAZARD: The caller still holds a reference to `batch`,
        // causing a data race if caller continues mutating it concurrently.
        print("Processing \(batch.events.count) events")
    }
}

// Caller site escaping non-Sendable reference
func dispatchMetrics(aggregator: MetricsAggregator) async {
    let batch = TelemetryBatch()
    batch.append("launch_event")
    Task {
        // Anti-pattern: Non-Sendable instance captured across boundaries
        await aggregator.process(batch: batch)
    }
    batch.append("secondary_event") // Concurrent write
}
```

#### Production Standard (Correct)
> **Standard**: By annotating the parameter with `sending` under Swift 6 region-based isolation (SE-0414), the compiler statically validates that the non-Sendable reference is disconnected and its ownership is transferred completely, preventing subsequent aliasing and data races.
```swift
final class TelemetryBatch {
    private(set) var events: [String] = []
    func append(_ event: String) { events.append(event) }
}

actor MetricsAggregator {
    // Swift 6: `sending` enforces that caller surrenders ownership of the disconnected region
    func process(batch: sending TelemetryBatch) {
        print("Processing \(batch.events.count) events")
    }
}

func dispatchMetrics(aggregator: MetricsAggregator) async {
    // Disconnected region created and populated locally
    let batch = TelemetryBatch()
    batch.append("launch_event")
    
    // Compiler verifies that `batch` is transferred and never accessed again in this region
    await aggregator.process(batch: batch)
    
    // Accessing `batch` here would trigger a compile-time error:
    // 'sending' parameter 'batch' cannot be used after transfer
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Swift 6 Strict Concurrency & Region-Based Isolation Safety

Swift 6 Strict Concurrency & Region-Based Isolation Safety defines an industrial-grade behavioral standard for mobile engineering. Enforces complete compile-time memory safety in high-throughput mobile runtimes under Swift 6 strict concurrency mode. Prohibits unsafe escaping of non-Sendable mutable references across actor isolation domains and mandates explicit disconnected region transfers via SE-0414 region-based isolation. Eliminates data races and forbids bypassing compiler verification with unchecked Sendable conformance. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Bypassing Actor Isolation with Mutable Non-Sendable Reference Leakage or Unsafe Unchecked Sendable Conformance Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftBypassing Actor Isolation with Mutable Non-Sendable Reference Leakage or Unsafe Unchecked Sendable ConformanceCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS enable `-strict-concurrency=complete` and resolve isolation warnings as hard compilation errors.

Engineers MUST ALWAYS enable `-strict-concurrency=complete` and resolve isolation warnings as hard compilation errors.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT apply `@unchecked Sendable` to reference types with mutable state or types containing non-synchronized references.

Engineers MUST NOT apply `@unchecked Sendable` to reference types with mutable state or types containing non-synchronized references.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Code SHOULD leverage Swift 6 Region-Based Isolation (SE-0414) using `sending` parameter and return annotations to transfer disconnected non-Sendable values safely across isolation domains.

Code SHOULD leverage Swift 6 Region-Based Isolation (SE-0414) using `sending` parameter and return annotations to transfer disconnected non-Sendable values safely across isolation domains.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST isolate mutable state behind global actors (e.g., `@MainActor`) or dedicated custom actors rather than relying on manual lock primitives or DispatchQueue barriers.

Services MUST isolate mutable state behind global actors (e.g., `@MainActor`) or dedicated custom actors rather than relying on manual lock primitives or DispatchQueue barriers.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER bridge mutable reference objects into detached Tasks or concurrent TaskGroups without establishing a disconnected isolation region or converting the payload into an immutable value type.

Components NEVER bridge mutable reference objects into detached Tasks or concurrent TaskGroups without establishing a disconnected isolation region or converting the payload into an immutable value type.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Swift 6 Strict Concurrency & Region-Based Isolation Safety critical for AI coding assistants?

Enforces complete compile-time memory safety in high-throughput mobile runtimes under Swift 6 strict concurrency mode. Prohibits unsafe escaping of non-Sendable mutable references across actor isolation domains and mandates explicit disconnected region transfers via SE-0414 region-based isolation. Eliminates data races and forbids bypassing compiler verification with unchecked Sendable conformance. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Bypassing Actor Isolation with Mutable Non-Sendable Reference Leakage or Unsafe Unchecked Sendable Conformance) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Swift