You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Swift Concurrency build issue in AVSampleBufferVideoRenderer #313
When updating to 6.7.0, the following errors occur: compilation/AetherEngine/Sources/AetherEngine/Renderer/SampleBufferRenderer.swift:106:42 Non-Sendable type 'AVSampleBufferVideoRenderer' of property 'sampleBufferRenderer' cannot exit main actor-isolated context
Steps to reproduce
Update SDK to 6.7.0
Compile the project
AetherEngine version or commit SHA
6.7.0
Host app
Custom / my own integration
Platform
macOS
OS version
macOS 27 beta4
Device / chip
MacBook Pro M2
Playback path
Native AVPlayer
Source media (for playback bugs)
No response
Error codes / log lines
compilation/AetherEngine/Sources/AetherEngine/Renderer/SampleBufferRenderer.swift:106:42 Non-Sendable type 'AVSampleBufferVideoRenderer' of property 'sampleBufferRenderer' cannot exit main actor-isolated context
Anything else
I created a PR without modifying any existing logic, but marked the error method as @mainactor. #312
Merged as c436aa6, and thanks for both the report and the patch.
The annotation is the right call rather than a build workaround: every caller of loadRenderMetrics() is already main-actor isolated (SoftwarePlaybackHost is a @MainActor class, and the telemetry sampler reads it from a @MainActor path), so it costs no hop and nothing changes at runtime. What it fixes is the crossing. The read of displayLayer.sampleBufferRenderer and the suspension on that renderer's async accessor now sit in one isolation domain, so the non-Sendable renderer never has to leave the main actor at the await.
I could not reproduce the error here (Xcode 26.6, macOS 26.5 SDK), with or without NonisolatedNonsendingByDefault, so I rebuilt the shape in isolation to check the diagnosis rather than guess at it. It reproduces with your exact error text as soon as the layer access is main-actor isolated, which points at the macOS 27 SDK having moved AVSampleBufferDisplayLayer (or CALayer under it) onto the main actor.
If that is what happened, this one line is probably not the end of it. SampleBufferRenderer also touches displayLayer synchronously from the decode thread (queueTarget, status, error, the flush path), and AudioOutput adds and removes the renderer on the synchronizer, all from nonisolated contexts. Those should be failing as well.
Could you paste the full error list from the beta build, plus the Xcode version? If this really was the only error, the SDK change is narrower than I am assuming, and either answer decides how much more of the renderer has to move. Leaving this open until the engine builds clean on the 27 beta on your side.
Follow-up, and a correction to what I merged above: the annotation on its own broke the build at the other end of the toolchain range. CI here runs Xcode 16 on macOS 15, where the async videoPerformanceMetrics imports as nonisolated, so once the function sat on the main actor the non-Sendable renderer could no longer be handed to it. All three jobs failed on the same line your patch fixed. One line, opposite verdicts:
macOS 27 SDK: the layer is main-actor isolated, so sampleBufferRenderer must not be read from any other domain.
Xcode 16 / macOS 15 SDK: the async accessor is nonisolated, so that renderer must not be passed to it from the main actor.
8989631 keeps the @MainActor and replaces the await on the async accessor with loadVideoPerformanceMetrics(completionHandler:) inside withCheckedContinuation. The completion form starts synchronously in the caller's isolation and suspends without moving the renderer, so both constraints hold at once. CI is green again, and the behaviour is unchanged: same values, same call sites, no hop.
Your patch is what found this, and the attribution stays on the merge commit. The full error list from the beta build would still help, for the reason in my previous comment.
Thanks for the detailed breakdown and the clever fix with withCheckedContinuation!
To answer your question regarding the beta build:
SDK Annotation Confirmation: I checked the headers/API declarations in macOS 27 / iOS 27 beta 4, and AVSampleBufferDisplayLayer is indeed annotated with @MainActor.
Build Status: After marking loadRenderMetrics with @MainActor (and incorporating your 8989631b fix), the entire framework compiles completely clean on iOS 27 / macOS 27 beta 4. There are no other build errors or warnings anywhere in SampleBufferRenderer or across the engine.
Thanks again for resolving the CI compatibility issue so quickly!
Thanks for checking the headers and for going back to the beta build. That answers the question I had, and the release side is done: c436aa6a plus 8989631b shipped in 6.12.1, green on the Xcode 16 / macOS 15 CI, on 26.6 here, and on your beta 4.
One detail does not add up though, and it is worth a minute because it decides how much of the renderer has to move at GM.
I rebuilt the isolation shapes locally as typecheck-only models (Swift 6.3, swiftc -typecheck -swift-version 6), since I still have no 27 SDK here:
Modelling sampleBufferRenderer as main actor isolated, either the property alone or the whole layer, reproduces your diagnostic word for word, down to the "of property 'sampleBufferRenderer'" phrasing. So that part of your reading looks right.
In that same shape, the other reads of that property in the same file fail as well, and harder. In 6.7.0 those are line 118 (queueTarget), 130 (the status gate), 137 (the error gate) and 258 (the flush path). All four read displayLayer.sampleBufferRenderer from a synchronous nonisolated context, which is "main actor-isolated property 'sampleBufferRenderer' can not be referenced from a nonisolated context". Nothing downgrades that one. I checked @preconcurrency import specifically: it turns the async region error into a warning and leaves the four synchronous ones as errors, so it is the wrong way round to explain a build with a single error.
Compiling the same shape with -default-isolation MainActor does clear the synchronous sites, but then the remaining error reads "cannot exit main actor-isolated context in call to nonisolated property", which is not the text you got either.
So a compile that reports exactly one error on line 106 is not the compile I would expect from a main actor AVSampleBufferDisplayLayer. Either the annotation in beta 4 is narrower or availability gated in a way the header does not show at a glance, or that target is built with flags that make the four synchronous sites legal.
If it is cheap on your side: the raw build log of an unmodified 6.7.0 against the beta, or just the Swift flags of that target, would settle it. If it is not cheap, do not bother. Either way nothing blocks you today, and if a later beta starts failing on those four lines, that is the signal that the layer really did move wholesale and the queue gates follow it onto the main actor. Leaving this open until then.
Thanks again for the report and the patch. The attribution stays on the merge commit.
So this is not only sampleBufferRenderer; the whole layer is now main actor isolated in the latest SDK.
I realized my previous test was slightly different from yours. I was not compiling AetherEngine directly; I was only consuming it as a dependency in my app. Xcode hides warnings from dependency builds by default, so I did not see the internal concurrency diagnostics from AetherEngine itself.
I just built AetherEngine directly with Xcode 27 beta 4 and confirmed some of the warnings you mentioned:
Main actor-isolated property 'sampleBufferRenderer' can not be referenced from a nonisolated context
So your analysis was right: this SDK change has a larger impact than we initially thought.
However, at least with Xcode 27 beta 4, these are currently warnings in my build and not errors that block compilation. The existing fix still resolves the videoPerformanceMetrics issue, but the other renderer access points will likely need to be addressed if Apple makes these diagnostics stricter in future SDKs.
Thanks, the log answered it. The short version: my "those four sites must break harder" reasoning was right about the isolation and wrong about the severity, and the reason is that I had modelled the wrong thing.
Why exactly one error. I built the earlier model in pure Swift. The annotation actually arrives through an ObjC import, and that carries preconcurrency semantics. Rebuilt as a ~20 line ObjC module (__attribute__((swift_attr("@MainActor"))) on the class, non-Sendable object property) plus a Swift file, swiftc -typecheck -swift-version 6, Swift 6.3.3:
synchronous read, mutation and method call against the main-actor class: warnings, in Swift 6 mode, word for word yours, down to the [#ActorIsolatedCall] group tag.
the 6.7.0 shape, a nonisolated async function pulling sampleBufferRenderer out across an await: error, non-Sendable type 'X' of property 'sampleBufferRenderer' cannot exit main actor-isolated context.
So isolation violations against imported declarations are downgraded; the region rule that governs a non-Sendable value leaving the actor is not. One error on line 106 plus a pile of warnings is exactly the build I should have predicted.
A correction to my earlier comment while I am here: I wrote that @preconcurrency import was the wrong way round because it would leave the synchronous sites hard. That was true of the pure Swift model, not of yours, and your log shows the compiler suggesting it. It is still not the tool I want, it silences the Sendable rule wholesale rather than the one crossing.
What the log settles that I could not have guessed. The hot path is already clean. queueTarget is typed any AVQueuedSampleBufferRendering, and that protocol did not move to the main actor: the readiness gate through it (SampleBufferRenderer.swift:165), the enqueue path (:342) and the diagnostic read (:368) produce no diagnostic at all in your build. Enqueue and back-pressure, the two things that run per frame on the decode thread, need nothing. That was the open question, and it turns out the answer is "almost none of the renderer has to move".
What warns is the acquisition and the layer-only API: four reads of .sampleBufferRenderer (:158, :170, :177, :300, plus AudioOutput.swift:29 and :43), status/error and flushAndRemoveImage()/flush() on the pre-18 branch (:172, :179, :303, :305), and two configuration writes in the layer factory (:184, :188). Twelve sites, all compile time, none per frame.
Not patching them now. The obvious fix, caching the renderer once, is the wrong shape here: displayLayer is a var and gets replaced when HDR output changes, so a stored renderer becomes a second source of truth the next layer swap can forget. What holds is either a main-actor factory that produces the layer and its queue target together, or raising the platform floor to tvOS 18 / iOS 18 / macOS 15 and deleting the legacy branch, which is a major. Neither is worth doing against a beta SDK that can still move before GM, for diagnostics that cost nothing today. All of it is written down in #351, including the trigger: a beta or GM where any of the twelve flips to an error. If you hit that first, a note there is plenty.
One more thing your log was good for. It also caught something unrelated to the SDK: AudioTapController had its [weak self] on the inner Task while the enclosing onTermination closure captured self strongly anyway, so the controller's own continuation retained the controller back. Not a leak in the shipped paths, but the annotation promised something the code did not do. Fixed in #350.
Closing this one: the build failure you reported is fixed and released in 6.12.1, and the remainder is tracked in #351. Thanks for the report, the patch, and for going back to the beta twice to settle it.
Activity
fix(render): isolate loadRenderMetrics to the main actor (#312)
docs(render): record why the metrics read is main-actor isolated (#313 …
superuser404notfound commentedon Aug 7, 2026
Merged as c436aa6, and thanks for both the report and the patch.
The annotation is the right call rather than a build workaround: every caller of
loadRenderMetrics()is already main-actor isolated (SoftwarePlaybackHostis a@MainActorclass, and the telemetry sampler reads it from a@MainActorpath), so it costs no hop and nothing changes at runtime. What it fixes is the crossing. The read ofdisplayLayer.sampleBufferRendererand the suspension on that renderer's async accessor now sit in one isolation domain, so the non-Sendable renderer never has to leave the main actor at theawait.I could not reproduce the error here (Xcode 26.6, macOS 26.5 SDK), with or without
NonisolatedNonsendingByDefault, so I rebuilt the shape in isolation to check the diagnosis rather than guess at it. It reproduces with your exact error text as soon as the layer access is main-actor isolated, which points at the macOS 27 SDK having movedAVSampleBufferDisplayLayer(orCALayerunder it) onto the main actor.If that is what happened, this one line is probably not the end of it.
SampleBufferRendereralso touchesdisplayLayersynchronously from the decode thread (queueTarget,status,error, the flush path), andAudioOutputadds and removes the renderer on the synchronizer, all from nonisolated contexts. Those should be failing as well.Could you paste the full error list from the beta build, plus the Xcode version? If this really was the only error, the SDK change is narrower than I am assuming, and either answer decides how much more of the renderer has to move. Leaving this open until the engine builds clean on the 27 beta on your side.
fix(render): read the video metrics without moving the renderer off t…
superuser404notfound commentedon Aug 7, 2026
Follow-up, and a correction to what I merged above: the annotation on its own broke the build at the other end of the toolchain range. CI here runs Xcode 16 on macOS 15, where the async
videoPerformanceMetricsimports asnonisolated, so once the function sat on the main actor the non-Sendable renderer could no longer be handed to it. All three jobs failed on the same line your patch fixed. One line, opposite verdicts:sampleBufferRenderermust not be read from any other domain.8989631 keeps the
@MainActorand replaces theawaiton the async accessor withloadVideoPerformanceMetrics(completionHandler:)insidewithCheckedContinuation. The completion form starts synchronously in the caller's isolation and suspends without moving the renderer, so both constraints hold at once. CI is green again, and the behaviour is unchanged: same values, same call sites, no hop.Your patch is what found this, and the attribution stays on the merge commit. The full error list from the beta build would still help, for the reason in my previous comment.
jihongboo commentedon Aug 7, 2026
Thanks for the detailed breakdown and the clever fix with
withCheckedContinuation!To answer your question regarding the beta build:
AVSampleBufferDisplayLayeris indeed annotated with@MainActor.loadRenderMetricswith@MainActor(and incorporating your8989631bfix), the entire framework compiles completely clean on iOS 27 / macOS 27 beta 4. There are no other build errors or warnings anywhere inSampleBufferRendereror across the engine.Thanks again for resolving the CI compatibility issue so quickly!
superuser404notfound commentedon Aug 7, 2026
Thanks for checking the headers and for going back to the beta build. That answers the question I had, and the release side is done:
c436aa6aplus8989631bshipped in 6.12.1, green on the Xcode 16 / macOS 15 CI, on 26.6 here, and on your beta 4.One detail does not add up though, and it is worth a minute because it decides how much of the renderer has to move at GM.
I rebuilt the isolation shapes locally as typecheck-only models (Swift 6.3,
swiftc -typecheck -swift-version 6), since I still have no 27 SDK here:sampleBufferRendereras main actor isolated, either the property alone or the whole layer, reproduces your diagnostic word for word, down to the "of property 'sampleBufferRenderer'" phrasing. So that part of your reading looks right.queueTarget), 130 (the status gate), 137 (the error gate) and 258 (the flush path). All four readdisplayLayer.sampleBufferRendererfrom a synchronous nonisolated context, which is "main actor-isolated property 'sampleBufferRenderer' can not be referenced from a nonisolated context". Nothing downgrades that one. I checked@preconcurrency importspecifically: it turns the async region error into a warning and leaves the four synchronous ones as errors, so it is the wrong way round to explain a build with a single error.-default-isolation MainActordoes clear the synchronous sites, but then the remaining error reads "cannot exit main actor-isolated context in call to nonisolated property", which is not the text you got either.So a compile that reports exactly one error on line 106 is not the compile I would expect from a main actor
AVSampleBufferDisplayLayer. Either the annotation in beta 4 is narrower or availability gated in a way the header does not show at a glance, or that target is built with flags that make the four synchronous sites legal.If it is cheap on your side: the raw build log of an unmodified 6.7.0 against the beta, or just the Swift flags of that target, would settle it. If it is not cheap, do not bother. Either way nothing blocks you today, and if a later beta starts failing on those four lines, that is the signal that the layer really did move wholesale and the queue gates follow it onto the main actor. Leaving this open until then.
Thanks again for the report and the patch. The attribution stays on the merge commit.
jihongboo commentedon Aug 8, 2026
Thanks for the follow-up. I did some more checks and I think your suspicion was correct.
AVSampleBufferDisplayLayeris indeed fully annotated withMainActor:So this is not only
sampleBufferRenderer; the whole layer is now main actor isolated in the latest SDK.I just built AetherEngine directly with Xcode 27 beta 4 and confirmed some of the warnings you mentioned:
So your analysis was right: this SDK change has a larger impact than we initially thought.
However, at least with Xcode 27 beta 4, these are currently warnings in my build and not errors that block compilation. The existing fix still resolves the
videoPerformanceMetricsissue, but the other renderer access points will likely need to be addressed if Apple makes these diagnostics stricter in future SDKs.Thanks again for digging into this.
Build AetherEngine_2026-08-08T15-50-22.txt
superuser404notfound commentedon Aug 9, 2026
Thanks, the log answered it. The short version: my "those four sites must break harder" reasoning was right about the isolation and wrong about the severity, and the reason is that I had modelled the wrong thing.
Why exactly one error. I built the earlier model in pure Swift. The annotation actually arrives through an ObjC import, and that carries preconcurrency semantics. Rebuilt as a ~20 line ObjC module (
__attribute__((swift_attr("@MainActor")))on the class, non-Sendable object property) plus a Swift file,swiftc -typecheck -swift-version 6, Swift 6.3.3:[#ActorIsolatedCall]group tag.asyncfunction pullingsampleBufferRendererout across anawait: error,non-Sendable type 'X' of property 'sampleBufferRenderer' cannot exit main actor-isolated context.So isolation violations against imported declarations are downgraded; the region rule that governs a non-Sendable value leaving the actor is not. One error on line 106 plus a pile of warnings is exactly the build I should have predicted.
A correction to my earlier comment while I am here: I wrote that
@preconcurrency importwas the wrong way round because it would leave the synchronous sites hard. That was true of the pure Swift model, not of yours, and your log shows the compiler suggesting it. It is still not the tool I want, it silences the Sendable rule wholesale rather than the one crossing.What the log settles that I could not have guessed. The hot path is already clean.
queueTargetis typedany AVQueuedSampleBufferRendering, and that protocol did not move to the main actor: the readiness gate through it (SampleBufferRenderer.swift:165), the enqueue path (:342) and the diagnostic read (:368) produce no diagnostic at all in your build. Enqueue and back-pressure, the two things that run per frame on the decode thread, need nothing. That was the open question, and it turns out the answer is "almost none of the renderer has to move".What warns is the acquisition and the layer-only API: four reads of
.sampleBufferRenderer(:158, :170, :177, :300, plus AudioOutput.swift:29 and :43),status/errorandflushAndRemoveImage()/flush()on the pre-18 branch (:172, :179, :303, :305), and two configuration writes in the layer factory (:184, :188). Twelve sites, all compile time, none per frame.Not patching them now. The obvious fix, caching the renderer once, is the wrong shape here:
displayLayeris avarand gets replaced when HDR output changes, so a stored renderer becomes a second source of truth the next layer swap can forget. What holds is either a main-actor factory that produces the layer and its queue target together, or raising the platform floor to tvOS 18 / iOS 18 / macOS 15 and deleting the legacy branch, which is a major. Neither is worth doing against a beta SDK that can still move before GM, for diagnostics that cost nothing today. All of it is written down in #351, including the trigger: a beta or GM where any of the twelve flips to an error. If you hit that first, a note there is plenty.One more thing your log was good for. It also caught something unrelated to the SDK:
AudioTapControllerhad its[weak self]on the innerTaskwhile the enclosingonTerminationclosure capturedselfstrongly anyway, so the controller's own continuation retained the controller back. Not a leak in the shipped paths, but the annotation promised something the code did not do. Fixed in #350.Closing this one: the build failure you reported is fixed and released in 6.12.1, and the remainder is tracked in #351. Thanks for the report, the patch, and for going back to the beta twice to settle it.
fix(audio): the tap continuation's weak capture sat on the wrong closure
ci: watch the newest Xcode, betas included, for the 27 SDK isolation …