Repository navigation
fix(capture): one live source at a time; a phone pause keeps its conversation - #18839
Conversation
…ersation - Phone pause mutes, releases the mic and keeps the socket and recording id; resume unmutes and restarts only the mic (_resumeMicRecording). Before, Pause/Resume stopped and restarted the recording: a new client conversation id, so a second conversation, with the first stranded in_progress. - A user stop of a live phone recording restores the policy it started from, so it no longer leaves a (later) pendant muted. - An explicit phone start hands off a live pendant (BLE streams closed, its conversation processed) and the pendant resumes by itself when the phone stops, in its prior live/paused state. finishCapture() processes the phone conversation before that resume. Before, the phone socket replaced the pendant's while the pendant listener kept writing into it. - A pendant (re)connecting during a phone recording waits and never rolls the phone's capture session. - An Omi phone call pauses a streaming pendant and resumes it after. - pauseCapture/resumeCapture/finishCapture are the one API for the live page, the capture card and quick actions. Device-connection seam for tests. Failure-Class: FC-unowned-session-mutation-tears-down-live-capture Co-Authored-By: Claude Opus 5.5 <[email protected]>
…apture Failure-Class: FC-unowned-session-mutation-tears-down-live-capture Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| Future<void> _resumePhoneRecording() async { | ||
| final revision = await _setCaptureMuted(false); | ||
| if (!_admitsCapture(revision)) return; | ||
| _phoneMicPaused = false; | ||
| // The socket may have closed during a long pause; reopen it for the same recording. | ||
| if (_socket?.state != SocketServiceState.connected) { | ||
| await _initiateWebsocket(audioCodec: BleAudioCodec.pcm16, sampleRate: 16000); | ||
| } |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
A phone pause now keeps the authenticated /v4/listen socket and recording id, and resume reuses that socket whenever it is still connected. Sign-out does not stop this socket, and the new phone-owns path skips the session roll that device detach used to run, so the previous account's listen connection can remain current.
Impact: On a shared phone, the next account can resume into the previous account's already-authenticated listen socket. Later PCM frames are not re-bound to the signed-in user, so the new account's microphone audio can be transcribed into the previous account's open conversation.
Reviewed by Cursor Security Reviewer for commit 02b3e8e. Configure here.
- A call handoff outlives a pendant BLE drop; streamDeviceRecording returns early while a call is active (no transcript wipe, no session roll). - Phone handoffs and resumes share the call-switch queue; each step re-reads its condition. A phone start over a call-paused pendant takes the handoff. - The handoff closes the pendant's recording so the phone mints its own id. - A pause is not undone by stall/reconnect recovery or a Transcribe Later toggle; settings refresh follows the owning source; a superseded stop reports it, and Finish only resumes the pendant after a real stop. - A persisted marker restores the pre-recording policy after a process death. - Speech-profile onboarding keeps a handed-off pendant paused. - liveCaptureSource / liveCaptureStartedAt for the live card. Failure-Class: FC-unowned-session-mutation-tears-down-live-capture Co-Authored-By: Claude Opus 5.5 <[email protected]>




One live source at a time: a phone pause keeps its conversation, and the pendant hands off and comes back
This is PR 1 of 2 for the capture UX David approved on 2026-09-25 (storyboard: "Capture UX: live card + phone button"). It changes capture behaviour only. PR 2 builds the UI on top of it.
What was wrong on main
Each point below was reproduced by a failing test first. The run before the fix had 7 failures, and the output is quoted under Verification.
stopStreamRecording()and Unmute calledstreamRecording(). That minted a new recording id, which becomes a newclient_conversation_idon/v4/listen, so the backend created a second conversation. The first half stayedin_progress, because the server finalizes phone sockets on close only for desktop.streamRecording()→changeAudioRecordProfile()→_resetState()re-opened the pendant's BLE stream. The phone's PCM socket then replaced the pendant's, and the pendant listener kept writing its frames into it. The phone's stop then left the pendant muted.The fix
The capture policy stays the single durable mute authority (FC-split-mutation-authority); this PR adds no second mute flag. "Separate pause" (b) holds because only one source is ever live. A stop restores the state its recording started from, and a handed-off pendant is restored explicitly.
(a) Real phone pause.
pauseCapture()mutes first, which retires the in-flight callbacks. It then flushes the frames captured so far, releases the mic, and keeps the socket and the recording id.resumeCapture()unmutes, reopens the socket only if it closed, and restarts only the mic through_resumeMicRecording, so the conversation continues. A pause that outlasts the server's conversation timeout still splits on the backend's lifecycle loop, as it should.(b) The stop restores the pre-recording state. A user stop of a live phone recording mutes (retiring callbacks) and then restores the policy it started from. Transcribe Later keeps its mute across stop, unchanged.
(c) Explicit handoff. An explicit phone start with a realtime pendant streaming or user-paused hands the pendant off:
finishCapture()is the one Finish. It stops, processes the phone conversation, and then resumes the pendant, so the processing request cannot reach the pendant's next conversation. Other cases:(d) Omi calls.
PhoneCallProvider.callStateListenableis wired in production composition. Connecting, ringing and active pause a streaming pendant without touching the policy or its conversation, and the pendant resumes when the call ends. A user-paused pendant stays paused. Call-driven switches are serialized.API.
pauseCapture/resumeCapture/finishCaptureare now the one pause/stop API for the live page, the Home capture card, quick actions and the Home button. These call-site swaps are small; the UI redesign is PR 2. New getters for PR 2:pendantPausedForPhone,pendantPausedForCall,isPhoneMicPaused.Test seam. A device-connection seam (
deviceConnectionLoader) replaces the directServiceManager…ensureConnectioncalls inside the controller.ScriptedDeviceConnectionlets the replay world stream real BLE packets through the production path.Docs.
CAPTURE_POLICY.mdhas a new "Live sources" section, and its phone-stop rule is updated.Known gaps (deferred, with reasons)
CAPTURE_POLICY.md.source. This is unchanged; the backend defaults the source toomi, while the keep-alive reconnect sendsphone. It is out of scope here, and the tests assert only "not omi" for the phone socket.Verification (hermetic, Flutter 3.44.5, TZ=UTC)
Before the fix:
flutter test test/services/capture/capture_one_source_test.dartgave 2 passed and 7 failed:stop, notpause, because the recording ended.isPausedwastrueafter a phone stop, and a pendant connected afterwards came uppause.isPausedwastrue(the pendant was left muted), and a user-paused pendant ended instop, notpause. One (c) assertion was wrong in the first draft: phone sockets on main declare no source. I corrected it to assert "not omi".The socket-mixing half of (c) is established by reading the code, not by a failing run: the corrected assertion was not re-run against main. After the fix, the test asserts that no pendant bytes reach the phone socket and that the pendant stream is closed.
After the fix: 17 of 17 pass. That covers the 9 above plus Finish ordering, pendant connect and disconnect during a phone recording, the live-source getter, and the Grok-review scenarios (BLE drop during a call, a call that ends while the phone takes over, Transcribe Later toggled while paused, process death during a pause). One more bug was found while writing PR 2 and has a failing test: the phone reused the pendant's recording id, so it would have joined the pendant's conversation.
bash app/test.sh: 3053 tests passed, plus 138 in the spine suite, after rebasing ond3d945cce2.The analyzer ratchet passes, and
dart analyzeon the changed files is clean.This is not verified on a physical device (BLE, native background streaming, OS mic release); those remain device checks.
Cursor Grok review (grok-4.7-high via agentctl, read-only, including misses beyond the diff)
Grok raised 15 findings (1 P0, 8 P1, 4 P2, 2 P3).
Fixed in this PR
streamDeviceRecordingreturns early while a call is active. Tested.streamDeviceRecordingduring a call handoff wiped the transcript and rolled the session. It now returns early, as above. Tested (same recording id after the reconnect).resumeHandedOffPendant: falseand treatsisPhoneMicPausedas a live phone.onConnectedduring a pause could restart the mic._onMicStalled,_restartPhoneMicRecording,_resumeMicRecordingandonConnectednow all respect_phoneMicPaused.setBatchModewhile paused rolled the recording under the mute and stranded it. A paused recording now keeps its mode, and the new mode applies to the next recording. Tested.onTranscriptionSettingsChangedopened a device socket while the phone or a call owned the capture. It now branches on the owning source.finishCaptureresumed the pendant anyway.stopStreamRecordingnow returns whether it stopped, andfinishCaptureresumes only then.Deferred, with reasons
_micInterrupted), and a dedicated phone-mic pause for calls is a follow-up._isPhoneMicPaused, small screens, and the "pendant waiting" state are all in the UI PR (PR 2). Android keeps the foreground hold while paused on purpose, so the session survives. The OS mic indicator goes off because the mic is released.finishCapture, and socket drop during pause. They are guarded in code but not covered by a scenario, because the replay world cannot yet drive a native stall or a raced policy write.Line count
Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 3137 -> 3459 | The source-switch rules (handoff, restore, pause) read and mutate controller-private stream, socket and session state, so extracting them means splitting the controller, which is a separate change. About 80 of the added lines are doc comments on the new rules; about 75 more came from the Grok review fixes.
Product invariants affected
none
Failure class (fixes)
Failure-Class: FC-unowned-session-mutation-tears-down-live-capture
🤖 Generated with Claude Code