Skip to content

fix(app): keep custom STT live when Omi listen socket fails - #23875

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/cs-androidstt
Oct 28, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/cs-androidstt

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Keep a configured custom STT primary connected when the Omi /v4/listen secondary fails to connect, closes, or errors; retry the Omi socket with bounded exponential backoff.
  • Leave raw audio frames unsynced in the local WAL while forwarding to Omi is degraded, so the capture copy remains available for later sync.
  • When raw-audio forwarding is opted out, buffer only suggested transcripts during the Omi outage and flush them after recovery; never queue raw audio.
  • Treat a thrown initial Omi connect as a failed connect when the custom STT primary is healthy, and keep the composite state recoverable for retry.
  • Clear queued suggested transcripts on stop and before a new connection so outage data cannot cross into a later capture.
  • Add regression coverage for connect failures, a 1011 close, transcript recovery, cross-session cleanup, and retry teardown.

Root cause

The custom STT composite treated any Omi secondary failure as fatal and disconnected the still-working local provider. The #15500 support reply confirms this app-side failure mode.

Verification

  • /Users/dazheng/workspace/omi/bin/omi-heavy run -- nice -n 19 flutter test test/unit/composite_transcription_socket_test.dart (app unit suite, 27 passed).
  • /Users/dazheng/workspace/omi/bin/omi-heavy run -- nice -n 19 scripts/pr-preflight --lane ci --pr-body-file /Volumes/Ephemeral/scratch/cs-androidstt/pr-body.md (26 checks passed).
  • dart format on the two updated Dart files (no changes); git diff --check (clean).

Scope

  • Product invariant: INV-CAP-1.
  • The language=ko&stt_service=parakeet query is still sent by the app and generic close handling retries after 15 seconds; whether the backend route closes that tuple with 1011 remains backend-owned and is not changed here.

Refs #15500

Luna review follow-up

  • Buffer suggested transcripts for raw-audio-opt-out sessions while Omi is degraded, then flush on recovery. The bounded buffer is transcript-only; opted-out raw audio remains excluded.
  • Handle thrown initial secondary connects by keeping a healthy primary live in degraded retry mode.
  • Clear queued transcript data when a session stops or a new connection starts.

Owns: #23875

UI-Evidence: none -- only service/socket and capture plumbing changed; no visible UI changed.
Failure-Class: none

View guided diff Turn on auto-fix

CompositeTranscriptionSocket treated a secondary (Omi /v4/listen) connect
failure, close or error as fatal for both sockets, so an Omi outage also
disconnected the user's working custom/local STT engine and retried it in
the reconnect loop (#15500, #20381). Port of the approved #20382 design:
when keepPrimaryWhenSecondaryFails is on (live custom STT and on-device
composite), a secondary failure enters a degraded state instead — the
primary keeps transcribing, the secondary is retried with backoff, and
audio/suggested transcripts never reach Omi while degraded. WAL frames are
marked synced only when the socket delivers to Omi, so audio Omi never
received stays durable for later sync.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-28T11:20:37.664878Z 1e3a556 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e00cc1032

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +236 to +238
if (name == 'Secondary' && keepPrimaryWhenSecondaryFails) {
_enterDegraded('closed:${closeCode ?? -1}');
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve application-level close-code handling

When the secondary closes with an application-level code, this unconditional return bypasses the existing handling in CaptureController._socketClosedBody: 4001 forces a rejected-token refresh, 4002 refreshes the out-of-credits state, and 4005 expires a deleted-account session. Treating these as ordinary transport outages leaves those actions unexecuted and instead retries the secondary indefinitely; in particular, a server-rejected token that still appears valid locally is reused by getAuthHeader(). Preserve or explicitly dispatch these control-code actions rather than swallowing every secondary close.

Useful? React with 👍 / 👎.

Comment on lines +221 to +224
if (secondarySocket.status == PureSocketStatus.connected) {
CustomSttLogService.instance.info('Composite', 'Omi socket restored after $_secondaryRetryAttempts attempt(s)');
DebugLogManager.logEvent('composite_secondary_restored', {'attempts': _secondaryRetryAttempts});
_clearDegraded();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rebase transcript timestamps when restoring the secondary

When raw-audio forwarding is enabled and an audio frame reaches the restored secondary before the next transcript, the new backend session establishes first_audio_byte_timestamp from that frame (backend/routers/listen/receiver.py, _mark_first_audio). However, the primary remains connected and continues emitting timestamps relative to its original session—for example, PurePollingSocket retains _audioOffsetSeconds. Clearing degraded state resumes forwarding those unchanged timestamps, and backend/routers/listen/transcripts.py adds them to the new backend origin, shifting subsequent transcripts into the future by the primary's pre-reconnect duration and misaligning them with the recording. Establish a timestamp mapping for each restored secondary session before resuming suggested-transcript forwarding.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit d569d6a into main Oct 28, 2026
48 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/cs-androidstt branch October 28, 2026 11:58
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