Skip to content

fix(desktop): resolve PTT input routing off the main actor - #10695

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
katipally:fix/ptt-input-routing-offmain
Jul 27, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
katipally:fix/ptt-input-routing-offmain

Conversation

@katipally

@katipally katipally commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #10442.

PTT resolved its input device from an @MainActor method 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.

  • Read the HAL only on a dedicated non-main queue and publish the result as a Snapshot. The main actor now reads that snapshot under a lock and never touches CoreAudio.
  • Coalesce refreshes so a wedged driver parks exactly one probe thread no matter how many turns the user starts, instead of one per turn.
  • Warm the snapshot in setup() and at both PTT entry points, so the read overlaps turn-start work that already happens rather than gating capture on it.
  • Keep PTTInputDeviceRouting.overrideDeviceID byte-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:

bounded wait:      RESOLUTION=timedOut ELAPSED=0.305s RUNLOOP_TICKS=0
snapshot read:     RUNLOOP_TICKS > 10

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. testMainRunLoopKeepsPumpingWhileTheHALIsWedged fails 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 through recordFallback(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.swift baseline raised 2584 to 2587 with a justification for the three warm-up lines.

Real path, named bundle /Applications/omi-10442-ptt.app, bundle id com.omi.omi-10442-ptt, development backend, driven by real Option holds because every automation bridge action sets automationCaptureBypass and returns before this code:

  • 4 authenticated PTT turns, all reason=success route=hub with live transcripts and audio replies.
  • 2 of those with AirPods Pro as the default input and output device, which is the case the A2DP rule exists for:
    • PushToTalkManager: hub on Bluetooth output, capturing from built-in mic to keep A2DP
    • AudioCapture: Using override device ID 84, confirmed against CoreAudio as MacBook Pro Microphone, not the AirPods mic.
    • AirPods output stayed at 48000 Hz through both turns. An HFP flap would have dropped it to 16000.
  • The AirPods were connected roughly 20 minutes after launch, and the first turn after connecting routed correctly with 0 cold-snapshot fallbacks, which exercises snapshot refresh across a device change.
  • 0 occurrences of PTT input routing not resolved yet across 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 overrideDeviceID is unchanged from main and is covered by the existing ShortcutSettingsTests.

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.
  • Policy preservation: explicit user choice, Bluetooth built-in fallback, system default when output is not Bluetooth, unplugged selected device, and that the expensive built-in enumeration is skipped when output is not Bluetooth.
  • Cold and stale snapshots: a cold snapshot reports no override rather than guessing, and a snapshot resolved for a previous microphone is never applied after the user picks a different one.

Both fault tests join their parked probe before returning, so a late HAL answer cannot publish into whichever test runs next.

DesktopDiagnosticsManagerTests.testFallbackNamedAreasAreNotCollapsedToOther gains ptt_input_routing, which is the guard that the new area survives allowlist bucketing instead of silently collapsing to other.

Product invariants affected

  • INV-CHAT-1
  • INV-VOICE-1

Both are path matches rather than behavior changes. PushToTalkManager+InputDeviceRouting.swift and PushToTalkManager.swift sit under the FloatingControlBar/** glob, and PushToTalkManager.swift is named directly in the INV-VOICE-1 globs. The change adds no chat surface and no turn ownership: VoiceTurnReducer remains 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 is AppBuild.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.

Review in cubic

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.
@undivisible
undivisible force-pushed the fix/ptt-input-routing-offmain branch from c8eb478 to 3aa495f Compare July 27, 2026 05:02
@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution needs-maintainer-review Needs a human maintainer to sign off before merge labels Jul 27, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

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 .github/scripts ratchet baseline, and the monitor context disallows auto-approval for these risk surfaces. I also did not run the macOS/CoreAudio XCTest suite from this Linux review environment, so a human maintainer should still verify the desktop test target/CI on macOS before merge.

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 need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kodjima33
kodjima33 merged commit a8dc6ef into BasedHardware:main Jul 27, 2026
8 of 9 checks passed
Archit-lal added a commit to Archit-lal/omi that referenced this pull request Jul 27, 2026
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
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: move synchronous CoreAudio PTT routing off MainActor

3 participants