Repository navigation
fix(desktop): serialize mic watchdog reset - #10924
Conversation
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 👍 / 👎.
1278a38 to
68bb46e
Compare
There was a problem hiding this comment.
💡 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 } |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 👍 / 👎.
kodjima33
left a comment
There was a problem hiding this comment.
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.
Fixes two remaining Codex findings from #10917:
Checks:
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. AsilentMicWatchdogLockguards window peaks, evaluation, and resets; the IOProc uses a per-bufferwindowPeakmerged under the lock and callsevaluateSilentMicWindowLockedwithout 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.