iOS: harden dictation lifecycle (double-stop, dismissal teardown, stale interim, metering perf)#28
Merged
Merged
Conversation
…etering - DictationController.finishRecording is now idempotent (guard on .recording) so racing stop paths (double tap, interruption + route change, interruption vs user stop) can't both finalize; a generation counter discards in-flight starts/transcripts after cancellation - AudioRecorder.stop clears captured samples after reading them so a second stop can't return the same audio twice - KeyboardViewController.viewWillDisappear cancels active dictation via new DictationController.cancel(), so a dismissed keyboard stops the mic, ends the live preview, and drops the pending transcript - LiveTranscriber ignores late recognition results from a stale request (identity check against the current request) so stopped sessions can't republish interim text - Level metering: publishes throttled to ~15 Hz via a new pure RateLimiter helper, RMS computed with x*x instead of pow, and the Waveform child now observes the recorder itself so per-tick re-renders no longer hit the whole keyboard - Tests: RateLimiterTests cover the new throttling logic Co-Authored-By: Claude Fable 5 <[email protected]>
metaforismo
added a commit
that referenced
this pull request
Jun 11, 2026
Co-Authored-By: Claude Fable 5 <[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.
Fixes from a correctness review of the recently merged iOS dictation work (PRs #25/#26), verified at build + test time on a simulator.
finishRecording()was not idempotent (two quick stop taps; AirPods removal firing both interruption AND route-change notifications; an interruption racing a user stop) andAudioRecorder.stop()returnedpcmSampleswithout clearing them — the same WAV could be POSTed twice and the transcript inserted twice. Now guarded by a state check at the top offinishRecording()(@mainactor, no suspension point before the state flip) andstop()takes-and-clears the samples under the lock.AVAudioEnginekept capturing (orange mic indicator with no UI) and a late transcript could be inserted into whatever field the proxy pointed at later.viewWillDisappearnow cancels via a new generation-countedDictationController.cancel()that also discards in-flight start/transcription results.SFSpeechRecognizerresult delivered afterstop()could republish old words at the start of the next dictation; the result handler now ignores results from a request that is no longer current.RateLimiter(RMS skipped entirely when throttled,x*xinstead ofpow), and the waveform is isolated into a child view so the whole keyboard no longer re-renders 25–50×/sec — keyboard extensions live under tight CPU/memory budgets.Tests: +5
RateLimiterunit tests; full suite 36 green on a booted simulator;xcodebuild buildsucceeds withCODE_SIGNING_ALLOWED=NO.🤖 Generated with Claude Code