Description
Hi LiveKit team,
I’m evaluating the agent-starter-swift example on Xcode 16 (Swift 6 toolchain) and ran into a Swift concurrency warning related to the AudioProcessor class (which is part of LiveKitComponents).
Error
Task-isolated value of type '() async -> ()' passed as a strongly transferred parameter; later accesses could race
File: Sources/LiveKitComponents/Audio/AudioProcessor.swift
Line: ~51
Function: public nonisolated func render(pcmBuffer: AVAudioPCMBuffer)
Steps to Reproduce
- Clone
livekit-examples/agent-starter-swift
- Open in Xcode 16.0 (Swift 6)
- Build or run the iOS target (e.g.,
VoiceAgent)
- Observe the compiler warning in
AudioProcessor.swift
Snippet
public nonisolated func render(pcmBuffer: AVAudioPCMBuffer) {
Task {
let newBands = await processor.process(pcmBuffer: pcmBuffer)
guard var newBands else { return }
if isCentered {
newBands.sort(by: >)
newBands = Self.centerBands(newBands)
}
await MainActor.run { [newBands] in
bands = zip(bands, newBands).map { old, new in
Self.smoothTransition(from: old, to: new, factor: smoothingFactor)
}
}
}
}
Possible Fix / Workaround
Using explicit actor isolation or Task.detached eliminates the warning, but semantics might differ:
Task { @MainActor in
// ...
}
or
await MainActor.run { ... }