# Different behaviour on adding explicit actor isolation to \`group.addTask\`

**URL:** <https://forums.swift.org/t/different-behaviour-on-adding-explicit-actor-isolation-to-group-addtask/83822>\
**Category:** Using Swift\
**Tags:** concurrency, asyncawait, task, actors, taskgroup\
**Created:** [December 23, 2025, 10:39am UTC](https://forums.swift.org/t/different-behaviour-on-adding-explicit-actor-isolation-to-group-addtask/83822 "2025-12-23T10:39:02Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [December 23, 2025, 12:50pm UTC](https://forums.swift.org/t/different-behaviour-on-adding-explicit-actor-isolation-to-group-addtask/83822/3 "2025-12-23T12:50:26Z")

</div>

> [@soumyamahunt](#):
>
> From what I understand the closure accepted by `group.addTask` is marked with `@isolated(any)` which makes it to inherit actor context from parent.

this is, i think, a fairly common misconception, but that is not what `@isolated(any)` does. the best discussion of this i've seen is [here](https://forums.swift.org/t/distinction-between-isolated-any-and-inheritactorcontext/75730/2), and to quote a relevant bit:

> [@Distinction between \`@isolated(any)\` and \`@\_inheritActorContext\`](https://forums.swift.org/t/distinction-between-isolated-any-and-inheritactorcontext/75730/2):
>
> `@isolated(any)` allows you to recover the isolation of a function value as an `(any Actor)?` value. It has no impact on the inferred isolation of a closure whose type includes `@isolated(any)`, and that's where I think people get confused.

without the explicit `@SomeActor` in the signature of the closures passed to `group.addTask`, those closures are not actor-isolated, so they begin execution on the global concurrent executor before switching to the custom executor for the actor-instance (hence the arbitrarily-ordered results).

as touched on [here](https://forums.swift.org/t/distinction-between-isolated-any-and-inheritactorcontext/75730/4) and [here](https://forums.swift.org/t/distinction-between-isolated-any-and-inheritactorcontext/75730/7) in that same thread, the intent of the `taskGroup.addTask` API specifically is to allow you to introduce concurrency between the parent and child tasks, so having those closures inferred to be isolated to their parent context by default would undermine the primary use case of the API.

one other thing that stood out to me in the example, which i imagine could also cause confusion, is that the `SomeActor` type is being used both as a global actor, and distinct instances are being created and used independently. in this construction, the `shared` instance and other instances do not share the same executor (each instance creates its own), so code running on one actor instance will not execute exclusively with code running on another (i think). additionally, the closure in code like this:

```swift
group.addTask {
    await instance.log(external: index)
}

```

is not isolated to the actor '`instance`'. specifying that a closure be isolated to a specific actor instance is a feature that [doesn't yet exist](https://forums.swift.org/t/closure-isolation-control/70378) in the language.

---

_[View the full topic](https://forums.swift.org/t/different-behaviour-on-adding-explicit-actor-isolation-to-group-addtask/83822)._
