Skip to content

fix(desktop): serialize mic watchdog reset - #10924

Merged
kodjima33 merged 2 commits into
mainfrom
codex/pr10917-review-followups
Jul 31, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
codex/pr10917-review-followups

Conversation

@undivisible

@undivisible undivisible commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes two remaining Codex findings from #10917:

  • Serialize silent-mic watchdog resets with HAL callback evaluation.
  • Preserve the supplied Oakley Meta device name in Listening status.

Checks:

  • swift-format lint passed.
  • desktop test quality passed.
  • Focused XCTest build compiled, but XCTest could not load Sparkle.framework in this fresh worktree.

Failure-Class: none


Note

Medium Risk
Touches real-time CoreAudio capture and silent-mic recovery threading; incorrect locking could miss or duplicate recovery, but scope is limited to watchdog bookkeeping and display strings.

Overview
Serializes silent-mic watchdog state so HAL audio callbacks and resetSilentMicWatchdog() (start/stop, PTT reuse) cannot race. A silentMicWatchdogLock guards window peaks, evaluation, and resets; the IOProc uses a per-buffer windowPeak merged under the lock and calls evaluateSilentMicWindowLocked without re-entering the public evaluator. Detection callbacks still run on the main queue after the lock is released.

Listening status for Meta glasses no longer always collapses to “Ray-Ban Meta”: when the input name contains “Oakley”, the UI shows the actual device name (e.g. Oakley Meta Vanguard).

Adds XCTest coverage for reset/re-arm behavior and Oakley title display, plus an unreleased changelog entry.

Reviewed by Cursor Bugbot for commit 68bb46e. Bugbot is set up for automated code reviews on this repo. Configure here.

@undivisible
undivisible marked this pull request as ready for review July 31, 2026 05:25

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1278a38f17

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// one-shot latch) so the watchdog observes recovery and can re-arm for a second
// episode — see `evaluateSilentMicWindow`.
let nowAbs = CFAbsoluteTimeGetCurrent()
let isBluetooth = Self.isBluetoothTransport(deviceID: deviceID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move the transport query out of the per-buffer path

handleAudioInput runs for every CoreAudio buffer, so moving isBluetoothTransport(deviceID:) above the one-second window check now executes AudioObjectGetPropertyData on every callback instead of once per watchdog window. That synchronous HAL query can block—especially while coreaudiod is recovering after sleep—and repeatedly performing it on the real-time IOProc thread can stall audio delivery and corrupt transcription. Cache the device transport or query it only when a watchdog window is ready for evaluation.

Useful? React with 👍 / 👎.

svc.detectSilentMicOnAnyTransport = true

XCTAssertNil(svc.evaluateSilentMicWindow(peak: 0, isBluetooth: false, now: 0))
svc.resetSilentMicWatchdog()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Make the reset test reproduce the race

This test performs evaluation, reset, and another evaluation entirely serially, so it already passes against the parent implementation where reset and the HAL callback are unsynchronized. It therefore cannot catch a regression in the synchronization this commit is intended to add; use a controllable barrier or equivalent seam to overlap reset with watchdog evaluation and assert the post-reset boundary outcome. Bug-fix regression tests are required to be capable of catching the repaired bug.

AGENTS.md reference: AGENTS.md:L28-L28

Useful? React with 👍 / 👎.

@undivisible
undivisible force-pushed the codex/pr10917-review-followups branch from 1278a38 to 68bb46e Compare July 31, 2026 06:05

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68bb46e648

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let nowAbs = CFAbsoluteTimeGetCurrent()
let isBluetooth = Self.isBluetoothTransport(deviceID: deviceID)
silentMicWatchdogLock.lock()
if windowPeak > watchdogWindowPeak { watchdogWindowPeak = windowPeak }

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 Badge Keep pre-reset audio out of the new watchdog window

When a parked capture is reset for adoption while the IOProc is converting a buffer, that callback can compute windowPeak before the reset, wait for the reset to clear the shared state, and then merge the old peak here after the reset returns. A loud frame from the previous turn can therefore mark the first post-reset silent window as non-silent and delay recovery by another watchdog window. Fresh production-path evidence beyond the existing test comment is that local peak computation occurs outside the lock with no reset epoch check; capture a watchdog generation before conversion and discard the peak if reset advanced it, or provide an equivalent boundary.

AGENTS.md reference: AGENTS.md:L41-L45

Useful? React with 👍 / 👎.

let handler = onSilentMicDetected
DispatchQueue.main.async { handler?(detection) }
}
detection = evaluateSilentMicWindowLocked(peak: watchdogWindowPeak, isBluetooth: isBluetooth, now: nowAbs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move the HAL lookup outside the watchdog lock

When silence reaches the firing threshold, this locked call constructs SilentMicDetection using currentDeviceDescription, which calls findBuiltInMicDeviceID() and performs several synchronous CoreAudio property queries. If coreaudiod is slow or wedged—the same condition this watchdog is intended to recover from—the IOProc can hold silentMicWatchdogLock for seconds while a main-thread stopCapture() or warm-capture reset blocks waiting for it, freezing capture controls or teardown. Snapshot the device identity outside the critical section or cache the description so the lock protects only in-memory bookkeeping.

Useful? React with 👍 / 👎.

@undivisible undivisible added bug Something isn't working macOS labels Jul 31, 2026

@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 bug fix: serializes silent-mic watchdog state against the HAL callback (real data race) and preserves the Oakley Meta device name; tests added, CI green.

@kodjima33
kodjima33 merged commit 9a2b8b2 into main Jul 31, 2026
39 of 40 checks passed
@kodjima33
kodjima33 deleted the codex/pr10917-review-followups branch July 31, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants