Repository navigation
fix(desktop): resolve PTT input routing off the main actor - #10695
Conversation
PTT resolved its input device from an @mainactor method that synchronously called three CoreAudio HAL reads at turn start. Those reads have no deadline and no cancellation, so a wedged audio driver pinned the whole UI, not just push-to-talk. Read the HAL only on a dedicated non-main queue and publish a Snapshot that the main actor reads under a lock. Refreshes coalesce, so a wedged driver parks exactly one probe thread no matter how many turns start, instead of one per turn. setup() and both PTT entry points warm the snapshot so the read overlaps turn-start work rather than gating capture on it. A bounded wait on the main thread was tried first and rejected. It moves the CoreAudio work off-thread but still parks the run loop for the whole budget (RUNLOOP_TICKS=0 over 305ms), which fails the requirement that the main run loop stays responsive. overrideDeviceID is unchanged, so the selected-device and Bluetooth A2DP policy is identical, and all four routing call sites are untouched. Verified: 387 Swift suites; agent-logic-harness 526 lifecycle tests; SwiftLint 0 violations across 902 files; pinned swift-format clean. Four real Option-hold PTT turns on the omi-10442-ptt bundle, all reason=success route=hub. Two ran with AirPods Pro as the default input and output device: the override resolved to device 84, confirmed against CoreAudio as MacBook Pro Microphone, and AirPods output held 48000 Hz, so A2DP never flapped to HFP. Failure-Class: none
…outing warm-up setup() and both PTT entry points warm the CoreAudio input-routing snapshot off the main thread, which grows PushToTalkManager.swift from 2584 to 2587 lines. The existing BasedHardware#10499 justification is kept alongside the new one.
c8eb478 to
3aa495f
Compare
|
Thanks for the careful fix here. I reviewed the PTT input-routing change statically and this looks like the right direction: CoreAudio/HAL reads move off the main actor, the main-actor path only reads a locked snapshot, refreshes are coalesced so a wedged driver does not spawn one blocked probe per turn, and the existing explicit-mic/Bluetooth built-in fallback policy is preserved. The new tests cover the important regression cases, including main-run-loop responsiveness while the probe is wedged, coalescing, stale UID snapshots, and the existing routing policy. I’m leaving this as a positive signal rather than a formal approval because this touches desktop audio routing plus the No requested changes from me based on the static review. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Verified against #10442: the synchronous CoreAudio HAL reads still run on the main actor on main, so a wedged driver pins the whole UI; moving the probe to a dedicated queue with a published Snapshot is the right shape and comes with tests + a changelog entry.
Sync 205 commits from upstream so CI runs People Intelligence on current main. This pulls in BasedHardware#10695 (a8dc6ef, "resolve PTT input routing off the main actor"), which fixes PTTInputDeviceProbeTests — the sole real failure on the pre-merge branch (the main run loop wedged on the stale base, so the 0.3s tick assertion saw 9/10 ticks). The "test-install ... semantically match" launcher lines are non-fatal negative-control output; that step exits 0 on both upstream/main and this merge. Conflict: desktop-swift-root.json line-count baseline for OmiApp.swift. Resolved to 1567 = upstream's 1562 + the 5-line PeopleGraphBuilder.syncIfNeeded app-become-active wiring (preserved at OmiApp.swift:662). Verified locally on the merged tree: macOS manifest static checks pass (0 swiftlint violations across 943 files, 3 manifest checks), and the test-install workflow contract launcher test exits 0. Swift unit suite requires Xcode 16.4 (not available locally); CI validates it post-push. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_017Lnh6aTGmBGSUpewYZCkQc
…ware#10695) * fix(desktop): resolve PTT input routing off the main actor PTT resolved its input device from an @mainactor method that synchronously called three CoreAudio HAL reads at turn start. Those reads have no deadline and no cancellation, so a wedged audio driver pinned the whole UI, not just push-to-talk. Read the HAL only on a dedicated non-main queue and publish a Snapshot that the main actor reads under a lock. Refreshes coalesce, so a wedged driver parks exactly one probe thread no matter how many turns start, instead of one per turn. setup() and both PTT entry points warm the snapshot so the read overlaps turn-start work rather than gating capture on it. A bounded wait on the main thread was tried first and rejected. It moves the CoreAudio work off-thread but still parks the run loop for the whole budget (RUNLOOP_TICKS=0 over 305ms), which fails the requirement that the main run loop stays responsive. overrideDeviceID is unchanged, so the selected-device and Bluetooth A2DP policy is identical, and all four routing call sites are untouched. Verified: 387 Swift suites; agent-logic-harness 526 lifecycle tests; SwiftLint 0 violations across 902 files; pinned swift-format clean. Four real Option-hold PTT turns on the omi-10442-ptt bundle, all reason=success route=hub. Two ran with AirPods Pro as the default input and output device: the override resolved to device 84, confirmed against CoreAudio as MacBook Pro Microphone, and AirPods output held 48000 Hz, so A2DP never flapped to HFP. Failure-Class: none * chore(desktop): raise PushToTalkManager line-count baseline for PTT routing warm-up setup() and both PTT entry points warm the CoreAudio input-routing snapshot off the main thread, which grows PushToTalkManager.swift from 2584 to 2587 lines. The existing BasedHardware#10499 justification is kept alongside the new one.
Summary
Fixes #10442.
PTT resolved its input device from an
@MainActormethod that synchronously called three CoreAudio HAL reads (inputDeviceID(forUID:),isDefaultOutputBluetooth(),findBuiltInMicDeviceID()) at turn start. Those reads have no deadline and no cancellation, so a wedged audio driver pinned the whole UI, not just PTT.Snapshot. The main actor now reads that snapshot under a lock and never touches CoreAudio.setup()and at both PTT entry points, so the read overlaps turn-start work that already happens rather than gating capture on it.PTTInputDeviceRouting.overrideDeviceIDbyte-identical, so the selected-device and Bluetooth A2DP policy is unchanged.The routing call stays synchronous and all four call sites are untouched, so turn-start ordering and reducer ownership do not change.
Why this is larger than a bounded wait
The obvious reading of "bounded non-main executor" is a background queue plus a timeout on the main thread. I built that first and measured it against the issue's other requirement, that the main run loop stays responsive:
A bounded wait moves the CoreAudio work off the main thread but still parks the run loop for the whole budget, so it converts an unbounded freeze into a 250ms freeze on every turn start.
testMainRunLoopKeepsPumpingWhileTheHALIsWedgedfails on that design and passes on this one.Trade-off
With a slow but not wedged HAL, the previous code froze the UI and then routed correctly. This code stays responsive and may fall back to the system default input for a single turn, which on Bluetooth output means one turn on the headset mic. Warming at
setup()plus both entry points reduced this to zero cold-snapshot fallbacks across every real turn I ran, including the first turn after launch, but the window is not provably zero on a slow machine. It self-corrects on the next turn and is recorded throughrecordFallback(area: "ptt_input_routing").Verification
Desktop Swift, from
desktop/macos:xcrun swift build -c debug --package-path Desktop: build complete, Swift 6 strict concurrency with warnings as errors.xcrun swift test --package-path Desktop --filter 'PTTInputDeviceProbeTests|ShortcutSettingsTests': 15 tests, 0 failures. Run 10 consecutive times to confirm no ordering dependence../test.sh: 387 Swift suites in isolation, all passed../scripts/agent-logic-harness.sh --swift-only: passed, 526 lifecycle/state tests../scripts/swiftlint-wrapper.sh lint: 0 violations across 902 files.bash desktop/macos/scripts/swift-format-wrapper.sh lint-scope: clean, pinned swift-format 602.0.0.python3 .github/scripts/check_product_file_line_count_ratchet.py --changed-files <list>: OK.PushToTalkManager.swiftbaseline raised 2584 to 2587 with a justification for the three warm-up lines.Real path, named bundle
/Applications/omi-10442-ptt.app, bundle idcom.omi.omi-10442-ptt, development backend, driven by realOptionholds because every automation bridge action setsautomationCaptureBypassand returns before this code:reason=success route=hubwith live transcripts and audio replies.PushToTalkManager: hub on Bluetooth output, capturing from built-in mic to keep A2DPAudioCapture: Using override device ID 84, confirmed against CoreAudio asMacBook Pro Microphone, not the AirPods mic.48000 Hzthrough both turns. An HFP flap would have dropped it to 16000.PTT input routing not resolved yetacross every real turn.Not verified on hardware: the wedged-driver branch itself. This machine's HAL is healthy, so that path is covered by fault injection only. The explicit user-selected-microphone branch was not re-tested on hardware because
overrideDeviceIDis unchanged frommainand is covered by the existingShortcutSettingsTests.Tests
PTTInputDeviceProbeTests(new, 9 tests):testMainRunLoopKeepsPumpingWhileTheHALIsWedged: the issue's acceptance criterion. Injects a HAL that never returns and asserts the main run loop keeps ticking while turn-start reads keep completing.testConcurrentRefreshesCoalesceIntoASingleHALRead: 25 turn starts against a wedged driver park exactly one probe thread.Both fault tests join their parked probe before returning, so a late HAL answer cannot publish into whichever test runs next.
DesktopDiagnosticsManagerTests.testFallbackNamedAreasAreNotCollapsedToOthergainsptt_input_routing, which is the guard that the new area survives allowlist bucketing instead of silently collapsing toother.Product invariants affected
Both are path matches rather than behavior changes.
PushToTalkManager+InputDeviceRouting.swiftandPushToTalkManager.swiftsit under theFloatingControlBar/**glob, andPushToTalkManager.swiftis named directly in the INV-VOICE-1 globs. The change adds no chat surface and no turn ownership:VoiceTurnReducerremains the sole turn owner and the four routing call sites are unchanged.Failure-Class: none
No class in
.github/failure-classes/describes an uncancellable external-subsystem call made on the owning actor. The closest sibling in-tree isAppBuild.channelProbeMainThreadBudget, a main-thread wait on a network probe, but one prior instance is not a recurring pattern, and opening a class is a separate registry PR.