Repository navigation
fix(mobile): a granted microphone tap launches no permission activity, and an aborted start says so - #22150
Conversation
…activity Every Android mic tap raised GrantPermissionsActivity although RECORD_AUDIO was granted: Expo's askForPermissions path has no granted check and goes straight to delegateRequestToActivity. The activity pauses and resumes the React host for 50-115 ms. The module now answers from getPermissionsWithPermissionsManager when the permission is already held. iOS needs nothing: EXPermissionsService returns on a granted status before it reaches the requester. The resume behind that activity forces a tabs reconciliation, which can transiently clear the active handle and so flip canSend, the hook's `enabled`. That reached cancel() through the !enabled Effect -- the same cancel the user's own has -- so a tapped start ended at idle with nothing shown. abandonDictation now carries a reason: null is the user's cancel and stays silent, anything else reaches onError when a start or a recording was underway. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe Android audio module now returns existing microphone permission state before requesting permission. The mobile dictation hook distinguishes user cancellation from input closure. It preserves closure errors when asynchronous operations finish late and ignores stale operations that could alter a newer dictation session. New tests cover pending starts, cancellation, input closure, and stale aborts. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Android permission handling avoids redundant prompts, and dictation closure and stale asynchronous operations preserve the current session state. No actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed context, implementation changes, scope, race-condition coverage, and verification results. It does not provide the required linked issue, visual proof or an explicit N/A statement, completed testing checkboxes, or completed checklist items.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 77d0d2ae-656f-4992-af7e-898ea793628d
📒 Files selected for processing (5)
mobile/packages/expo-two-way-audio/android/src/main/java/expo/modules/twowayaudio/ExpoTwoWayAudioModule.ktmobile/src/hooks/mobile-dictation-input-closed-mid-start.test.tsxmobile/src/hooks/mobile-dictation-session-state.tsmobile/src/hooks/use-mobile-dictation-source.test.tsmobile/src/hooks/use-mobile-dictation.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
Important
One real race in the new abort path: abandonDictation writes status and fires onError after awaiting the cancel RPC, without checking whether a newer start has taken over. A stale abort can therefore paint error and emit a toast over an active recording. Details inline.
Reviewed changes
- Android permission fast path —
requestMicrophonePermissionsAsyncnow checkshasGrantedPermissions(RECORD_AUDIO)and resolves viagetPermissionsWithPermissionsManagerwhen already granted, so a granted tap no longer launchesGrantPermissionsActivity. Verified against[email protected]: the granted branch resolves the same bundle (granted: true,canAskAgain: true) with no activity and no asked-permissions-cache write; a null manager still rejects withE_NO_PERMISSIONS. - Abort reporting in
useMobileDictation—cancel()is split intoabandonDictation(reason); the!enabledEffect passes the newMOBILE_DICTATION_INPUT_CLOSED_ERROR_MESSAGEso a start the composer disables no longer ends in silence, while the user's own cancel stays silent. AstatusRefmirrors status for aborts between commit and passive effects. - Tests — new
mobile-dictation-input-closed-mid-start.test.tsxdrives both halves (disable reports, user cancel silent);use-mobile-dictation-source.test.tsslices updated. Both verified passing, and the new case does fail against the pre-change code.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…laced it
abandonDictation read what it would report before awaiting the desktop cancel,
and nothing re-checked identity after it resumed. A start landing inside that
round trip reaches recording, then the stale abort reported the closure over it
or idled it. It now captures the generation it bumps to and returns if the
generation moved, the guard the finish check and the desktop start already use.
capture.open()'s catch had the same hole: a rejection arriving after a disable
had already reported the closure ran applyStatus('idle') and rethrew, wiping it.
The catch now makes the same check the arm below it makes, and returns without
rethrowing, because the composer toasts whatever start rejects with.
Both races predate this branch; probed against b964336 with the same cases.
Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The delta since the prior pullfrog review (6e394ac033) is commit 51c664de23, which closes the stale post-await write races both review bots had flagged.
- Guarded
abandonDictationafter its cancel await — it now captures the generation it bumps to and returns if a newer operation moved it, so a disable or a user cancel that resolves late no longer reports over, or idles, the start that replaced it. - Guarded
capture.open()'s catch — returns when the generation moved or the composer is disabled, so a late microphone refusal neither resets a reported closure back toidlenor rethrows into the composer's toast. - Added
mobile-dictation-stale-abort.test.tsx— drives the stale disable report, the stale user cancel, and the late open rejection; each assertion fails against the pre-fix code.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

A granted microphone tap must not launch the permission activity
Two halves of one defect from the 2026-09-22 device run (
followup-device-c7-9.md§7,device-run-20260922T0037Z/enginefix/report.md): every mic tap on Android raisedGrantPermissionsActivityalthoughRECORD_AUDIOwas already granted, and the resume behind itended 2 of 4 tapped starts at idle with no toast, no banner and no error.
Fix 1 — the module asks only when it has to
ExpoTwoWayAudioModule.requestMicrophonePermissionsAsynccalledPermissions.askForPermissionsWithPermissionsManagerunconditionally. Expo's Android service takesthat straight to the activity:
askForPermissionsWithPromise→askForPermissions→askForManifestPermissions→delegateRequestToActivity→currentActivity.requestPermissions(...),with no granted check anywhere on the way. The translucent activity lives 50–115 ms and drives
onUserLeaveHint → onHostPause → onHostResumethrough the React host.Before,
RECORD_AUDIOalready grantedAfter,
RECORD_AUDIOalready grantedSame resolved bundle, no activity, no host pause, and no write to the asked-permissions cache. When
the permission is not granted the call is byte-for-byte the old one, so a first-run prompt and a
re-prompt after a denial are unchanged. A null permissions manager also keeps its old answer: the
?.leaves the ask arm, which rejects withE_NO_PERMISSIONS.iOS: not the same shape, so not changed
MicrophonePermissionRequester.swifthas no granted check either, but it does not need one.EXPermissionsService.askForPermissionUsingRequesterClassreads the current status first andreturns
onResult(permission)before it ever reaches the requester when the status is granted. Therequester's
AVAudioApplication.requestRecordPermissionis never called on a granted tap, and noactivity equivalent exists on that path.
There is no Kotlin test harness in this module (
android/src/holdsmainonly), which is why thecall sequences above stand in for one.
Fix 2 — a tapped start that stops before recording says so
canSendis the hook'senabled, and it isactiveHandle != null && tabType is a terminal's && connState === 'connected' && clientId != null.Established
The arm that returned a tapped start to idle in silence is
cancel()from the!enabledEffect.cancel()is also the user's own cancel: it bumped the generation, ended the capture, setidleand cleared the error, and nothing distinguished the two. The downstream arms then correctly stayed
quiet, because the generation had moved —
start()'s post-opencheck releasing the capture, andcancelStaleStartin the desktop start.connStatedoes not move across a short background. A connected relay is retained underRELAY_BACKGROUND_GRACE_MS(30 s), the nudge router only probes a healthy relay on resume, and theterminal foreground recovery is gated to iOS.
clientIdis the entry's device token and does notmove either.
Still open: what flips
canSendon that resumeactiveHandleis the remaining input, and this change does not establish what clears it. A tabsreconciliation that has not yet answered is ruled out.
use-mobile-session-tabs-reconciliation.tsdoes subscribe
AppStateand forcerefresh(true)on every'active', but an in-flight oromitting snapshot cannot null the handle:
resolveActiveSessionTabreturns null for empty tabs(
active-session-tab.ts:27,62) and both clearing arms testactivefirst(
use-mobile-session-tab-application.ts:180,199), so a null active falls through and the handle isretained — which is what the comment at
:198guards. The handle is nulled only when the snapshotnames a real active tab carrying no handle:
:181a terminal tab whoseterminalis not a string,:199a non-terminal tab. Both persist while that tab stays active, and on the device run theactive tab was a terminal with a live handle. So a healthy resume snapshot would not have cleared
it, and the trigger needs its own evidence.
The fix does not depend on that answer. It is pinned at the hook level: whatever flips
enabled, astart the user tapped now reports instead of ending in silence.
The change
The hook now separates the user's cancel from an abort it did not ask for.
abandonDictation(reason)is the one abort path;reason === nullis the user's cancel and stayssilent, and anything else reaches
onErrorwhen a start or a recording was actually underway. The!enabledEffect passesMOBILE_DICTATION_INPUT_CLOSED_ERROR_MESSAGE, which the composer alreadyrenders through its
onErrortoast. A disable arriving while idle still says nothing.Both device shapes are covered by the one change, because the report survives what follows it: the
post-
openrelease andcancelStaleStartboth only reset the status while the generation is stilltheirs, and the abort moved it.
Device evidence this matches
@b526fa+0 ms, abandoned +599 ms with no re-requesttearDown(), whose only JS caller iscapture.release()@67e07eeretained, notoggleRecording(true)capture.end()without a teardowncapture.end()without a teardown iscloseDictationAudio(), which the abort runs; the teardowncase is the post-
openrelease that follows an abort that moved the generation.Not changed, and why
onInterruptionstill routes through the silentcancel(). Another app taking the microphone isthe same class of involuntary stop, but no device evidence reaches it on this path and it has its
own tests; it is a separate follow-up.
stop()is in flight (processing) still discards the recording quietly.That is a stop the user tapped, not a start, and it is outside this change.
Lead verification
Lead gate on
6e394ac033againstb9643365ba: tsc 0, ratchet 0, all lint gates 0, changed-code quality passed, React Doctor 0;config/scripts251 files passed; mobile 809 files passed; no machine paths. The Kotlin arm has no unit harness; it is the same shape the phone-verified engine fix (#22132) took, and the next device run's dictation step is its proof.Round 2 — two stale writes after an await
Both review bots found the same class of defect: a write that resumes after an
awaitand lands ona dictation that is no longer the one it belongs to. Both are reproduced by
mobile-dictation-stale-abort.test.tsxand both predate this branch.abandonDictation, the post-await writewasUnderwayand the branch it picks are read beforeawait dictationSessionCancel.request(...),which is a full desktop round trip. A fresh
start()that lands inside it reachesrecording, andthen the held cancel resolves into a stale abort.
Red, the reporting branch:
A toast over a live recording. The silent branch is the same shape one step milder: a user cancel
whose response arrives late idled the recording that replaced it,
expected 'idle' to be 'recording'.The abort now captures the generation it bumps to and returns if the generation moved while the
cancel was in flight — the guard
isCurrentMobileDictationFinishand the desktop-session startalready use.
capture.open()'s catch, the unguarded resetIf
enabledgoes false while the open is pending, the disable reports the closure and bumps thegeneration. A late rejection from that open then ran
applyStatus('idle')and rethrew, wiping theclosure the user had just been shown:
expected 'idle' to be 'error'.The catch now makes the same check the arm below it already made,
generationRef.current !== generation || !enabledRef.current, and returns. It does not rethrow onthat path either: the composer toasts whatever
startrejects with, so a stale refusal would landon top of the closure. That matches
shouldReportin the desktop start, which returnsfalserather than throwing once its start is no longer current.
Both predate this branch
Probed against
b9643365bawith the same cases. A user cancel whose response arrived after a newerrecording started idled it (
expected 'idle' to be 'recording'), and a late open rejection did thesame. This branch did not introduce either race. What it added was a reporting branch through the
first one, which turns a silent wrong reset into a visible wrong toast.
Lead gate on 51c664d against b964336 (gate-dictation-51c664de23.log): tsc 0, ratchet 0, changed-code quality 0, react-doctor 0, anti-slop 0, max-lines 0, root-oxlint 0 (5 files), config/scripts 251 passed / 2 skipped, mobile 810 passed, machine-paths 0.