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

Swift 6 Strict Concurrency Region-Based Isolation & Transfer Boundaries

Enforces compile-time region-based isolation (SE-0414) under Swift 6 strict concurrency to safely transfer non-Sendable mutable types across actor boundaries. Prohibits unsafe escape hatches like @unchecked Sendable and eliminates expensive defensive copies by requiring disconnected isolation regions and explicit 'sending' parameter semantics.

Prohibited Anti-Pattern: Bypassing Actor Isolation with @unchecked Sendable or Allocating Redundant Deep Copies

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Swift 6 Strict Concurrency Region-Based Isolation & Transfer Boundaries - Enforces compile-time region-based isolation (SE-0414) under Swift 6 strict concurrency to safely transfer non-Sendable mutable types across actor boundaries. Prohibits unsafe escape hatches like @unchecked Sendable and eliminates expensive defensive copies by requiring disconnected isolation regions and explicit 'sending' parameter semantics.
globs: **/*.swift
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/swift-6-region-based-isolation-boundary"
---

# Swift 6 Strict Concurrency Region-Based Isolation & Transfer Boundaries

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Bypassing Actor Isolation with @unchecked Sendable or Allocating Redundant Deep Copies

## System Constraints
You are a Principal Mobile Architect specializing in Swift 6 strict concurrency, actor isolation boundaries, and region-based isolation (SE-0414). Mandate that non-Sendable instances passed between actor domains form provably disconnected subgraphs at compile-time. Eliminate unnecessary defensive deep copies, reject pseudo-safe @unchecked Sendable escape hatches, and strictly enforce the 'sending' annotation for cross-isolation parameter transfers and returns.

## Strict Guidelines
- Engineers MUST ALWAYS leverage region-based isolation to transfer ownership of non-Sendable mutable references across actor boundaries rather than synthesizing deep clones or defensive serializations.
- Engineers MUST NOT mark mutable reference types with '@unchecked Sendable' to silence Swift 6 compiler isolation boundary diagnostics.
- Functions and initializers that pass or return non-Sendable instances across isolation domains MUST use the 'sending' parameter or return modifier (SE-0414 / SE-0430).
- Code MUST NOT access, capture, or mutate a non-Sendable value in the source scope once it has crossed an isolation boundary or been provided as a 'sending' argument.
- Services that produce mutable domain models asynchronously MUST structure factory pipelines so the returned reference begins in a fresh, disconnected isolation region before bridging to another actor.

## Bad vs Good Implementations
### Cross-Actor Transfer of Non-Sendable Mutable State

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Applying '@unchecked Sendable' bypasses compile-time data-race safety. The local scope continues mutating 'payload' after sending it across the actor boundary, resulting in concurrent data races without compiler diagnostics.
```swift
import Foundation

// ANTI-PATTERN: Forcing @unchecked Sendable to bypass compiler checks
// or performing defensive copies to pass data across actors.
final class MutablePayload: @unchecked Sendable {
    var metadata: [String: String]
    var buffer: [UInt8]

    init(metadata: [String: String], buffer: [UInt8]) {
        self.metadata = metadata
        self.buffer = buffer
    }
}

actor DataPipeline {
    private var cache: [String: MutablePayload] = [:]

    func ingest(_ payload: MutablePayload, id: String) {
        // Concurrently mutated state across domains causes undetected data races
        cache[id] = payload
    }
}

func processAndSubmit(pipeline: DataPipeline) async {
    let payload = MutablePayload(metadata: ["origin": "sensor"], buffer: [0x1, 0x2])
    await pipeline.ingest(payload, id: "item-1")
    // Race condition: Calling context mutates payload after passing across actor boundary
    payload.metadata["status"] = "mutated_locally"
}
```

#### Production Standard (Correct)
> **Standard**: The non-Sendable type preserves natural semantics without @unchecked Sendable or deep copies. Swift 6 region-based isolation tracks 'payload' as a disconnected region, safely passing it via the 'sending' parameter and statically disallowing subsequent access in the caller.
```swift
import Foundation

// PRODUCTION FIX: Leave class non-Sendable and rely on Region-Based Isolation (SE-0414)
// using the 'sending' parameter attribute to verify detachment.
final class MutablePayload {
    var metadata: [String: String]
    var buffer: [UInt8]

    init(metadata: [String: String], buffer: [UInt8]) {
        self.metadata = metadata
        self.buffer = buffer
    }
}

actor DataPipeline {
    private var cache: [String: MutablePayload] = [:]

    // 'sending' explicitly marks transfer of the disconnected region into this actor
    func ingest(_ payload: sending MutablePayload, id: String) {
        cache[id] = payload
    }
}

func processAndSubmit(pipeline: DataPipeline) async {
    // payload resides in a fresh, disconnected region
    let payload = MutablePayload(metadata: ["origin": "sensor"], buffer: [0x1, 0x2])
    
    // Ownership transferred across isolation domain
    await pipeline.ingest(payload, id: "item-1")
    
    // Compiler prevents any subsequent access to `payload` here:
    // error: sending 'payload' risks causing data races; 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 & Transfer Boundaries

Swift 6 Strict Concurrency Region-Based Isolation & Transfer Boundaries defines an industrial-grade behavioral standard for mobile engineering. Enforces compile-time region-based isolation (SE-0414) under Swift 6 strict concurrency to safely transfer non-Sendable mutable types across actor boundaries. Prohibits unsafe escape hatches like @unchecked Sendable and eliminates expensive defensive copies by requiring disconnected isolation regions and explicit 'sending' parameter semantics. 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 @unchecked Sendable or Allocating Redundant Deep Copies 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 @unchecked Sendable or Allocating Redundant Deep CopiesCritical
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 leverage region-based isolation to transfer ownership of non-Sendable mutable references across actor boundaries rather than synthesizing deep clones or defensive serializations.

Engineers MUST ALWAYS leverage region-based isolation to transfer ownership of non-Sendable mutable references across actor boundaries rather than synthesizing deep clones or defensive serializations.

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 mark mutable reference types with '@unchecked Sendable' to silence Swift 6 compiler isolation boundary diagnostics.

Engineers MUST NOT mark mutable reference types with '@unchecked Sendable' to silence Swift 6 compiler isolation boundary diagnostics.

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

Functions and initializers that pass or return non-Sendable instances across isolation domains MUST use the 'sending' parameter or return modifier (SE-0414 / SE-0430).

Functions and initializers that pass or return non-Sendable instances across isolation domains MUST use the 'sending' parameter or return modifier (SE-0414 / SE-0430).

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

Code MUST NOT access, capture, or mutate a non-Sendable value in the source scope once it has crossed an isolation boundary or been provided as a 'sending' argument.

Code MUST NOT access, capture, or mutate a non-Sendable value in the source scope once it has crossed an isolation boundary or been provided as a 'sending' argument.

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

Services that produce mutable domain models asynchronously MUST structure factory pipelines so the returned reference begins in a fresh, disconnected isolation region before bridging to another actor.

Services that produce mutable domain models asynchronously MUST structure factory pipelines so the returned reference begins in a fresh, disconnected isolation region before bridging to another actor.

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 & Transfer Boundaries critical for AI coding assistants?

Enforces compile-time region-based isolation (SE-0414) under Swift 6 strict concurrency to safely transfer non-Sendable mutable types across actor boundaries. Prohibits unsafe escape hatches like @unchecked Sendable and eliminates expensive defensive copies by requiring disconnected isolation regions and explicit 'sending' parameter semantics. 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 @unchecked Sendable or Allocating Redundant Deep Copies) 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