Skip to content

fix(audio): report and handle capture/session startup failures#49

Merged
missuo merged 4 commits into
missuo:mainfrom
erning:fix/audio-capture-error-handling
Apr 6, 2026
Merged

fix(audio): report and handle capture/session startup failures#49
missuo merged 4 commits into
missuo:mainfrom
erning:fix/audio-capture-error-handling

Conversation

@erning

@erning erning commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

When audio capture failed to start (e.g. device disconnection, format incompatibility), the app silently continued with the UI stuck in "recording" state and a Rust session waiting for audio that would never arrive. The user would eventually see a delayed "no speech recognized" error with no indication of the actual cause.

Return value propagation:

  • startCaptureWithAudioCallback: now returns BOOL instead of void; callers check the result and call handleAudioCaptureError: on failure
  • beginSessionWithMode: now returns BOOL; callers abort before starting audio capture if the Rust session fails to create
  • startAndReturnError: result is checked directly instead of relying on NSError being non-nil

Session cleanup:

  • handleAudioCaptureError: uses cancelSession instead of endSessionendSession only closes the audio channel, letting the session process empty input and emit a spurious "no speech recognized" error; cancelSession sets the cancelled flag so the session aborts cleanly

Error display protection:

  • Added showingError flag to prevent Rust-side state changes (cancelled, idle, failed) from overwriting the 2-second error display in both handleAudioCaptureError: and rustBridgeDidEncounterError:
  • Flag is cleared when a new session starts (hold/tap), preventing it from getting permanently stuck if the user retries within the error window

Test plan

  • xcodebuild passes
  • Disconnect audio input device, press hotkey — error notification appears and stays visible for 2 seconds
  • Immediately retry after error — new session starts normally, no stuck state
  • Trigger a Rust-side error (e.g. ASR connection failure) — error display stays for 2 seconds without flickering

erning added 4 commits March 31, 2026 18:40
Change startCaptureWithAudioCallback: return type from void to BOOL so
callers can detect failure. On failure, trigger handleAudioCaptureError
to end the Rust session, reset UI state, and notify the user instead
of silently producing no audio.
endSession only closes the audio channel, letting the session process
the empty input and emit a spurious "no speech recognized" error.
cancelSession sets the cancelled flag so the session aborts cleanly
without producing a duplicate error notification.
- Guard error UI state with showingError flag so Rust-side cancelled/idle
  state changes do not overwrite the 2-second error display
- Return BOOL from beginSessionWithMode: and abort early if the Rust
  session fails to start, instead of proceeding to audio capture
- Check startAndReturnError: return value instead of relying on NSError
  being non-nil
- Clear showingError when a new session starts (hold/tap), so the flag
  never gets stuck permanently if the user retries within the 2-second
  error window
- Apply the same showingError guard to rustBridgeDidEncounterError so
  Rust-side failed/idle state changes don't overwrite the error display
@missuo missuo merged commit 5132e93 into missuo:main Apr 6, 2026
@erning erning deleted the fix/audio-capture-error-handling branch April 7, 2026 02:02
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.

2 participants