Skip to content

fix(desktop): stop the silent-mic alert loop, and unify the microphone setting - #11421

Merged
kodjima33 merged 4 commits into
mainfrom
kodjima33/silent-mic-heal-and-unified-mic
Aug 13, 2026
Merged

kodjima33 merged 4 commits into
mainfrom
kodjima33/silent-mic-heal-and-unified-mic

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Silent-mic alert loop

Nik's prod log shows 31 silent-mic detections and 14 alerts in one sitting, roughly one modal every 60–90s:

13:53:52  Started session (device: AirPods Max)
13:54:00  Bluetooth mic returning silence for 2s — falling back to built-in mic
13:54:00  Using override device ID 86            <- built-in
13:54:12  Input device returning silence for 2s — rebuilding CoreAudio capture
13:54:15  Bluetooth mic returning silence for 2s — falling back to built-in mic

handleSilentMicFallback pins capture to the built-in mic; rebuildCoreAudioCaptureStack then builds a plain AudioCaptureService() with no override, re-resolving the system default — still the silent AirPods Max. The heal and its own recovery fight until the 3-attempt cap trips the modal, then it repeats.

AirPods Max returning zero samples is normal macOS behaviour (output-only mode). The bug is that the recovery undoes the fix.

Fix: silentMicHealedDeviceID holds the healed route for the session and the rebuild honours it; cleared at session start/stop. SilentMicRoutePolicy states the contract as a pure, tested function.

One microphone setting

