Skip to content

fix(desktop): stop ambient recording stop/restart loop + stop-reason telemetry (SCA-526) - #17828

Merged
Git-on-my-level merged 1 commit into
mainfrom
agent/m5-mbp-devin-swe-2/6ecaf22a5595
Sep 23, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
agent/m5-mbp-devin-swe-2/6ecaf22a5595

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the macOS ambient-recording stop/restart loop on stable 12371 (SCA-526): one conversation was being split into many by in-app stop→re-arm cycles (PostHog: 1,616 rapid Stopped→Started cycles / 380 users / 7d; build 12371 at 11.6% vs 3.1% on 12342). No closing keyword — tracking issue stays open for release verification.

Base: origin/main @ 76e3e1f

Root cause

Two confirmed mechanisms produce silent stop→re-arm cycles without user intent:

  1. Unserialized conversation rotation. finishConversation had no re-entrancy guard — it bumps recordingGeneration and errors if the generation changes mid-flight. handleMeetingObservation (meeting-boundary edges) and the deferred .meetingEnded finalizer in reconcileCapture are guarded by different flags (meetingBoundaryInProgress vs meetingEndFinalizationInProgress), so they could enter finishConversation concurrently. The loser returned .error, and the boundary path then called stopTranscription() — a silent terminal stop — followed by persisted-intent auto-restart. Always-mode users saw this as error/idle terminal cycles.

  2. Preferred-microphone reconnect = full session restart. PreferredMicrophoneReconnectMonitor re-pinned the mic by calling prepareTranscriptionRestartAfterSettingsChange(), i.e. stopTranscription() + startTranscription() — a Desktop Recording Stopped/Started pair and a new capture attempt on every qualifying kAudioHardwarePropertyDevices event. A flapping Bluetooth headset churns that listener.

  3. Amplifier — paywall verdict disagreement. freemium_threshold_reached sets isPaywalled and stops capture; the 60s fetchTrialMetadata poll could immediately clear the flag when the two backend verdicts disagree, letting persisted-intent restore re-arm into the next rejection.

Fix

  • finishConversation now serializes on conversationRotationInFlight and returns .busy (not .error) to a contended caller; handleMeetingObservation treats .busy as a queued edge (pendingMeetingState replay) and never stops the session for it.
  • The deferred .meetingEnded task re-validates meetingBoundaryInProgress and live detector state before finalizing.
  • stopTranscription(finalizationReason:) is idempotent for terminal emission (no double Desktop Recording Stopped) while still bumping recordingGeneration so in-flight rotations/restarts abort correctly; it still clears the user-facing error surface when the session is already down.
  • The preferred-mic monitor now calls reapplyPreferredMicrophone, which swaps the AudioCaptureService in place — session, conversation, and attempt identity survive; no Stopped/Started pair. Policy gains a 15s swap cooldown and refuses to re-pin onto the device a silent-mic heal already moved off, and the swap defers while the capture gate is mid-flight. Stale watchdog callbacks from a swapped-out service are identity-gated.
  • isPaywalled set by an admission event cannot be cleared by the trial-metadata poll inside a 10-minute debounce window.
  • Desktop Recording Stopped now carries finalization_reason (enum-backed, privacy-bounded — no error strings/device names), and every terminal stop site reports an honest reason (paywall, rotation_failed, silent_mic_exhausted, microphone_unavailable, device_unavailable, stt_fallback, system_sleep, app_terminated, recording_disabled, settings_change). Forced-termination reasons classify the capture-attempt outcome as error even if a call site forgets noteErrorTerminal(), so a future loop cannot hide inside idle_waiting_meeting.

Preserved behavior: 4-hour max_duration_rotation, explicit user stop, genuine meeting-boundary rotations, silent-mic terminal stop after bounded recovery.

Tests

  • RecordingStopRestartLoopTests (new): rotation .busy coalescing, double-stop suppression, in-place mic swap preserving session/attempt identity, healed-device refusal, gate-in-flight deferral, paywall debounce.
  • PreferredMicrophoneReconnectTests: cooldown and healed-device cases added.
  • CaptureAttemptOutcomeTelemetryTests: forced-termination reasons classify error (incl. on idle meetings wait); finalization_reason key-set contract on the stopped payload.

Verification

  • xcrun swift build -c debug --package-path Desktop — clean.
  • xcrun swift test --filter 'RecordingStopRestartLoopTests|PreferredMicrophoneReconnectTests|CaptureAttemptOutcomeTelemetryTests|TranscriptionSettingsRestartTests' — 39 tests, 0 failures; broader related sweep — 155 tests, 0 failures.
  • ./scripts/swift-format-wrapper.sh lint --strict on changed files — clean; swiftlint via preflight — 0 violations in 1755 files.
  • python3 .github/scripts/pr_preflight.py --lane local --base origin/main — 26/26 checks pass (incl. line-count ratchet, failure-class protocol, e2e flow coverage).
  • Named-bundle real-path exercise: run.sh built and launched omi-omi.app (com.omi.omi-omi, source identity e12888a0f8, clean tree) and e2e/flows/capture-lifecycle.yaml ran through the live automation bridge — 11/13 steps pass, including hermetic start → inject → meeting_start → meeting_end → stop with reason=user_stop finalization and backend upload. The two failures are environmental and on code untouched by this diff: S7 conversation_count_increased (server-side visibility of the uploaded test conversation lags the awaited count snapshot — upload itself succeeded, deterministic across two runs) and S12 notification_state (seeded settings carry the meeting-notes notification category toggle off; the app logged suppressing meeting-notes notification because its category toggle is off).

Failure-Class: new

Changelog: fragment added under desktop/macos/changelog/unreleased/.

Review in cubic

…dd stop-reason telemetry

Rapid Desktop Recording Stopped -> Started cycles (1-150s gaps) hit 380
users on stable 12371, splitting one conversation into many. Three
mechanisms produced silent cycles:

1. finishConversation had no re-entrancy guard: a meeting-boundary edge
   and the deferred .meetingEnded finalizer could enter it concurrently,
   collide on recordingGeneration, and surface the loser as .error -- the
   boundary path then hard-stopped the session and persisted intent
   re-armed it. finishConversation now serializes on
   conversationRotationInFlight and returns .busy; the boundary caller
   requeues the edge via pendingMeetingState instead of stopping.

2. PreferredMicrophoneReconnectMonitor restarted the whole transcription
   session (stop + start, new attempt, Stopped/Started telemetry pair) on
   every qualifying device-list event. It now re-pins capture in place
   through reapplyPreferredMicrophone, preserving session and attempt
   identity, with a 15s swap cooldown and a healed-device pin so a
   silent-mic fallback cannot be undone by a flapping device list.

3. A freemium_threshold_reached admission stop could be immediately
   unlatched by the 60s trial-metadata poll when the two backend verdicts
   disagree, looping stop -> re-arm -> rejection. The admission-set flag
   now holds for a 10-minute debounce window.

stopTranscription takes a bounded TranscriptionFinalizationReason that
propagates to Desktop Recording Stopped as finalization_reason, so
stop->start cycles self-attribute in PostHog. Forced-termination reasons
classify the capture-attempt outcome as error even without an explicit
error mark, so a future loop cannot hide inside idle_waiting_meeting.
Redundant stops still bump recordingGeneration (in-flight rotations and
the settings restart abort on the change) but no longer re-emit the
terminal event.

Failure-Class: new

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: multica-agent <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit de517cf into main Sep 23, 2026
47 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m5-mbp-devin-swe-2/6ecaf22a5595 branch September 23, 2026 20:04
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