{"schemaVersion":"2.0.0","locale":"en","title":"Required context lost through detachment","description":"Rule ID: concurrency.detached-task-context-loss@1.0.0. Availability below refers to source-scan at product 524fa07e.","htmlUrl":"https://docs.swift-analyzer.com/catalog/concurrency.detached-task-context-loss/","markdownUrl":"https://docs.swift-analyzer.com/catalog/concurrency.detached-task-context-loss/index.md","productRevision":"524fa07e0ae4153c84ac12ae9eb6559df89ec2be","catalogRevision":"4558458d","docsRevision":"1f17ba58ab08627e0de898f1442067b09e960b48cd5605d6529e9275f8930d68","channel":"pre-prod","maturity":"experimental","access":"owner-provided-checkout","markdown":"# Required context lost through detachment\n\nRule ID: concurrency.detached-task-context-loss@1.0.0. Availability below refers to source-scan at product 524fa07e.\n\n## V-EXEC-03 — Required context lost through detachment\n\nA detached task can lose the execution context required by an operation it calls. The tutorial asks for a MainActor context inside the detached task.\n\n### Availability\n\nSelected by default in source-scan. Selection does not mean a supported observation exists in your program.\n\nUse 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.\n\n```text\n\"$ANALYZER\" source-scan --package-path <package> --product <product> --allow-build\n```\n\n### Example and action\n\nReproduced 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/).\n\n```swift\nfunc requireMain() { MainActor.assumeIsolated {} }\n@MainActor func check() { Task.detached { requireMain() } }\n```\n\nThe 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.\n\n```swift\nfunc requireMain() { MainActor.assumeIsolated {} }\n@MainActor func check() { requireMain() }\n```\n\n### Why this check works\n\nThe 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.\n\n### Assumptions and unknown\n\nThe 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.\n\n### Evidence and interpretation\n\nRead 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.\n\nHistorical evidence at 4558458d: recovery-required (historical qualification is incomplete and needs further evidence). That evidence has not been requalified for this product revision.\n\n[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.\n","anchors":["required-context-lost-through-detachment","V-EXEC-03","availability","example-and-action","why-this-check-works","assumptions-and-unknown","evidence-and-interpretation"]}
