Repository navigation
fix(desktop): stop ambient recording stop/restart loop + stop-reason telemetry (SCA-526) - #17828
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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@ 76e3e1fRoot cause
Two confirmed mechanisms produce silent stop→re-arm cycles without user intent:
Unserialized conversation rotation.
finishConversationhad no re-entrancy guard — it bumpsrecordingGenerationand errors if the generation changes mid-flight.handleMeetingObservation(meeting-boundary edges) and the deferred.meetingEndedfinalizer inreconcileCaptureare guarded by different flags (meetingBoundaryInProgressvsmeetingEndFinalizationInProgress), so they could enterfinishConversationconcurrently. The loser returned.error, and the boundary path then calledstopTranscription()— a silent terminal stop — followed by persisted-intent auto-restart. Always-mode users saw this aserror/idleterminal cycles.Preferred-microphone reconnect = full session restart.
PreferredMicrophoneReconnectMonitorre-pinned the mic by callingprepareTranscriptionRestartAfterSettingsChange(), i.e.stopTranscription()+startTranscription()— aDesktop Recording Stopped/Startedpair and a new capture attempt on every qualifyingkAudioHardwarePropertyDevicesevent. A flapping Bluetooth headset churns that listener.Amplifier — paywall verdict disagreement.
freemium_threshold_reachedsetsisPaywalledand stops capture; the 60sfetchTrialMetadatapoll could immediately clear the flag when the two backend verdicts disagree, letting persisted-intent restore re-arm into the next rejection.Fix
finishConversationnow serializes onconversationRotationInFlightand returns.busy(not.error) to a contended caller;handleMeetingObservationtreats.busyas a queued edge (pendingMeetingStatereplay) and never stops the session for it..meetingEndedtask re-validatesmeetingBoundaryInProgressand live detector state before finalizing.stopTranscription(finalizationReason:)is idempotent for terminal emission (no doubleDesktop Recording Stopped) while still bumpingrecordingGenerationso in-flight rotations/restarts abort correctly; it still clears the user-facing error surface when the session is already down.reapplyPreferredMicrophone, which swaps theAudioCaptureServicein 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.isPaywalledset by an admission event cannot be cleared by the trial-metadata poll inside a 10-minute debounce window.Desktop Recording Stoppednow carriesfinalization_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 aserroreven if a call site forgetsnoteErrorTerminal(), so a future loop cannot hide insideidle_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.busycoalescing, 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 classifyerror(incl. on idle meetings wait);finalization_reasonkey-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 --stricton changed files — clean;swiftlintvia 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).run.shbuilt and launchedomi-omi.app(com.omi.omi-omi, source identitye12888a0f8, clean tree) ande2e/flows/capture-lifecycle.yamlran through the live automation bridge — 11/13 steps pass, including hermetic start → inject → meeting_start → meeting_end → stop withreason=user_stopfinalization and backend upload. The two failures are environmental and on code untouched by this diff: S7conversation_count_increased(server-side visibility of the uploaded test conversation lags the awaited count snapshot — upload itself succeeded, deterministic across two runs) and S12notification_state(seeded settings carry the meeting-notes notification category toggle off; the app loggedsuppressing meeting-notes notification because its category toggle is off).Failure-Class: new
Changelog: fragment added under
desktop/macos/changelog/unreleased/.