Push-to-talk carried its own picker in Shortcuts (#10393) storing shortcut_pttInputDeviceUID, separate from the transcription picker's preferredMicrophoneDeviceUID — a user could pick a mic in one place and be recorded by another. The duplicate card is removed; PTT reads the transcription setting, with a one-time migration so an existing PTT-only choice carries over.

Verification

Exercised on the running omi-mic bundle:

  • Shortcuts — no microphone card (screenshot)
  • Transcription — single Microphone picker
  • 25 focused tests pass; swift-format clean

UNVERIFIED: the alert loop end-to-end. Reproducing it needs a Bluetooth mic returning zero samples during a live session; the mechanism above is read from the prod log rather than re-triggered.

Failure-Class: none

Product invariants affected

  • INV-CHAT-1 — unchanged. This diff touches microphone input routing and the settings surface for it; it does not alter transcript ownership, session identity, or how a transcript is shared across surfaces. The silent-mic heal only changes which CoreAudio device a rebuilt capture reads from, and the PTT change consolidates two settings keys into the existing one.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 8 files

Confidence score: 3/5

  • In desktop/macos/Desktop/Sources/FloatingControlBar/ShortcutSettings.swift, the migration writes a completion marker separately from the legacy mic copy, so an app exit between writes can strand existing PTT-only users with no selected microphone on next launch; make the migration atomic (or only set completion after a verified copy) to prevent permanent preference loss.
  • In desktop/macos/Desktop/Sources/AppState/SharedCaptureSilentMicRecoveryPolicy.swift, SilentMicRoutePolicy.captureDeviceID appears unused in production paths, which raises drift risk where recovery behavior differs from intended logic; either wire it into the rebuild flow in AppState+Transcription.swift or remove it to keep one authoritative path.
  • In desktop/macos/Desktop/Sources/FloatingControlBar/PushToTalkManager+InputDeviceRouting.swift, ShortcutSettings.pttInputDeviceUID persistence is now orphaned, so stale settings may remain and confuse future maintenance or migrations; clean up the unused key/init/didSet or add an explicit deprecation migration.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/macos/Desktop/Sources/FloatingControlBar/ShortcutSettings.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/FloatingControlBar/ShortcutSettings.swift:385">
P2: An existing PTT-only user can permanently lose the selected microphone if the process exits between these two UserDefaults writes, because the next access sees the completion marker and skips migration. Copy the legacy value first and persist the completion marker only after the migration path has finished.</violation>
</file>

<file name="desktop/macos/Desktop/Sources/FloatingControlBar/PushToTalkManager+InputDeviceRouting.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/FloatingControlBar/PushToTalkManager+InputDeviceRouting.swift:161">
P3: After unifying the microphone setting, `ShortcutSettings.pttInputDeviceUID` (and its init/`didSet` persistence) is no longer read or written anywhere — routing uses `unifiedMicrophoneUID` and the picker card is gone, while the migration reads the raw defaults key directly. Consider removing the now-dead `@Published` property (and its restore-to-defaults wiring) to avoid two sources of truth for the same concept. If it's kept intentionally for migration/back-compat, a brief comment noting the reason would help future readers.</violation>
</file>

<file name="desktop/macos/Desktop/Sources/AppState/SharedCaptureSilentMicRecoveryPolicy.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/AppState/SharedCaptureSilentMicRecoveryPolicy.swift:34">
P3: The `SilentMicRoutePolicy.captureDeviceID` function added here is dead code as far as production is concerned — it is never called anywhere in `Sources/`. The rebuild path in `AppState+Transcription.swift` (`rebuildCoreAudioCaptureStack`) duplicates the same `healed ?? systemDefault` decision inline (`if let healed = silentMicHealedDeviceID { AudioCaptureService(overrideDeviceID: healed) } else { AudioCaptureService() }`) rather than invoking this tested function. As a result the new `SilentMicRoutePolicyTests` don't actually exercise the production code path this PR is fixing — the logic they pin can drift apart from what ships, so the test gives false confidence instead of guarding the real behavior. Consider wiring the rebuild through `SilentMicRoutePolicy.captureDeviceID` (or removing the unused helper and testing the rebuild path directly) so the documented contract and the runtime decision stay in sync.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

private static func migratePTTMicrophoneChoiceIfNeeded() {
let defaults = UserDefaults.standard
guard !defaults.bool(forKey: "shortcut_pttMicrophoneMergedIntoPreferred") else { return }
defaults.set(true, forKey: "shortcut_pttMicrophoneMergedIntoPreferred")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: An existing PTT-only user can permanently lose the selected microphone if the process exits between these two UserDefaults writes, because the next access sees the completion marker and skips migration. Copy the legacy value first and persist the completion marker only after the migration path has finished.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/FloatingControlBar/ShortcutSettings.swift, line 385:

<comment>An existing PTT-only user can permanently lose the selected microphone if the process exits between these two UserDefaults writes, because the next access sees the completion marker and skips migration. Copy the legacy value first and persist the completion marker only after the migration path has finished.</comment>

<file context>
@@ -367,6 +367,28 @@ class ShortcutSettings: ObservableObject {
+  private static func migratePTTMicrophoneChoiceIfNeeded() {
+    let defaults = UserDefaults.standard
+    guard !defaults.bool(forKey: "shortcut_pttMicrophoneMergedIntoPreferred") else { return }
+    defaults.set(true, forKey: "shortcut_pttMicrophoneMergedIntoPreferred")
+    let legacy = defaults.string(forKey: DefaultsKey.shortcutPTTInputDeviceUID.rawValue) ?? ""
+    let current = defaults.string(forKey: AudioCaptureService.preferredInputUIDDefaultsKey) ?? ""
</file context>

/// hit and the user gets a modal. A heal that a rebuild can undo is not a heal.
enum SilentMicRoutePolicy {
/// `healed` wins for the rest of the session; `nil` means follow the system default.
static func captureDeviceID(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The SilentMicRoutePolicy.captureDeviceID function added here is dead code as far as production is concerned — it is never called anywhere in Sources/. The rebuild path in AppState+Transcription.swift (rebuildCoreAudioCaptureStack) duplicates the same healed ?? systemDefault decision inline (if let healed = silentMicHealedDeviceID { AudioCaptureService(overrideDeviceID: healed) } else { AudioCaptureService() }) rather than invoking this tested function. As a result the new SilentMicRoutePolicyTests don't actually exercise the production code path this PR is fixing — the logic they pin can drift apart from what ships, so the test gives false confidence instead of guarding the real behavior. Consider wiring the rebuild through SilentMicRoutePolicy.captureDeviceID (or removing the unused helper and testing the rebuild path directly) so the documented contract and the runtime decision stay in sync.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/AppState/SharedCaptureSilentMicRecoveryPolicy.swift, line 34:

<comment>The `SilentMicRoutePolicy.captureDeviceID` function added here is dead code as far as production is concerned — it is never called anywhere in `Sources/`. The rebuild path in `AppState+Transcription.swift` (`rebuildCoreAudioCaptureStack`) duplicates the same `healed ?? systemDefault` decision inline (`if let healed = silentMicHealedDeviceID { AudioCaptureService(overrideDeviceID: healed) } else { AudioCaptureService() }`) rather than invoking this tested function. As a result the new `SilentMicRoutePolicyTests` don't actually exercise the production code path this PR is fixing — the logic they pin can drift apart from what ships, so the test gives false confidence instead of guarding the real behavior. Consider wiring the rebuild through `SilentMicRoutePolicy.captureDeviceID` (or removing the unused helper and testing the rebuild path directly) so the documented contract and the runtime decision stay in sync.</comment>

<file context>
@@ -20,3 +22,19 @@ enum SharedCaptureSilentMicRecoveryPolicy {
+/// hit and the user gets a modal. A heal that a rebuild can undo is not a heal.
+enum SilentMicRoutePolicy {
+  /// `healed` wins for the rest of the session; `nil` means follow the system default.
+  static func captureDeviceID(
+    healed: AudioDeviceID?,
+    systemDefault: AudioDeviceID?
</file context>

/// Non-blocking. Kicks the next HAL read and answers from the last one that landed.
func preferredPTTInputOverrideDeviceID() -> AudioDeviceID? {
let selectedUID = ShortcutSettings.shared.pttInputDeviceUID
let selectedUID = ShortcutSettings.unifiedMicrophoneUID

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: After unifying the microphone setting, ShortcutSettings.pttInputDeviceUID (and its init/didSet persistence) is no longer read or written anywhere — routing uses unifiedMicrophoneUID and the picker card is gone, while the migration reads the raw defaults key directly. Consider removing the now-dead @Published property (and its restore-to-defaults wiring) to avoid two sources of truth for the same concept. If it's kept intentionally for migration/back-compat, a brief comment noting the reason would help future readers.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/FloatingControlBar/PushToTalkManager+InputDeviceRouting.swift, line 161:

<comment>After unifying the microphone setting, `ShortcutSettings.pttInputDeviceUID` (and its init/`didSet` persistence) is no longer read or written anywhere — routing uses `unifiedMicrophoneUID` and the picker card is gone, while the migration reads the raw defaults key directly. Consider removing the now-dead `@Published` property (and its restore-to-defaults wiring) to avoid two sources of truth for the same concept. If it's kept intentionally for migration/back-compat, a brief comment noting the reason would help future readers.</comment>

<file context>
@@ -158,7 +158,7 @@ private final class SnapshotStore: @unchecked Sendable {
   /// Non-blocking. Kicks the next HAL read and answers from the last one that landed.
   func preferredPTTInputOverrideDeviceID() -> AudioDeviceID? {
-    let selectedUID = ShortcutSettings.shared.pttInputDeviceUID
+    let selectedUID = ShortcutSettings.unifiedMicrophoneUID
     let snapshot = PTTInputDeviceRouting.currentSnapshot(selectedUID: selectedUID)
     if let snapshot, !selectedUID.isEmpty, snapshot.selectedDeviceID == nil {
</file context>

@kodjima33
kodjima33 force-pushed the kodjima33/silent-mic-heal-and-unified-mic branch 2 times, most recently from 501b817 to af8514e Compare August 13, 2026 06:14
…e setting

Nik's prod log: 31 silent-mic detections and 14 "Microphone Isn't Capturing Audio"
alerts in one sitting, on a loop roughly every 60-90s.

    13:53:52  Started session (device: AirPods Max)
    13:54:00  Bluetooth mic returning silence for 2s — falling back to built-in mic
    13:54:00  Using override device ID 86            <- built-in
    13:54:12  Input device returning silence for 2s — rebuilding CoreAudio capture
    13:54:15  Bluetooth mic returning silence for 2s — falling back to built-in mic

`handleSilentMicFallback` pins capture to the built-in mic, then
`rebuildCoreAudioCaptureStack` builds a plain `AudioCaptureService()` with no override,
which re-resolves the *system default* — still the silent AirPods Max. The heal and its
own recovery fight until the 3-attempt cap trips the modal, then it repeats. A heal a
rebuild can undo is not a heal.

- `silentMicHealedDeviceID` holds the healed route for the session; the rebuild honours
  it. Cleared at session start and stop so it cannot outlive its reason.
- `SilentMicRoutePolicy` states the contract as a pure function, with tests: a healed
  device outranks the system default.

Separately, push-to-talk carried its own microphone picker in Shortcuts settings
(#10393), so a user could choose a mic in one place and be recorded by another. There is
one physical microphone; there is now one setting. The duplicate card is removed and PTT
reads the transcription setting, with a one-time migration so an existing PTT-only choice
is carried over rather than dropped.

Verified on the running named bundle omi-mic: Shortcuts shows no microphone card,
Transcription shows the single picker. 25 focused tests pass.

The alert loop itself is UNVERIFIED end-to-end — reproducing it needs a Bluetooth mic
returning zero samples during a live session. The mechanism above is from the prod log.

Failure-Class: none
…mic heal

The healed input route needs one stored property and its use at the rebuild site;
splitting this file is not in scope for a targeted alert-loop fix.
… at startup

Two gaps in the previous commit, both caught in review:

`SilentMicRoutePolicy` had no production call site, so its tests guarded nothing — they
would still have passed if `rebuildCoreAudioCaptureStack` went back to a plain
`AudioCaptureService()`. The rebuild now asks the policy which device to use.

The PTT microphone migration only ran when PTT routing read the shared preference, so a
user with a legacy PTT-only choice saw "System Default" in Transcription — and was
recorded by it — until they happened to take a push-to-talk turn. It now runs in
AppState.init(), before anything reads the preference.

Replaces the source-string wiring assertions with behavioural tests: the migration is
pure UserDefaults, so it is exercised directly (carries a legacy choice over, never
overwrites an explicit transcription choice, runs once). The repo's test-quality ratchet
was right to reject the string tripwires.

28 focused tests pass; make preflight 20/20.

Failure-Class: none
@kodjima33
kodjima33 force-pushed the kodjima33/silent-mic-heal-and-unified-mic branch from af8514e to 6be178a Compare August 13, 2026 06:22
@kodjima33
kodjima33 merged commit 6733ee3 into main Aug 13, 2026
27 of 31 checks passed
@kodjima33
kodjima33 deleted the kodjima33/silent-mic-heal-and-unified-mic branch August 13, 2026 18:09
undivisible added a commit that referenced this pull request Aug 26, 2026
## Summary

Present microphone recovery alerts as non-blocking sheets instead of
blocking the main actor. When no Omi window is available, queue the
alert until the application becomes active or a window becomes key.

## Sentry issue

-
[OMI-DESKTOP-3M5](https://omi-nk3.sentry.io/issues/7642270321/?project=4511086024851456)

Related: #11421 prevents repeated silent-mic recovery from reaching this
alert; this PR removes the separate blocking modal when an alert is
presented.

## Failure class

Failure-Class: none

## Verification

- Swift format, parse, test-quality, e2e coverage, and diff checks
passed.
- The focused XCTest compiled and linked locally; its runtime is blocked
by the host's missing Sparkle.framework.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes main-thread alert presentation and window activation for all
`showAlert` call sites (transcription, permissions, device errors);
incorrect queueing or summon logic could hide alerts or steal focus,
though tests cover the main edge cases.
> 
> **Overview**
> Replaces **blocking** `NSAlert.runModal()` for shared `showAlert`
paths with a **non-blocking sheet** on the main shell window, so
microphone and transcription warnings no longer freeze the main actor
(addresses the silent-mic / permission alert freeze).
> 
> Introduces **`DesktopAlertPresenting`** and
**`AppKitSheetAlertPresenter`**, wired via `AppState.alertPresenter`.
The presenter **queues** alerts, **coalesces** duplicates, **reveals**
the main window when no shell is presentable, **defers** when another
sheet is attached, and runs optional **completions after dismiss**—so
opening **System Settings → Microphone** happens only after the user
dismisses **"Omi Needs Microphone Access"**, not underneath it.
> 
> Adds **`AppStateAlertPresentationTests`** and extends the
audio-recording e2e flow for silent-mic recovery and permission alert
behavior; changelog notes the freeze fix.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
24ecd0c. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Line-Count-Exception:
desktop/macos/Desktop/Sources/AppState/AppState+Transcription.swift |
1738 -> 1743 | permission alert gains a sheet-completion callback that
opens the microphone settings pane only after the non-blocking alert is
seen
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.

1 participant