fix(ios): dictation race/lifecycle bugs found in review#26
Merged
Conversation
A fresh code review of the audio/dictation stack surfaced real bugs: 1. Double-start crash (high): `state` only flips to .recording after the async recorder.start(), so two quick mic taps both saw .idle and both started — installing a second audio tap throws an uncatchable NSException. Add an `isStarting` guard set synchronously before the await. 2. Empty-audio dead path (medium): recorder.stop() returns WAVEncoder output, which always includes the 44-byte header, so `audio.isEmpty` was never true — a tap-with-no-speech got POSTed and came back as an error. Guard on `audio.count > WAVEncoder.headerSize` instead. 3. Stale interim leak (medium): LiveTranscriber.start() cleared `interim` only after the availability guard, so an unavailable recognizer could leave the previous session's words on screen. Clear it first (and in stop()). 4. Minor: a failed engine.start() left the session active + interruption observers installed; tear them down in the catch. Build- + test-verified (31 iOS tests). Co-Authored-By: Claude Opus 4.8 <[email protected]>
metaforismo
added a commit
that referenced
this pull request
Jun 11, 2026
Co-Authored-By: Claude Opus 4.8 <[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.
A fresh code review of the iOS audio/dictation stack surfaced real bugs (all in recently-written code):
stateflips to.recordingonly after the asyncrecorder.start(), so two quick mic taps both started → a secondinstallTapthrows an uncatchable NSException. Added anisStartingguard set synchronously before the await.recorder.stop()always returns ≥44 bytes (WAV header), soaudio.isEmptywas never true → a no-speech tap got POSTed and errored. Guard onaudio.count > WAVEncoder.headerSize.LiveTranscriber.start()clearedinterimonly after the availability guard → an unavailable recognizer could show the previous session's words. Clear first (+ instop()).engine.start()left the session active + observers installed; tear them down in the catch.Build- + test-verified (31 iOS tests).
🤖 Generated with Claude Code