Skip to content

LiveKitComponents - Task-isolated value of type '() async -> ()' passed as strongly transferred parameter in AudioProcessor.render() #30

@svolla-aura

Description

@svolla-aura

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

  1. Clone livekit-examples/agent-starter-swift
  2. Open in Xcode 16.0 (Swift 6)
  3. Build or run the iOS target (e.g., VoiceAgent)
  4. 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 { ... }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions