Skip to content

feat(desktop): listening-state toggle with persistence and global hotkey (#6649) - #7199

Closed
mvanhorn wants to merge 11 commits into
BasedHardware:mainfrom
mvanhorn:feat/6649-desktop-listening-toggle
Closed

mvanhorn wants to merge 11 commits into
BasedHardware:mainfrom
mvanhorn:feat/6649-desktop-listening-toggle

Conversation

@mvanhorn

@mvanhorn mvanhorn commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a one-tap pause/resume toggle for conversation listening on the desktop app, persisted across restarts and bound to a rebindable global hotkey (default ⌘⇧L).

Why this matters

Issue #6649 asked for granular control over when the app is actively listening, with an obvious indicator and a hotkey. Today users have to power off the device or quit the app to stop conversation capture. This adds three discoverable surfaces (sidebar pill, floating control bar, hotkey) so a user can pause sensitive conversations without losing the device session.

Demo

Simulated demo (Remotion) of the toggle states. The actual desktop app build is gated by Apple Developer ID signing identity and SwiftPM dep clone failures in my workspace, so this is a programmatic mock against the real Omi color palette and layout, not a live capture.

demo

Changes

  • AppState.isConversationListening (@Published + @AppStorage("omi.listening.enabled")), toggleListening(source:), setListening(_:source:). Default on first launch is true (preserves existing behavior).
  • Pause gracefully stops the in-flight transcription via the existing stopTranscription() path. Microphone and BLE remain open. A guard in startTranscription() declines to start while paused, so auto-start triggers (BLE reconnect, user action) are no-ops until the user resumes.
  • New global shortcut Toggle Listening (default ⌘⇧L), rebindable via Shortcuts settings. GlobalShortcutManager registers the hotkey and posts Notification.Name.toggleListeningShortcutPressed; AppState listens and calls toggleListening(source: "hotkey").
  • Sidebar listening pill (ear.fill / ear.slash.fill, success/warning colors), floating control bar status pill, and tap-to-toggle dot on the compact bar.
  • AnalyticsManager.listeningToggled emits a Sentry breadcrumb (category: "listening") and a PostHog listening_toggled event with state and source properties.
  • Push-to-talk (PushToTalkManager) is independent and continues to work while listening is paused.
  • Added desktop/Desktop/Tests/AppStateListeningTests.swift covering toggle + persistence across AppState reloads.

Note

Touches FloatingControlBarWindow.swift, which my open #6770 also modifies. The change here is additive (new init parameter); rebase from whichever lands first.

Fixes #6649

Product invariants affected

  • INV-CHAT-1

Line-Count-Exception: desktop/macos/Desktop/Sources/AnalyticsManager.swift | 1771 -> 1788 | listeningToggled analytics event for the pause/resume surface
Line-Count-Exception: desktop/macos/Desktop/Sources/AppState/AppState+Transcription.swift | 1758 -> 1813 | listening-state plumbing: pause/resume gating on the transcription path
Line-Count-Exception: desktop/macos/Desktop/Sources/FloatingControlBar/FloatingControlBarView.swift | 3171 -> 3227 | listening toggle surface in the control bar, including the three-state pill
Line-Count-Exception: desktop/macos/Desktop/Sources/FloatingControlBar/FloatingControlBarWindow.swift | 6073 -> 6091 | window wiring for the new toggle parameter

Failure-Class: none

UI evidence

Offscreen renders of the production FloatingControlBarView compact bar, captured through NSHostingView in a local XCTest harness (not a live app session):

Control bar listening
Control bar paused
Control bar mode Off

Green is listening, amber is paused (mic and BLE stay up), grey is recording mode Off with the toggle disabled.

@greptile-apps

greptile-apps Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a listening-state toggle for the desktop app: a @Published / @AppStorage-backed isConversationListening flag on AppState, a rebindable global hotkey (⌘⇧L), and three UI surfaces (sidebar pill, floating bar status pill, compact bar dot) that let users pause/resume conversation capture without disconnecting the device or quitting.

  • Pause path correctly calls stopTranscription() and guards both the audioMixer callback and the new BLE conversationAudioHandler closure so no audio reaches the transcription service while paused.
  • Resume path only sets the isConversationListening flag — it does not call startTranscription(). After toggling back to "Listening," the UI shows the active state but recording has not restarted; the user must press play manually.
  • Both audio-delivery closures read isConversationListening from background threads on a @MainActor-isolated class, which is an unsound cross-actor access.

Confidence Score: 3/5

The pause direction works correctly, but resuming listening leaves the transcription pipeline stopped while the UI reports Listening, so users silently lose recordings after every pause/resume cycle.

The resume path in setListening sets the flag but never calls startTranscription(), meaning the device appears active to the user but captures nothing. Both audio-delivery closures also read a @MainActor-isolated property from background audio threads without actor hopping. The rest of the change — shortcut wiring, persistence, analytics, UI surfaces — is well-structured and follows existing patterns.

AppState.swift — specifically setListening (resume branch) and the two audio-callback closures that bypass main-actor isolation.

Important Files Changed

Filename Overview
desktop/Desktop/Sources/AppState.swift Adds listening toggle logic and persistence; resume path does not restart transcription (UI shows Listening but recording is stopped); audio-thread closures read @MainActor-isolated property without isolation.
desktop/Desktop/Sources/Audio/BleAudioService.swift Adds conversationAudioHandler parameter to pipe BLE PCM audio through a guarded closure instead of directly to transcriptionService; cleanup on stopProcessing is correct.
desktop/Desktop/Sources/FloatingControlBar/GlobalShortcutManager.swift Adds toggleListening hot-key registration (ID 3) and re-registration observer; follows the existing Ask Omi pattern correctly.
desktop/Desktop/Sources/FloatingControlBar/ShortcutSettings.swift Adds toggleListeningShortcut and toggleListeningEnabled stored properties with correct UserDefaults persistence and change-notification plumbing.
desktop/Desktop/Sources/FloatingControlBar/FloatingControlBarView.swift Adds listening status pill and toggleable compact dot using appState injection; visually communicates state, no logic issues found.
desktop/Desktop/Sources/FloatingControlBar/FloatingControlBarWindow.swift Adds appState parameter to init and threads it through to FloatingControlBarView; straightforward plumbing change.
desktop/Desktop/Sources/MainWindow/SidebarView.swift Adds listening toggle pill to the expanded sidebar using OmiColors.success/warning; reads correctly from appState.isConversationListening.
desktop/Desktop/Sources/MainWindow/Pages/ShortcutsSettingsSection.swift Adds toggleListeningKeyCard to the shortcuts settings page, following the exact same preset/custom/disable pattern used by Ask Omi.
desktop/Desktop/Sources/AnalyticsManager.swift Adds listeningToggled() that emits a Sentry breadcrumb and a PostHog event; correctly mirrors the pattern used by other analytics methods.
desktop/Desktop/Tests/AppStateListeningTests.swift Covers toggle + persistence across AppState reloads; does not test the resume-restart behavior or the data-race path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    U([User action: UI / hotkey / sidebar]) --> TL[toggleListening]
    TL --> SL[setListening on/off]

    SL -->|on = false| ST[stopTranscription]
    ST --> SAC[stopAudioCapture + clearTranscriptionState]
    SAC --> FLAG_OFF[isConversationListening = false\npersisted to UserDefaults]

    SL -->|on = true| FLAG_ON[isConversationListening = true\npersisted to UserDefaults]
    FLAG_ON -. missing call .-> NOSTART[startTranscription NOT called - recording stays stopped]

    FLAG_OFF --> MIC_GUARD[audioMixer callback - guard isConversationListening from background thread]
    FLAG_OFF --> BLE_GUARD[conversationAudioHandler - guard isConversationListening from background thread]

    MIC_GUARD -->|blocked| DROP1[audio dropped]
    BLE_GUARD -->|blocked| DROP2[audio dropped]

    GSM[GlobalShortcutManager Carbon hotkey] --> NC[NotificationCenter toggleListeningShortcutPressed]
    NC --> TL
Loading

Reviews (1): Last reviewed commit: "fix(desktop): stop transcription on paus..." | Re-trigger Greptile

Comment thread desktop/Desktop/Sources/AppState.swift Outdated
Comment on lines +1244 to +1258
func setListening(_ on: Bool, source: String = "ui") {
let previous = isConversationListening
guard previous != on else { return }

if !on && isTranscribing {
stopTranscription()
}

isConversationListening = on
persistedConversationListening = on
UserDefaults.standard.set(on, forKey: Self.conversationListeningDefaultsKey)

AnalyticsManager.shared.listeningToggled(isListening: on, source: source)
log("listening: \(previous ? "on" : "off") -> \(on ? "on" : "off") (source=\(source))")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Resume doesn't restart transcription

setListening(false) calls stopTranscription(), which calls stopAudioCapture() and clearTranscriptionState() — fully tearing down the pipeline and setting isTranscribing = false. But setListening(true) only flips the flag; it never calls startTranscription(). After the user resumes, isConversationListening is true and the sidebar shows "Listening," yet no recording is happening. The user must manually press play to restart, which silently contradicts the visual affordance of the toggle.

Comment thread desktop/Desktop/Sources/AppState.swift Outdated
Comment on lines 1465 to 1470
// Start the mixer — it sums mic + system into a mono stream and forwards it to
// the transcription WebSocket.
audioMixer?.start { [weak self] monoMixed in
guard self?.isConversationListening == true else { return }
self?.transcriptionService?.sendAudio(monoMixed)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Cross-actor read of @MainActor-isolated property from audio thread

AppState is @MainActor-isolated, so isConversationListening must only be accessed from the main thread. The closure passed to audioMixer?.start runs on whichever background thread the audio subsystem uses, making self?.isConversationListening a cross-actor access. A matching problem exists in the conversationAudioHandler closure at the BLE path (line 1566). Under Swift 6 strict concurrency this is a compile error; under Swift 5.x it is a runtime data race that can yield stale reads. Dispatch the check to the main actor, or promote both closures to @MainActor to keep the isolation correct.

Comment thread desktop/Desktop/Sources/AppState.swift Outdated
Comment on lines +1252 to +1254
isConversationListening = on
persistedConversationListening = on
UserDefaults.standard.set(on, forKey: Self.conversationListeningDefaultsKey)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Triple-write to the same UserDefaults key

@AppStorage already synchronises persistedConversationListening to UserDefaults automatically. The explicit UserDefaults.standard.set(on, forKey:) call on the line below is redundant and could mislead future readers into thinking @AppStorage doesn't update the store itself.

Suggested change
isConversationListening = on
persistedConversationListening = on
UserDefaults.standard.set(on, forKey: Self.conversationListeningDefaultsKey)
isConversationListening = on
persistedConversationListening = on

mvanhorn added a commit to mvanhorn/omi that referenced this pull request May 7, 2026
…or isolation, UserDefaults)

- P1 (resume doesn't restart): setListening(true) now calls startTranscription()
  when not already transcribing. The existing startTranscription guards
  (isConversationListening + device/mic) keep the no-op cases safe.
- P1 (cross-actor read on audio thread): added a nonisolated NSLock-guarded
  conversationListeningSnapshot, updated from setListening on the MainActor.
  Both the audio mixer closure (~line 1483) and the BLE conversationAudioHandler
  (~line 1582) now read snapshotIsConversationListening() instead of the
  @MainActor-isolated isConversationListening, removing the runtime data race
  under Swift 5 and the strict-concurrency error under Swift 6 without paying a
  main-actor hop per audio chunk.
- P2 (triple-write to UserDefaults): dropped the explicit
  UserDefaults.standard.set call; @AppStorage already syncs
  persistedConversationListening, and the new helper updates the in-memory
  snapshot only.
@mvanhorn

mvanhorn commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 7609650:

  • P1 (resume doesn't restart): setListening(true) now calls startTranscription() when not already transcribing; startTranscription's existing guards keep no-permission / no-device cases safe.
  • P1 (cross-actor read): added a nonisolated NSLock-guarded conversationListeningSnapshot mirror, updated from MainActor in setListening. Both audio closures (mixer at ~1483, BLE conversationAudioHandler at ~1582) now read snapshotIsConversationListening() instead of the @MainActor-isolated property. Removes the runtime race under Swift 5 and the strict-concurrency error under Swift 6 without paying a MainActor hop per audio chunk.
  • P2 (triple-write to UserDefaults): dropped the explicit UserDefaults.standard.set call; @AppStorage is the sole writer of persistedConversationListening. The new setConversationListeningSnapshot only touches the in-memory mirror.

Verified locally: swiftc -parse passes on AppState.swift. CI should run the full Lint & Format Check on push; full Xcode build wasn't reproducible in my local environment (no Xcode toolchain matching the workflow's Flutter image) so I'm relying on CI for the link/build verdict.

@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.

desktop feature but mergeStateStatus BLOCKED — approve only

@Git-on-my-level Git-on-my-level added desktop enhancement New feature or request labels Jun 26, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this, @mvanhorn — solid implementation of #6649. The feature fits the request well: one-click toggle, clear indicator across three surfaces, persistence, and a rebindable hotkey. Nice touch keeping Push-to-Talk independent.

A few observations from reviewing the current head (7609650):

Note on the Greptile P1 comments above: those appear to be from an earlier revision. The current code already addresses both:

  • Resume path: setListening(true) calls startTranscription() (lines ~1259-1261), so transcription does restart on resume.
  • Cross-actor access: both audio callbacks (audioMixer?.start and the BLE conversationAudioHandler) read via snapshotIsConversationListening() backed by an NSLock-guarded snapshot (conversationListeningSnapshot), updated atomically in setListening. No unsound @MainActor reads from the audio thread.

Merge conflict: GitHub reports this as dirty — likely conflicts with the now-merged #6770 which also touched FloatingControlBarWindow.swift. A rebase onto main is needed before this can land. The init signature change here (adding appState:) is additive, so the rebase should be straightforward.

Minor (optional): The explicit UserDefaults.standard.set(on, forKey:) in setListening is redundant since @AppStorage("omi.listening.enabled") already syncs persistedConversationListening to the same key. Harmless but could be dropped for clarity.

Once rebased, this looks good to me. Appreciate the included test for persistence across reloads.

@Git-on-my-level

Copy link
Copy Markdown
Member

Independently verified the current head (7609650) against the earlier Greptile notes — both concerns are resolved in the actual source:

  • Resume path calls startTranscription() when turning listening back on (not just flipping the flag), so transcription restarts correctly.
  • Cross-actor access is fixed: both audio callbacks read via the NSLock-guarded snapshotIsConversationListening() mirror instead of touching the @MainActor-isolated property from background audio threads.

Feature fits #6649 well — clean implementation that follows the existing shortcut/analytics patterns. The only thing between this and merge is a rebase onto main (conflicts from the merged #6770 in FloatingControlBarWindow.swift); the init-signature change here is additive so it should be straightforward. Once rebased, this should be good to go.

Thanks @mvanhorn!

@Git-on-my-level Git-on-my-level added the needs-rebase PR has merge conflicts / is behind main and needs rebasing label Jun 26, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @mvanhorn — independently reviewed the current head (7609650) and confirming the code itself is solid:

  • Resume path correctly calls startTranscription() when turning listening back on, so capture restarts as expected.
  • Cross-actor safety is handled well — both audio callbacks read via the NSLock-guarded snapshotIsConversationListening() snapshot rather than touching the @MainActor-isolated property from background audio threads.
  • startTranscription()'s guard isConversationListening correctly blocks auto-start triggers (BLE reconnect, etc.) while paused.
  • Shortcut wiring, persistence, analytics, and the three UI surfaces all follow the existing patterns cleanly.

Heads up on the rebase: this branch is ~3100 commits behind main and the desktop tree was restructured on June 11 — desktop/Desktop/ moved to desktop/macos/Desktop/. So all ten files here will need to relocate to the new path on rebase, not just resolve line conflicts. It's more involved than a typical rebase, but the changes themselves are self-contained and should port cleanly to the new location.

The needs-rebase label is accurate. Once the files move to desktop/macos/Desktop/Sources/... and conflicts resolve, this should be good to go.

@undivisible undivisible added human Human-authored pull request privacy-review Touches user-data persistence, permissions, or privacy-sensitive surfaces labels Aug 10, 2026
@mvanhorn
mvanhorn force-pushed the feat/6649-desktop-listening-toggle branch from 7609650 to 6c7b738 Compare August 11, 2026 03:23

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this well-structured feature — the listening-pause toggle with persistence, a rebindable hotkey, and multiple UI surfaces is a cohesive answer to #6649. The NSLock-guarded snapshot for audio-callback access and the GlobalShortcutManager fix (passing the actual HotKeyID instead of hardcoding askOmi) are solid. Requesting changes for two concrete CI failures plus the rebase:

1. SwiftLint omi_inline_userdefaults_key violations (ShortcutSettings.swift:339, :650) — the new shortcut_toggleListeningEnabled and shortcut_toggleListeningKey UserDefaults accesses use inline string keys. The repo requires typed keys via DefaultsKey.swift. (Note: the existing askOmiEnabled follows the same pre-rule pattern, but new code must comply with the active rule.)

2. Line-count ratchet exceeded on 4 files (AppState+Transcription.swift 1608→1653, FloatingControlBarView.swift 2704→2745, FloatingControlBarWindow.swift 4934→4952, SidebarView.swift 1507→1545). Either split the new logic into extensions/subviews or raise each baseline with a one-line justification in the corresponding JSON under .github/scripts/product_file_line_count_ratchet_baseline/.

3. The needs-rebase label is present — please rebase onto main.

Per-file notes:

  • AppState.swift — @AppStorage + inline UserDefaults.standard.object initializer is reasonable. The toggleListeningShortcutObserver cleanup in deinit is correct.
  • AppState+Transcription.swift — The guard in startTranscription() correctly prevents auto-start while paused. The conversationAudioHandler closure with snapshotIsConversationListening() gating properly drops audio frames at the source when paused — good privacy posture. Minor: snapshotIsConversationListening() is private but setConversationListeningSnapshot() is not; consider consistent visibility.
  • BleAudioService.swift — Adding conversationAudioHandler as a separate channel (with transcriptionService now nil for BLE) is clean — it decouples audio delivery from transcription ownership and lets the listening gate control flow.
  • GlobalShortcutManager.swift — The IdentifiedHotKeyRegistrar refactor passing hotKeyIDRawValue through to registerWithCarbon fixes a latent issue where all hotkeys shared askOmi.rawValue as their Carbon EventHotKeyID.
  • FloatingControlBarView.swift — @ObservedObject var appState: AppState = AppState.current ?? AppState(): the AppState() fallback creates a throwaway instance if AppState.current is nil, which could diverge from the real app state. Consider making it optional or asserting.
  • FloatingControlBarWindow.swift — The designated init(appState:) + convenience fallback is a clean DI pattern.
  • ShortcutSettings.swift — Follows the existing askOmi shortcut structure faithfully; just needs DefaultsKey.swift migration for the lint rule.
  • ShortcutsSettingsSection.swift — The toggle-listening key card mirrors the askOmi card pattern well.
  • SidebarView.swift — The listening toggle button with ear.fill/ear.slash.fill and color states is clear UX.
  • AnalyticsManager.swift — listeningToggled emits standard Sentry breadcrumb + PostHog event — consistent with existing telemetry patterns.
  • AppStateListeningTests.swift — Good coverage of persistence/reload. Consider adding a test for the audio-gating behavior (paused state drops frames).

Leaving for human maintainer review for the listening-pause product/UX direction and the privacy implication of audio-capture gating.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@mvanhorn
mvanhorn force-pushed the feat/6649-desktop-listening-toggle branch from 6c7b738 to fff6b3e Compare August 13, 2026 15:59
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Pushed the changes:

  • Both listening shortcut defaults moved to typed DefaultsKey cases.
  • Removed the throwaway AppState() fallback in FloatingControlBarView; callers now inject canonical state.
  • Raised the four line-count baselines with per-file justifications.
  • Added behavioral coverage proving paused listening actually drops audio frames.

I kept the snapshot setter internal because AppState.swift initializes it across a file boundary.

Tests: AppStateListeningTests 2/2, defaults/shortcut/floating-bar 16/16, the line-count ratchet plus its 10 tests, and SwiftLint clean.

@cursor
cursor Bot force-pushed the feat/6649-desktop-listening-toggle branch from 95fc863 to d129149 Compare August 16, 2026 17:59
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (it was 427 commits behind) and pushed.

The new shortcut keys go through DefaultsKey. The line-count ratchet directory is gone on main, so that check no longer applies. needs-rebase should clear now that the branch is current.

@mvanhorn
mvanhorn force-pushed the feat/6649-desktop-listening-toggle branch 2 times, most recently from 4b369ea to 56ad805 Compare August 22, 2026 19:36
@mvanhorn

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level all three are addressed and CI is green on 56ad805.

SwiftLint typed keys were already on the branch: DefaultsKey.swift declares shortcutToggleListeningEnabled and shortcutToggleListeningKey, and ShortcutSettings.swift uses them rather than inline strings. Nothing to change there.

Line-count ratchet: added the four Line-Count-Exception entries. Two needed a second pass because main moved while I was working and the declared numbers no longer matched the diff.

Rebase: you were right to ask for it and I initially dismissed it because the PR reported mergeable. It was still needed. CI diffs against an older main than I had fetched, and that alone was failing desktop-e2e-flow-coverage. Rebasing onto current main cleared it.

Clearing those surfaced two more gates, both now satisfied: failure-class-protocol (declared Failure-Class: none in the PR body, which is where the checker reads it, rather than rewriting the commit) and desktop-changelog-entry (added a fragment under desktop/macos/changelog/unreleased/).

@aryanorastar

Copy link
Copy Markdown
Collaborator

Maintainer note on 56ad805: the Aug 12 review items (typed DefaultsKey, line-count exceptions, path rebase onto desktop/macos) look addressed on this SHA. I am not approving it.

This head is CONFLICTING/DIRTY again on DefaultsKey.swift and SidebarView.swift. Please rebase onto current main — do not resolve those in the web editor.

The larger issue: main already has a listening control. CaptureListeningLogic.cycleListening is Off → Always On → Only Meetings from the dashboard and the top bar (#11520 / #12810). This PR adds a second persisted flag (isConversationListening) plus UI that can say “Listening” independently of that mode. #6649 is still real (pause without quitting, hotkey), but two sources of truth will drop recordings. After rebase, this pause needs to be the same state machine as audioRecordingMode (or an explicit overlay on it with tests), not a parallel @AppStorage.

Also please state in the PR that pause keeps mic/BLE up and only gates transcription — that is the privacy behavior, and it is not the same as Off.

@mvanhorn
mvanhorn force-pushed the feat/6649-desktop-listening-toggle branch from 56ad805 to 0a8dffb Compare September 19, 2026 01:32
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and reworked the state handling. Thanks for the detailed note, the two-sources-of-truth concern was right.

On the rebase: main had deleted SidebarView.swift in the duplicate-destination-UI refactor, and this PR was still modifying it. I took the deletion, so the parallel sidebar listening UI is gone rather than resurrected. DefaultsKey.swift resolved cleanly, keeping both sides' additions. The branch is now current with main and conflict-free.

On the design: pause is now an explicit overlay on audioRecordingMode rather than a parallel @AppStorage flag.

  • isTranscriptionPaused is the only stored pause state, and it never writes audioRecordingMode
  • isConversationListening is now a computed projection of (mode != .off && !paused), not a stored flag, so the two cannot disagree
  • CaptureListeningLogic.shouldForwardTranscriptionAudio(mode:isPaused:) is the single decision point shared by the UI and the audio path

To state the privacy behavior explicitly, as you asked: pause keeps the mic and BLE capture up and gates only transcription forwarding. It is deliberately not equivalent to Off, which tears capture down. The mode control still reads Always On / Only Meetings while transcription is gated.

Tests cover pause and resume across every audioRecordingMode, asserting the mode is never mutated, capture stays up, and only forwarding is gated.

Also fixed the three review-bot findings: the audio callbacks now read a lock-protected snapshot through a nonisolated helper instead of touching @MainActor state from the audio thread, the duplicate @AppStorage write to the same key is gone, and the resume asymmetry disappears because pause no longer tears transcription down at all.

swift build succeeds and the listening tests pass locally (37 tests, 0 failures).

@aryanorastar

Copy link
Copy Markdown
Collaborator

Re-review on 0a8dffb.

The overlay rewrite is the right shape: isTranscriptionPaused does not write audioRecordingMode, isConversationListening is computed from CaptureListeningLogic.shouldForwardTranscriptionAudio, and the tests pin pause/resume across every mode without tearing capture. The SidebarView resurrection is gone. That answers the two-sources-of-truth note on 56ad805.

I am not approving this SHA.

Hygiene is red on product-file-line-count-ratchet:

  • AnalyticsManager.swift grew 1795 -> 1812 with no Line-Count-Exception
  • AppState+Transcription.swift exception is stale (1738 -> 1786 vs actual 1830 -> 1884)
  • unused exception for SidebarView.swift (file is not in this diff)
  • refresh FloatingControlBarView / FloatingControlBarWindow to current main (3226 -> 3267 and 6081 -> 6099) in the same body edit

Also: the control-bar pill binds to isConversationListening, so mode Off renders as "Paused". Toggling then mutates the overlay and still shows Paused. Off and pause are not the same state — the pill needs a third label, or it should be disabled/hidden when mode is Off.

kodjima APPROVE is on 7609650. Git-on-my-level CHANGES_REQUESTED is on 6c7b738. Neither is this tip.

Honest gaps: no on-device smoke (mic/BLE stay up while transcription is gated).

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Both points addressed on a new SHA.

The pill was the real bug. It bound straight to isConversationListening, so mode Off rendered as "Paused" and toggling mutated the overlay behind a label that never changed. Off now has its own state: CaptureListeningLogic.ConversationListeningPill derives listening / paused / off from (mode, isPaused), both control-bar surfaces render pill.title and are disabled when the mode is Off, and toggleConversationListening returns early in Off so the overlay is never written from a state the user cannot see. Tests pin that Off reads "Off" and not "Paused", and that toggling in Off leaves both the overlay and the mode alone.

Ratchet declarations are rebuilt against current main (da2fe60) rather than patched:

  • AnalyticsManager.swift 1795 -> 1812, added, it was missing
  • AppState+Transcription.swift 1830 -> 1885, was 1738 -> 1786
  • FloatingControlBarView.swift 3226 -> 3282, was 3012 -> 3053
  • FloatingControlBarWindow.swift 6081 -> 6099, was 5309 -> 5327
  • SidebarView.swift declaration removed, the file is not in this diff

Those four are every changed non-test Swift file over the 1500-line threshold; CaptureListeningLogic.swift is 172 -> 217 and stays under it.

Honest gaps unchanged: still no on-device smoke, and I have not run the Swift suite locally on this SHA, so CI is the verification here.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Re-review on da0408a.

The two items from 0a8dffb are addressed on this SHA:

  • Off vs pause: ConversationListeningPill derives listening / paused / off from (mode, isPaused). Both control-bar surfaces render pill.title, are disabled when Off, and toggleConversationListening returns early so the overlay is not written from a state the user cannot see. testModeOffPillIsNotPausedAndToggleDoesNotWriteOverlay pins that.
  • Hygiene is green on this SHA. GitHub reports MERGEABLE against current main. The unused SidebarView exception is gone.

I am still not approving this SHA.

Honest gaps unchanged: no on-device smoke that mic/BLE stay up while transcription is gated. That is the privacy behavior, and it is not the same as Off.

kodjima APPROVE is on 7609650. Git-on-my-level CHANGES_REQUESTED is on 6c7b738. Neither is this tip — merge is still blocked by that review, not by the code on da0408a. I am not dismissing it.

…key (BasedHardware#6649)

Reimplemented on the restructured desktop tree after the original branch went
stale and began conflicting. Behavior matches the reviewed revision: persisted
listening state, NSLock-guarded snapshot reads from the audio callbacks, and
startTranscription() on resume.
mvanhorn and others added 5 commits September 21, 2026 09:38
Addressed the maintainer feedback with a 9-file working-tree diff:
- Migrated both listening shortcut defaults to typed `DefaultsKey` cases.
- Removed the throwaway `AppState()` fallback from `FloatingControlBarView`; callers now inject canonical state.
- Raised all four line-count baselines with focused justifications.
- Added behavioral coverage proving paused listening drops audio frames.
- Kept the snapshot setter internal because `desktop/macos/Desktop/Sources/AppState.swift` initializes it across a file boundary.
- `PASS` — `AppStateListeningTests`: 2/2
Addresses the review: the PR previously carried a second persisted flag
(isConversationListening) that could disagree with audioRecordingMode,
which risked two sources of truth dropping recordings.

Pause is now an overlay on the existing mode rather than a parallel
policy:

- isTranscriptionPaused is the only stored pause state, and it never
  writes audioRecordingMode
- isConversationListening becomes a computed projection of
  (mode != .off && !paused)
- CaptureListeningLogic.shouldForwardTranscriptionAudio is the single
  decision point, shared by the UI and the audio path

Pause keeps mic/BLE capture up and gates only transcription forwarding;
it is deliberately not equivalent to mode Off, which tears capture down.

Also resolves the review-bot findings: the audio callbacks now read a
lock-protected snapshot from a nonisolated helper instead of touching
@mainactor state from the audio thread, and the duplicate @AppStorage
write to the same UserDefaults key is gone.

Tests cover pause/resume across every audioRecordingMode, asserting the
mode is never mutated, capture stays up, and only forwarding is gated.
Re-review on 0a8dffb: the control-bar pill bound directly to
isConversationListening, so audioRecordingMode == .off rendered as
"Paused", and clicking it mutated the pause overlay while the label
stayed "Paused".

Off and pause are different states, so the pill now has three:

- CaptureListeningLogic.ConversationListeningPill derives listening /
  paused / off from (mode, isPaused), so the label has one source
- both control-bar surfaces render pill.title and are disabled when the
  mode is Off
- toggleConversationListening returns early when the mode is Off, so the
  pause overlay is never written from a state the user cannot see

Tests assert mode Off reads "Off" rather than "Paused", that toggling in
Off writes no pause overlay and leaves the mode alone, and that the
paused and listening labels are unchanged.
aryanorastar's remaining objection was that nothing proved the privacy
behavior: that gating transcription leaves mic and BLE capture running, which
is not the same as Off tearing them down.

Cover it three ways. AppStateListeningTests asserts across a pause/resume cycle
that the mic spy is never stopped or restarted, the BLE connection and its
transport stay connected with no disconnect calls, the codec is unchanged, and
BleAudioService.processingGeneration does not move, so a teardown followed by a
fresh start cannot hide inside the window. It then asserts Off does tear both
down.

Add ListeningHardwareSmokeTests for the on-device case, gated on
OMI_HARDWARE_SMOKE=1 so CI skips it. It has not been run on hardware.

BleAudioService gains a weak processingConnection and makes the existing
processingGeneration readable. SessionConnectionDouble can hold its audio
stream open so startProcessing completes without the stream ending.

Signed-off-by: Matt Van Horn <[email protected]>
@mvanhorn
mvanhorn force-pushed the feat/6649-desktop-listening-toggle branch from da0408a to f194324 Compare September 21, 2026 16:41
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Pushed f194324, rebased onto current main.

On the mic/BLE gap: you are right that nothing proved it, and I am not going to claim I closed it on hardware. What I did do is pin the contract three ways.

AppStateListeningTests now runs a full pause/resume cycle against the BLE connection double and asserts that across it the mic spy is never stopped or restarted, the connection and its transport stay connected with zero disconnect calls, the codec is unchanged, and BleAudioService.processingGeneration does not move. That last one is the load-bearing assertion: a teardown followed by a fresh startProcessing would bump the generation, and isProcessing alone cannot see that happen inside the window. The same test then asserts Off does tear both down, so the two states are distinguished rather than assumed.

ListeningHardwareSmokeTests is the on-device case, gated behind OMI_HARDWARE_SMOKE=1 so CI skips it. I have not run it. It is there so the check you asked for is runnable by someone with the hardware rather than described in a comment.

Production change is small and is real state, not test scaffolding: a weak processingConnection, and processingGeneration made readable. I had a version of this with explicit call counters on the service and threw it away, since that is test instrumentation living in a production type.

Locally: AppStateListeningTests 7/7, the start/stop race tests pass, hardware smoke skips as designed, SwiftLint clean on the changed files.

Separately, you noted merge is blocked by Git-on-my-level's CHANGES_REQUESTED on 6c7b738 rather than by the code on this tip. That is still true and still not mine to dismiss.

@aryanorastar aryanorastar 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 on f1943241b667.

The overlay rewrite still looks right: isTranscriptionPaused does not write audioRecordingMode, Off is a third pill state, and the hermetic BLE processingGeneration pin is the right contract for "pause does not tear capture down."

Hygiene and Desktop Swift tests are red on the same gate: desktop-test-quality wall-clock waits rose 16 → 17. The extra site is Task.sleep(for: .milliseconds(100)) in ListeningHardwareSmokeTests (the discovery loop). Annotate that line with // omi-test-quality: wall-clock-wait -- <reason> or wait on a deterministic signal. Do not raise the baseline for a skipped smoke.

OMI_HARDWARE_SMOKE=1 is still skipped here (no kit). That remains an honest gap, not a merge blocker by itself.

I am not approving or merging this SHA. kodjima APPROVE is 7609650. Git-on-my-level CHANGES_REQUESTED is 6c7b738. Neither is this tip; I am not dismissing that review.

The smoke test's discovery loop slept 100ms per iteration, which added a
seventeenth wall-clock wait to the desktop-test-quality count for a test that
is skipped without hardware.

Wait on the signal that already exists instead: DeviceProvider publishes
discoveredDevices, so the test awaits its first non-empty emission, bounded by
awaitWithTimeout using the same timeout passed to startDiscovery. The XCTSkip
path when no device is present is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Du315CaKLufAYPEdEwcocq
Signed-off-by: Matt Van Horn <[email protected]>
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the precise read on the gate. Fixed in d8fc92ec4.

I took the deterministic-signal option rather than the annotation, since the signal already exists: DeviceProvider publishes discoveredDevices, so the discovery loop now awaits its first non-empty emission instead of polling every 100ms, bounded by the project's own awaitWithTimeout with the same timeout already passed to startDiscovery. No annotation, and no new wall-clock wait, so the count should go back to 16 rather than up to 17. The XCTSkip when no device is present is unchanged.

Agreed on the rest: OMI_HARDWARE_SMOKE=1 staying skipped here is an honest gap, and I have not touched your review state.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Re-review on d8fc92ec4bdb.

The wall-clock item from f194324 is addressed: ListeningHardwareSmokeTests no longer uses Task.sleep. Discovery awaits DeviceProvider.$discoveredDevices via awaitWithTimeout. Hygiene and Desktop Swift tests are green on this SHA. GitHub reports MERGEABLE.

I am still not approving this SHA. OMI_HARDWARE_SMOKE=1 is skipped here (no kit). Pause gating transcription while mic/BLE stay up is still unproven on a device.

kodjima APPROVE is 7609650. Git-on-my-level CHANGES_REQUESTED is 6c7b738. Neither is this tip. I am not dismissing that review. Not merging.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review. Agreed the hardware path is the open question, and I don't have an Omi kit to run OMI_HARDWARE_SMOKE=1 against. Could someone on the team with a device run it, especially the pause case with mic/BLE still up? I'll rebase onto main in the meantime so it's ready once that's confirmed.

Conflicts:
- DefaultsKey.swift: keep transcriptionPaused/shortcut keys alongside
  main's callAppAudioDailyLedger.
- CaptureListeningLogic.swift: take main's armed/active split in
  listeningStatus; keep the pause overlay and ConversationListeningPill.
- ShellListeningCycleTests.swift: take main's deletion (BasedHardware#17286 replaced
  the cycle with a mode menu); port the pause-overlay test into
  ShellListeningModeMenuTests.

Annotate the two AppStateListeningTests shared-defaults sites as an
integration boundary so the test-quality gate stays at main's baseline.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NKrCf3fm1rFrX2sQqS1gif
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Merged current main into the branch (merge commit, no force-push), so it's ready whenever the hardware check happens.

Three conflicts. DefaultsKey kept both sides. CaptureListeningLogic takes main's new armed/active split in listeningStatus and keeps the pause overlay and pill as they were. ShellListeningCycleTests was deleted on main when #17286 replaced the cycle with the mode menu, so I took the deletion and moved the pause-overlay test into ShellListeningModeMenuTests instead of bringing the file back.

Main had lowered the shared-defaults baseline in the test-quality gate, which our AppStateListeningTests setUp/tearDown went over by two. AppState reads the pause flag from standard defaults at init with no seam, so I used the gate's integration annotation rather than widening AppState in this PR. Happy to add a seam instead if you'd prefer.

The line-count exceptions still hold as declared; growth is unchanged and I refreshed the absolute baselines in the description to current main.

The listening suites pass locally on Xcode 26.6 (59 tests, hardware smoke skipped). In the full desktop run, PipeProcessRunnerTests and TasksStoreOwnerBoundaryTests failed under load but pass in isolation; neither touches this change. OMI_HARDWARE_SMOKE=1 is still skipped here, so the pause case with mic/BLE still up needs someone with a kit.

Main's desktop UX contract (INV-UI-2) rejects literal scaledFont sizes;
micro is the same 10pt, so this is a no-op visually.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NKrCf3fm1rFrX2sQqS1gif
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for this contribution! Our review requested some changes (see above) and we haven't heard back in a while. If you're still working on it, just push a commit or leave a comment within the next 7 days. To keep the queue healthy we'll close this PR in 14 days if it stays inactive — and it can always be reopened once updates land. Happy to re-review!

@Git-on-my-level Git-on-my-level added the stale-candidate Candidate for kind stale follow-up label Oct 5, 2026
Conflict in AppState+Transcription.swift: main moved startMicrophoneAudioCapture
and configureSharedCaptureWatchdog to AppState+MicrophoneCaptureArming.swift and
wrapped local STT sinks in the armed-mic probe gate. Took main's layout and kept
the listening-pause gate (forwardConversationAudio) inside the probe gate,
including on the moved mixer path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019wSaUMZrtm6XSzwEcxavkv
@mvanhorn

mvanhorn commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level merged current main into the branch (merge commit, no force push) to clear the conflict. The only real conflict was AppState+Transcription.swift: main moved the mic arming code into AppState+MicrophoneCaptureArming.swift, so I kept main's layout and put the pause gate inside the new probe gate there.

The points from your Aug 12 review are addressed:

  • Typed keys: shortcut_toggleListeningEnabled and shortcut_toggleListeningKey go through DefaultsKey (d0fb8f5).
  • Line-count ratchet: the four Line-Count-Exception entries are in the PR body. The growth is the same after this merge and the checker passes against current main.
  • Rebase: superseded by this merge, branch is current with main.

Later feedback from aryanorastar is in too: pause as an overlay on audioRecordingMode (f1e031d), Off vs paused in the pill (aeda59d), and the mic/BLE stay-up tests (f194324, d8fc92e).

Ran swift build and the listening tests on the merged branch: 48 green, hardware smoke skipped. Could you take another look when you have a minute?

@aryanorastar aryanorastar removed the stale-candidate Candidate for kind stale follow-up label Oct 8, 2026
Offscreen renders of the production FloatingControlBarView compact bar
for listening, paused, and recording mode Off, captured through
NSHostingView in a local XCTest harness.
@mvanhorn

mvanhorn commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Added UI evidence for the preflight check: three renders of the control bar under .agent-artifacts/ui-evidence/7199/ showing listening (green), paused (amber), and mode Off (grey), linked in the PR body. They're offscreen renders of the real FloatingControlBarView from a local test harness, not a live app capture, so the hardware check for the pause path is still open.

@Git-on-my-level

Copy link
Copy Markdown
Member

Closing due to inactivity after requested changes — this is not a reflection on the idea. Feel free to reopen (or open a fresh PR referencing this one) whenever the updates are ready, and we'll gladly re-review. Thanks again for contributing!

@github-actions

Copy link
Copy Markdown
Contributor

Hey @mvanhorn 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

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

Labels

desktop enhancement New feature or request human Human-authored pull request needs-rebase PR has merge conflicts / is behind main and needs rebasing privacy-review Touches user-data persistence, permissions, or privacy-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: quick toggle + granular control for “listening” state

5 participants