Skip to content

Conversation

@saamerm
Copy link

@saamerm saamerm commented Nov 23, 2025

Why is this change needed?

Problem:
Swift 6 strict concurrency checking prevents DiarizerManager from being passed to background tasks (e.g., Task.detached) because it is a class that does not conform to Sendable. This makes it difficult to run diarization inference off the Main Actor without warnings or errors.

Solution:

  • Marked DiarizerManager as @unchecked Sendable.
  • Introduced OSAllocatedUnfairLock to protect mutable state (models and embeddingExtractor).
  • Added backing storage (_models, _embeddingExtractor) to support the locking mechanism.
  • Updated cleanup() to properly nullify the embedding extractor as well.

Safety Justification:
Thread safety is achieved because the public API captures a local reference to the models and embeddingExtractor inside the lock before beginning long-running inference tasks. If cleanup() is called concurrently, the inference method holds onto the valid reference until it completes, preventing race conditions on the pointer.

Problem:
Swift 6 strict concurrency checking prevents DiarizerManager from being passed to background tasks (e.g., Task.detached) because it is a class that does not conform to Sendable. This makes it difficult to run diarization inference off the Main Actor without warnings or errors.

Solution:

Marked DiarizerManager as @unchecked Sendable.
Introduced OSAllocatedUnfairLock to protect mutable state (models and embeddingExtractor).
Added backing storage (_models, _embeddingExtractor) to support the locking mechanism.
Updated cleanup() to properly nullify the embedding extractor as well.
Safety Justification:
Thread safety is achieved because the public API captures a local reference to the models and embeddingExtractor inside the lock before beginning long-running inference tasks. If cleanup() is called concurrently, the inference method holds onto the valid reference until it completes, preventing race conditions on the pointer.
@Alex-Wengg
Copy link
Contributor

actions/runner-images#13341 we are currently exping a weird bug with github job runner i have attempted means to get around the issue but so far no success

@saamerm
Copy link
Author

saamerm commented Nov 24, 2025

@Alex-Wengg no worries, does that mean no merges till that is resolved?

@Alex-Wengg
Copy link
Contributor

@saamerm they reesolved it , i will take a look

@Alex-Wengg
Copy link
Contributor

just a headups we aren't on swift 6 as of this moment but we do plan to migrate soon

@saamerm
Copy link
Author

saamerm commented Nov 29, 2025

@Alex-Wengg ah I see. I was trying to use it in the sample repo yall have “swift-scribe” which runs swift 6, so I had manually pulled the files into that project. This PR helps allow better usage away from the UI thread without workarounds

@Alex-Wengg
Copy link
Contributor

we might plan to migrate to swift 6 soon

@xinnjie
Copy link
Contributor

xinnjie commented Dec 24, 2025

Better to use Mutex in the new Synchronization library rather than the old lock. Note that Synchronization requires IOS 18.

Or use make DiarizerManager an actor. But API will change.

@Alex-Wengg
Copy link
Contributor

hi @saamerm we have just migrated over to swift 6 so this change may not be needed anymore.

@Alex-Wengg Alex-Wengg closed this Dec 31, 2025
@saamerm
Copy link
Author

saamerm commented Dec 31, 2025

@Alex-Wengg sounds good, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants