Skip to content

fix(capture): tell the server when the user taps Stop so notes start right away - #25536

Merged
kodjima33 merged 1 commit into
mainfrom
t3/capture-user-stop-finalization
Nov 16, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
t3/capture-user-stop-finalization

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Why

#25460 keeps a mobile conversation open when its /v4/listen socket closes, so a phone or pendant reconnect continues the same conversation. A deliberate Stop now looks the same as a network drop, so the server waits for the durable quiet check (~5-8 min) before it finalizes, and notes arrive late.

The backend already accepts an explicit signal on the listen socket, {"type":"finalization_reason","reason":"user_stop"} (backend/routers/listen/receiver.py, finalization_reason branch). Any finalization reason makes resumable_after_drop (backend/routers/listen/batch_close.py) return false, so teardown finalizes right away. The app never sent it.

What

  • TranscriptSegmentSocketService.stop(userStop: true) sends that frame right before the socket closes. It is best-effort: skipped when the socket is not connected, and a send error is logged and never blocks the close.
  • Phone live recording: _stopPhoneLiveBody passes userStop only for reason user_stopped (Stop on the live page, the Home button, Siri, and the voice-profile handoff).
  • Pendant: the explicit stop (DeviceStopRequested(cleanDevice: false)) carries userStop through the SocketClose effect.
  • Nothing else sends it: network drops, server closes, automatic reconnects, BLE disconnects (cleanDevice: true / DeviceUpdated(null)), source restarts, transcription-settings reconnects and app backgrounding all leave the conversation open as fix(listen): a mobile socket drop no longer ends the conversation #25460 intends. Phone batch stop does not close the socket, so it is unchanged.
  • Custom STT composite sockets: the frame reaches Omi. The custom STT primaries already drop text frames, the same as client-state frames.

Tests

New app/test/services/capture/capture_user_stop_finalization_test.dart drives the real CaptureController and TranscriptSegmentSocketService over the scripted transport, which now records an ordered wire log of sends and closes:

  • Phone Stop sends exactly one user_stop, after the last audio frame and immediately before close.
  • A phone socket drop and its reconnect send none; the later Stop sends exactly one, on the live socket.
  • Pendant explicit stop sends exactly one, right before close.
  • Pendant BLE disconnect closes the socket with none.
  • A dead socket gets no frame and still closes; a send that throws never blocks the close.

Mutation check: with the send removed, 3 tests fail. With BLE disconnect also marked userStop, 1 test fails.

Ran locally with the pinned Flutter 3.44.5:

  • flutter test test/services/capture/ test/services/sockets/ test/unit/capture_recovery_replay_scenarios_test.dart test/unit/composite_transcription_socket_test.dart test/unit/capture_mute_admission_test.dart test/services/live_preview/: 677 passed
  • flutter test --dart-define=OMI_DEV_CONTROLS=1 test/spine: 138 passed
  • app/scripts/analyze_ratchet.sh: passed; dart format --line-length 120: no changes

Product invariants affected

  • INV-CAP-1: unchanged. This adds no new close, unsubscribe or fence. The frame rides closes that already happen on a user stop, so pendant audio delivery and retention are untouched.

Failure class (fixes)

Failure-Class: FC-transport-drop-terminalizes-resumable-capture

This is the client half of that class's prevention ("key immediate finalization on the client's close semantics ... and an explicit client finalization reason"). With the server keeping drops open, the explicit reason is what keeps a deliberate Stop immediate.

UI-Evidence: none -- protocol only, no visible UI change

Line-Count-Exception: app/lib/services/capture/capture_coordinator.dart | 3026 -> 3027 | the user-stop flag on the SocketClose effect

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

…right away

Since the backend keeps a mobile conversation open when /v4/listen closes
(so a reconnect continues it), a deliberate Stop looked like a drop and the
conversation waited for the quiet check (~5-8 min) before finalizing.

On a user Stop (phone live recording with reason user_stopped, or an
explicit pendant stop) the socket service now sends
{"type":"finalization_reason","reason":"user_stop"} after the last audio
frame and right before close. Drops, BLE disconnects, source restarts and
settings-change reconnects send nothing. The send is best-effort and never
blocks the close.
@kodjima33
kodjima33 merged commit e2e2b48 into main Nov 16, 2026
61 of 63 checks passed
@kodjima33
kodjima33 deleted the t3/capture-user-stop-finalization branch November 16, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant