Should the Mic Turn Back On?

Say someone is transcribing a meeting when their phone rings. The app starts pausing the session, but the call ends before the pause finishes. The OS signals that the app can resume. The meeting is still going, so turning the mic back on sounds reasonable.
Go back two seconds and suppose they had tapped Pause just before the phone rang. They'd expect the mic to stay off when the call ends. Or suppose the app has already queued a resume when they tap End. They should be able to put the phone down and keep talking, knowing the mic will stay off.
I work on client engineering at JAPAN AI. Our small team looks after several products, including our native iOS and Android apps. One thing that helps us keep both apps moving is starting each port with a spec. We write down what users should be able to do on both platforms and how we'll check it, then review each change against that spec as the coding assistant works from the existing app.
When we brought real-time transcription to Android, we used our iOS implementation as a reference. On iOS, if someone paused transcription themselves, the mic stayed off when the call ended. On Android, a foreground service handled audio focus changes and queued the work to resume transcription. During review, we found a case we'd missed in the spec: what if the service handled End before that queued work ran?
What we gave the coding assistant
In June, we gave the coding assistant the iOS code for the existing behavior, the Android repo (with its Compose UI, navigation, and networking modules) where the feature had to live, and a task plan broken down from the spec. For each reviewable change, the assistant suggested commands to verify the work and an engineer checked the results before confirming the commit. How interruptions worked on Android still depended on Android's own audio and service lifecycles.
In the iOS reference code, for instance, a Paused state says what the session is doing, not who paused it, so our iOS client tracks that separately. When an audio interruption starts, the client only marks the session as interrupted if transcription was live at the time. Once the interruption ends, it checks that flag alongside the system's shouldResume hint (see Apple's guide to audio interruptions). If the user paused the session themselves, resuming stays up to them.
How we split up the Android work
We split the Android port into three PRs so we could check each change before building on it. In the first, a unit test fed in a transcript update and checked that editing a segment preserved its translation, which we could verify before wiring up a microphone. The second PR connected a live session to the caption screen so we could start transcription, see the captions, and end the session. That left pause and resume, audio interruptions, and connection changes for the third PR, when we already had a working session to interrupt with a phone call.
The End button shows how an iOS behavior turned into concrete Android tasks across that split. On iOS, pausing closes the live connection while keeping the room ID and the latest transcript version ID the client has received. We kept the same split on Android: the UI sends the same stop command whether transcription is live or paused, and the session manager ends an active session over the connection or uses the saved IDs to finalize a paused one.
We tested what happens on Android when someone taps End after a pause. In the first test, the client has received a transcript version ID, so we expect one finalization request with the room ID and version ID, and no stop call on the old connection. In the second, the client has no version ID, so it skips the request and marks the session stopped locally. Both tests call stop() after the session has already reached Paused. Neither covers a call ending while the session is still Pausing.
When the call ends before pause finishes
On Android, audio focus changes act as inputs to the session (see Android's guide to audio focus). A transient loss of focus triggers a pause, while after a permanent loss the app won't resume until the user takes action. Regaining focus gives the app a chance to decide whether to pick back up. Before it can show "Transcribing" again, it has to connect, publish the microphone track, and wait for the transcription service to report that it's ready.
The tricky state here is Pausing. Pausing involves asynchronous work, and the OS can hand focus back before that work finishes. If the app ignores that callback, another one might never come, and if it reconnects too soon, the previous connection might still be shutting down. Both clients handle this by recording that a resume was requested, waiting until the session reaches Paused, and then consuming and clearing that pending request.

On Android, an interruption coordinator handles that transition, and our unit test checks it at two points. When audio focus returns while the session is still Pausing, the test expects NONE, and when the coordinator then receives Paused, it expects RESUME. Checking only the second result would let a bug slip through if the coordinator requested a resume both times. That test stops at the coordinator's return value, before the Android service acts on RESUME.
A race condition caught in AI review
Our spec covered what to do when audio focus returned during a pause, and because the coordinator test passed, we treated returning RESUME as the end of the decision. Reviewing the Android diff, our AI reviewer followed RESUME one step further into the foreground service, where that return value became a coroutine queued on Dispatchers.Main. Even though the session was eligible to resume when the coroutine was scheduled, a stop command handled on the main thread could still run before the coroutine started.
When the service handles End on the main thread, it sets stopping and clears currentSession before queuing the shutdown work. The manager captured by the resume coroutine can still report Paused at that point. Because the service stays in the foreground during a normal pause, a stale resume could update the foreground notification and then ask the old manager to resume.
We added the check inside the coroutine, right before either of those calls. Here's the relevant part in simplified Kotlin:
val target = currentSession ?: return
launch {
if (stopping || currentSession !== target || target.state != Paused) {
return@launch
}
updateForegroundNotification()
resumeSession(target)
}Each of those three conditions covers a different case: shutdown has already started, currentSession is no longer the instance the task was scheduled for, or that session is no longer Paused. The AI reviewer checked our follow-up change too. Its original comment was quick to verify: we only had to read a few lines and see which side of launch the check ran on.
Replaying the race with an agent
Because that launch block lived inside the Android Service alongside lifecycle and notification calls rather than in the plain-Kotlin coordinator, our existing unit tests didn't reach it, and tapping a screen won't reliably hit a single-turn gap on Dispatchers.Main. To sanity-check the ordering before testing on a device, we had an agent model that service queue in a small Python replay: hold the scheduled task, deliver End, and then let the task run.
At that point, stopping is set and currentSession is cleared, while the queued task still holds the old session reporting Paused. The replay counts calls to update the foreground notification and calls to resume.
| Replay | Foreground updates | Calls to resume |
|---|---|---|
| Deliver End before the queued task runs | 0 | 0 |
| Same order, remove only the check inside launch | 1 | 1 |
| Keep the check and let the meeting continue | 1 | 1 |
In the first two rows, the service handles End at the exact same point, and removing the check inside launch lets the old task reach both calls. The third row checks that a normal resume still goes through, since a guard that dropped every resume would pass the first case and fail the third.
That model only checks our branching logic, not Android's callbacks or the microphone. For the OS callback path, an agent can place and end a simulated call through the emulator console and check the logs to confirm that the app received the audio focus events. On a physical phone, I still check the audio itself: let transcription resume after a call, speak a fresh phrase, and look for those words in the transcript.
What we'd take to the next port
Going into this port, I thought the biggest advantage of using AI was handing it a working iOS app, and that did help. Splitting the Android work into three PRs mattered just as much, because each one gave us something concrete to verify, from preserving translations on a segment edit to interrupting a live session with a call. Keeping each step small meant our team could let the assistant carry familiar code across platforms and still read every diff closely enough to review it.
I'd write the next spec with that review in mind. Because we'd described when transcription should resume, I assumed we'd settled the behavior on both platforms, until the AI reviewer traced the request into the service and found a moment where the app still had a choice to make. Next time, I'd write down what the person in the meeting should be able to count on, such as the mic and active notification staying off once they tap End, and ask the reviewer to trace that rule all the way to the code that acts on it. Getting a second look at a decision I thought I'd already made turned out to be the part of working with AI I hadn't expected.