# Required context lost through detachment

Rule ID: concurrency.detached-task-context-loss@1.0.0. Availability below refers to source-scan at product 524fa07e.

## V-EXEC-03 — Required context lost through detachment

A detached task can lose the execution context required by an operation it calls. The tutorial asks for a MainActor context inside the detached task.

### Availability

Selected by default in source-scan. Selection does not mean a supported observation exists in your program.

Use the terminal from [Installation](https://docs.swift-analyzer.com/get-started/installation/), with ANALYZER set. Replace `<package>` and `<product>` with your supported package path and product name.

```text
"$ANALYZER" source-scan --package-path <package> --product <product> --allow-build
```

### Example and action

Reproduced as part of the first-analysis package at product 524fa07e on Apple Swift 6.3.3, macOS arm64. The complete package and command are in [First analysis](https://docs.swift-analyzer.com/get-started/first-analysis/).

```swift
func requireMain() { MainActor.assumeIsolated {} }
@MainActor func check() { Task.detached { requireMain() } }
```

The control removes detachment and calls the operation directly from the MainActor function. The finding disappears in this example, but other observations remain unknown and the full report is still degraded.

```swift
func requireMain() { MainActor.assumeIsolated {} }
@MainActor func check() { requireMain() }
```

### Why this check works

The extractor recognizes the MainActor origin, detached-task transition and required MainActor operation, and binds them to admitted source evidence. The context lost through that transition supplies the witness. [Structured concurrency](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0304-structured-concurrency.md) defines the relevant task-context distinction. This implementation claim is limited to the reproduced source form.

### Assumptions and unknown

The current workflow recognizes bounded source forms. An unresolved required context, callback contract, resource domain or thread-affinity fact can remain unknown. A condition with no supported observations is reported as no-observations, not as proof that all uses are valid.

### Evidence and interpretation

Read condition coverage, observation counts and reasons in the actual report. A finding and an unknown observation can coexist. No observations is not a negative proof.

Historical evidence at 4558458d: recovery-required (historical qualification is incomplete and needs further evidence). That evidence has not been requalified for this product revision.

[How we validate checks](https://docs.swift-analyzer.com/concepts/validation/) explains the evidence boundary. [Foundations](https://docs.swift-analyzer.com/concepts/foundations/) separates method assumptions from implementation claims.


---

Language: en
Canonical: https://docs.swift-analyzer.com/catalog/concurrency.detached-task-context-loss/
Product revision: 524fa07e0ae4153c84ac12ae9eb6559df89ec2be
Catalog revision: 4558458d
Documentation digest: 1f17ba58ab08627e0de898f1442067b09e960b48cd5605d6529e9275f8930d68
Channel: pre-prod; maturity: experimental; access: owner-provided checkout.
