Skip to content

fix(desktop): keep PTT dead-mic recovery armed across zero-frame turns (#9081) - #9677

Closed
kodjima33 wants to merge 1 commit into
mainfrom
watchdog/issue-9081-ptt-dead-mic-recovery
Closed

kodjima33 wants to merge 1 commit into
mainfrom
watchdog/issue-9081-ptt-dead-mic-recovery

Conversation

@kodjima33

@kodjima33 kodjima33 commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

Fixes #9081. Desktop health telemetry shows ptt_audio_capture_silent_turn on macOS 0.12.0 hold mode affecting 169 users / 1,104 events, every one of them reporting recovery_action=none, recovery_result=not_attempted. PTT has a dead-mic self-heal — it simply never fired for the users who needed it, so a dead microphone stayed dead turn after turn with no recovery attempted.

Root cause

PTTSilentMicRecoveryPolicy.recordDiscardedTurn (PushToTalkManager.swift) decides whether consecutive silent turns should trigger a CoreAudio capture rebuild:

if totalSec >= Self.minDeadTurnSeconds && peak <= Self.deadMicPeakThreshold {
  consecutiveDeadMicTurns += 1
} else {
  consecutiveDeadMicTurns = 0   // <-- any turn under 0.25s lands here
}

Every turn shorter than minDeadTurnSeconds (0.25s) fell into the else branch and reset the dead-mic streak. Crucially that includes turns which captured no frames at all: startMicCapture starts CoreAudio asynchronously (AudioDeviceStart is blocking HAL IPC to coreaudiod), so a key release that beats capture start finalizes a turn with totalSec = 0, peak = 0. Such a turn says nothing about mic health, but it erased the evidence — so with a dead mic interleaved with ordinary taps, consecutiveDeadMicTurns never reached the threshold of 2 and recovery was never requested. All four recordPTTSilentTurn call sites (hub, omni, batch, warm-wait fallback) derive recovery_action/recovery_result from this one return value, which is why the field data is uniformly none/not_attempted.

The failure class: absence of evidence was treated as evidence of health.

Fix

Make each outcome carry only the evidence it actually has:

  • audible input (peak > deadMicPeakThreshold) proves the mic is alive → reset the streak
  • a judgeable silent turn (totalSec >= minDeadTurnSeconds, near-zero peak) → increment
  • a too-short / zero-frame turn → neutral, leave the streak intact

Three-line behavior change in the policy struct; no call sites, thresholds, or telemetry fields changed.

Verification

  • Regression test PTTSilentMicRecoveryPolicyTests.testZeroFrameTurnDoesNotEraseDeadMicStreak reproduces the field scenario (dead turn → zero-frame turn → dead turn). It fails on the old code (consecutiveDeadMicTurns 0 instead of 1; recovery never returns true) and passes on the fix. Added testAudibleShortTapResetsDeadMicStreak to pin the other direction.
  • xcrun swift test --package-path Desktop --filter "PTT|PushToTalk|VoiceTurn|DesktopDiagnostics" → 65 tests, 0 failures (incl. PTTAudioCaptureRaceTests, PTTSilentTurnRecoveryWiringTests, PushToTalkStateMachineTests, DesktopDiagnosticsManagerTests).
  • xcrun swift build -c debug --package-path Desktop → green.
  • make preflight → green.

Hermetic unit coverage of a pure policy struct; not exercised against a physically dead microphone on prod hardware.

Product invariants

Path-matched by desktop/macos/Desktop/Sources/FloatingControlBar/PushToTalkManager.swift:

  • INV-CHAT-1 — unchanged. No chat write-path, provider, projection, or viewport code is touched; no message store or turn-recording behavior changes.
  • INV-VOICE-1 — preserved and strengthened. The voice-turn state machine, capture lifecycle, and silence gating are untouched; the only change is when the existing dead-mic recovery is allowed to arm, so a silent capture is more likely to self-heal rather than less.

Follow-up (not in this PR)

The zero-frame turns themselves come from the release beating asynchronous CoreAudio capture start. Closing that race means changing the turn state machine's capture-start/finalize ordering — a wider blast radius than this fix warrants, and it remains tracked by #9081's investigation items.

🤖 automated by the hourly desktop bug watchdog.

Review in cubic

@kodjima33

Copy link
Copy Markdown
Collaborator Author

CI status: the one red check is pre-existing on main, not from this PR

Desktop Swift Build & Tests fails on HubSystemInstructionTests.testRealtimeListAgentSessionsToolIsExposed — realtime hub tool exposure, untouched by this diff (which only changes PTTSilentMicRecoveryPolicy + its tests).

Reproduced on unmodified origin/main (fec07c184f, "fix(macos): harden shared chat and PTT agent continuity (#9660)"), with no changes applied:

xcrun swift test --package-path Desktop --filter HubSystemInstructionTests/testRealtimeListAgentSessionsToolIsExposed
Test Case '-[Omi_ComputerTests.HubSystemInstructionTests testRealtimeListAgentSessionsToolIsExposed]' failed (1.284 seconds)
Executed 1 test, with 1 failure

So desktop CI on main is currently red and every desktop PR will inherit this failure until it is fixed. Worth a separate fix.

Everything this PR does own is green: 65 tests across PTT|PushToTalk|VoiceTurn|DesktopDiagnostics pass, debug build + release compile pass, make preflight passes.

Per the watchdog's auto-merge gate (which requires all required checks green before a prod deploy), this is left as a PR and not merged.

#9081)

PTT silent turns reported recovery_action=none / recovery_result=not_attempted
for 169 users on 0.12.0 (1,104 events), so a dead mic never self-healed.

Root cause: PTTSilentMicRecoveryPolicy.recordDiscardedTurn treated every turn
under minDeadTurnSeconds (0.25s) as evidence the mic was alive and reset
consecutiveDeadMicTurns. A turn that captured no frames at all - the key
release beating CoreAudio's asynchronous capture start - carries no evidence
either way, but it erased the streak, so the 2-turn recovery threshold was
never reached when a dead mic interleaved with taps. Absence of evidence was
being treated as evidence of health.

Fix: audible input (peak > deadMicPeakThreshold) resets the streak, a
judgeable silent turn increments it, and a too-short/zero-frame turn is
neutral.

Verification:
- New PTTSilentMicRecoveryPolicyTests.testZeroFrameTurnDoesNotEraseDeadMicStreak
  fails on the old code (streak 0, recovery never fires) and passes on the fix.
- xcrun swift test --filter "PTT|PushToTalk|VoiceTurn|DesktopDiagnostics":
  65 tests, 0 failures. Debug build green.
@github-actions

Copy link
Copy Markdown
Contributor

Hey @kodjima33 👋

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS PTT hold mode records silent turns for 169 users with no recovery attempted

2 participants