Repository navigation
Conversation
Xcode 26.3 ships Swift 6.2.4, which rejects the nested main-queue closure with "sending 'self' risks causing data races": the outer block's weak capture is a mutable variable there. Capturing weakly again in the inner closure says the same thing in a form both compilers accept. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ne's queue AVAudioEngine posts its configuration change synchronously from its own queue. The observer was registered on the main operation queue, so the post waited for the main thread — which, rebuilding capture for the same route change, was waiting for that queue inside the old engine's dealloc. AirPods coming off mid-recording left the app hung, the mic track cut short and coreaudiod spinning (gsamat#63). The observer now runs on the poster's thread and only hands the change to the main queue. The engine being replaced is released off the main thread, with a wait that gives up after two seconds, so teardown still precedes setup without tying the app to Core Audio. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…dphones Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t points at Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
poznik
added a commit
to poznik/amanu
that referenced
this pull request
Nov 11, 2026
…ьный клон убран Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63.
The deadlock
AVAudioEnginepostsAVAudioEngineConfigurationChangesynchronously from its own serial queue.MicRecorderobserved it withqueue: .main, so the post waited for the main thread. The main thread, rebuilding capture for the same route change, was waiting for that queue inside-[AVAudioEngine dealloc](engine.stop()andremoveTap(onBus:)wait for it too). Thesampleof the hung process is in #63.What changes
queue: nil. On the poster's thread it only notes which engine posted, as anObjectIdentifier, and hands the rest to the main queue asynchronously (MicRecorder.observeConfigurationChanges). Everything that acts on the change still runs on the main thread.MicRecorder.Retiring). The caller waits for that, so teardown still precedes setup, but for no more than two seconds; past that it logs a warning and carries on.docs/pitfalls.mdgets a section on the deadlock, a section on Voice Isolation (below), and an entry under "What has never been verified".selfweakly itself. Happy to drop it from this PR if you would rather not carry it.Tests
Four tests in
MicRestartTests. The first reproduces the shape of the deadlock without a device: the main thread waits for a queue while that queue posts the notification. Against the oldqueue: .mainobserver it fails (the wait times out); with the change it passes.On my machine (macOS 15.8, Xcode 26.3)
swift testruns 771 tests with two failures that are also there without this change —MeetingLanguagesTests("The rest follow by name…") andStatusWindowLayoutTests("Every row the status window can show…") — andTests/scriptsfailstest_app_iconthe same way.landing/tests/check.pypasses. I have not run any of it on macOS 26.On a real device
MacBook Air M3, macOS 15.8, a call in another app, AirPods Max taken off mid-recording, with a build of this branch:
mic_restarts, and stops when asked. On 0.6.5 in the same situation it hung.One thing I got wrong in #63: the
coreaudiodloop is not caused by the deadlock. It goes with Voice Isolation chosen as the microphone mode for amanu itself in Control Center. With that mode on,coreaudiodspun in three recordings out of three (two on 0.6.5, one on this branch), and while it spins the rebuilt engine delivers no buffers. With amanu on Standard and the call app left on Voice Isolation, the same route change was uneventful twice, once on stock 0.6.5 and once on this branch: capture moved to the built-in microphone after about 0.9 s andcoreaudiodstayed under 20% CPU. So on 0.6.5 the deadlock only shows up once that loop is running; the fix here is what keeps the app alive when it does. Five recordings on one Mac is all the evidence there is, and I do not know the mechanism.Not covered here: after the switch the built-in microphone (three discrete channels) records silence, which is #57.
🤖 Generated with Claude Code