Skip to content

Keep custom STT live when Omi's listen socket fails - #20382

Open
meath1981 wants to merge 5 commits into
BasedHardware:mainfrom
meath1981:custom-stt-keep-primary-when-omi-socket-fails
Open

meath1981 wants to merge 5 commits into
BasedHardware:mainfrom
meath1981:custom-stt-keep-primary-when-omi-socket-fails

Conversation

@meath1981

@meath1981 meath1981 commented Oct 2, 2026 •

Copy link
Copy Markdown

What

Live custom STT keeps running when Omi's own /v4/listen socket fails, instead of the app tearing down the user's STT socket together with it. Closes #20381.

Why

CompositeTranscriptionSocket treats a secondary (Omi) connect failure, close or error as fatal for both sockets. When Omi's listen socket is unavailable, the user's healthy custom STT is therefore disconnected and retried every 15 s. The app log shows Connection failed - primary: true, secondary: false on each attempt. The STT server sees a connect followed by CloseStream ~0.6 s later, with no audio.

Changes

  • CompositeTranscriptionSocket: new keepPrimaryWhenSecondaryFails (default false, so existing behaviour is unchanged). When it is on:
    • Connect: a secondary connect failure leaves the composite connected on the primary, with secondaryDegraded = true.
    • Mid-session: a secondary close or error enters the same degraded state instead of tearing down. A primary close or error still tears everything down.
    • Retries: the secondary is retried in the background with exponential backoff (default 5 s → 60 s). On success the composite leaves degraded mode and Omi forwarding resumes. stop()/disconnect() cancel the retries.
    • While degraded: audio and suggested transcripts are not sent to the secondary.
  • TranscriptSegmentSocketService.deliversToOmi: false while the composite is degraded.
  • CaptureController: the three phone-mic paths that mark WAL frames synced on send now do so only when deliversToOmi is true. Audio Omi never received therefore stays durable for later sync. Pendant frames already stay unsynced until transcript confirmation, so they are unchanged.
  • _createCompositeService (live custom STT) enables the new mode. The speech-profile composites keep the strict behaviour.

Tests

test/unit/composite_transcription_socket_test.dart has a new group, "when the Omi socket fails" (11 tests):

  • default constructor keeps the strict behaviour;
  • a failed Omi connect stays live and degraded, with no audio or transcripts to Omi;
  • a mid-session Omi drop does not tear down the composite; a primary close still does;
  • background retry restores the secondary; stop() cancels retries;
  • service-level deliversToOmi: false while degraded with raw-audio forwarding, true with forwarding off (no later upload of opted-out audio);
  • reconnect after a primary close retries Omi again;
  • a retry still pending across stop()/connect() cannot disturb the new session;
  • the live custom-STT factory enables the mode.

Commands run (Flutter 3.47.6 / Dart 3.13.5, Linux):

  • flutter test test/unit/composite_transcription_socket_test.dart: 22/22 pass.
  • flutter test on the 16 test files referencing CaptureController, TranscriptSegmentSocketService or CompositeTranscriptionSocket: 351/351 pass.
  • dart analyze on the changed files: no new issues. dart format -l 120: no changes.
  • scripts/pr-preflight (.github/scripts/pr_preflight.py --lane local with this body): 22/22 checks pass. capture_controller.dart stays at its current line count, and there is a changelog fragment under app/changelog/unreleased/.

Not exercised: an on-device iOS build.

Open question for maintainers: while degraded, the live transcript UI shows nothing, because UI messages come from the secondary. The user's server keeps working. Surfacing primary segments to the UI could be a follow-up.

Failure-Class

Failure-Class: none

Invariants

none


🤖 Generated with Claude Code

https://claude.ai/code/session_01VwRBbPmTir6bzqEQdRF9un

CompositeTranscriptionSocket tore down the user's custom STT socket
whenever the Omi secondary failed to connect, closed or errored, so an
Omi listen outage also stopped a healthy custom STT stream.

Add an opt-in keepPrimaryWhenSecondaryFails mode, enabled for the live
custom-STT composite. The composite stays connected on the primary,
retries the secondary with backoff and resumes forwarding once it is
back. While degraded, nothing is sent to Omi, and phone-mic WAL frames
are no longer marked synced, so that audio stays durable for later sync.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VwRBbPmTir6bzqEQdRF9un

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 4 files

Confidence score: 3/5

  • The healthy-only coverage in app/test/unit/composite_transcription_socket_test.dart could miss a degraded Omi path where deliversToOmi stays true and unsent WAL frames are marked synced. Add a service-level test for a degraded composite and assert it does not report delivery.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="app/test/unit/composite_transcription_socket_test.dart">

<violation number="1" location="app/test/unit/composite_transcription_socket_test.dart:315">
P2: This checks only healthy delivery and cannot catch `deliversToOmi` staying true while Omi is degraded, which would mark unsent WAL frames as synced. Exercise a degraded composite through a service and assert delivery becomes false.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

final composite = service.socket as CompositeTranscriptionSocket;

expect(composite.keepPrimaryWhenSecondaryFails, isTrue);
expect(service.deliversToOmi, isTrue);

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: This checks only healthy delivery and cannot catch deliversToOmi staying true while Omi is degraded, which would mark unsent WAL frames as synced. Exercise a degraded composite through a service and assert delivery becomes false.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At app/test/unit/composite_transcription_socket_test.dart, line 315:

<comment>This checks only healthy delivery and cannot catch `deliversToOmi` staying true while Omi is degraded, which would mark unsent WAL frames as synced. Exercise a degraded composite through a service and assert delivery becomes false.</comment>

<file context>
@@ -189,6 +189,206 @@ void main() {
+      final composite = service.socket as CompositeTranscriptionSocket;
+
+      expect(composite.keepPrimaryWhenSecondaryFails, isTrue);
+      expect(service.deliversToOmi, isTrue);
+    });
+  });
</file context>

- deliversToOmi stays true when raw-audio forwarding is off, so frames
  from users who opted out of sending audio to Omi are not left unsynced
  and queued for a later upload (P1).
- Clear degraded state and cancel the Omi retry timer on primary
  close/error and at the start of connect(), so a reused composite
  retries Omi again after a reconnect (P2).
- Tests: default-constructor strict behaviour, service-level
  deliversToOmi while degraded (with and without raw-audio forwarding),
  and reconnect after a primary close.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VwRBbPmTir6bzqEQdRF9un
@meath1981

Copy link
Copy Markdown
Author

Thanks @cubic-dev-ai — all four findings addressed in the latest commit:

  1. P1, raw-audio opt-out leak (transcription_service.dart): deliversToOmi now returns !secondaryDegraded || !forwardRawAudioToSecondary. Users who turned off "send raw audio to Omi" keep the previous behaviour: frames are marked synced and never queued for a later upload.
  2. P2, degraded state surviving a primary teardown (composite_transcription_socket.dart): degraded state and the retry timer are now cleared on a primary close or error, and at the start of connect(). A reused composite therefore retries Omi again after a reconnect.
  3. P2, default not tested: the "default behaviour is unchanged" test now uses the plain constructor and asserts keepPrimaryWhenSecondaryFails is false.
  4. P2, deliversToOmi only tested when healthy: new service-level tests check that deliversToOmi is false while degraded with raw-audio forwarding on, and stays true with it off. A further test covers reconnecting after a primary close.

Tests: flutter test test/unit/composite_transcription_socket_test.dart passes 21/21. The 16 related test files (capture controller, transcription service, composite) pass 350/350.

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks @cubic-dev-ai — all four findings addressed in the latest commit:

  1. P1, raw-audio opt-out leak (transcription_service.dart): deliversToOmi now returns !secondaryDegraded || !forwardRawAudioToSecondary. Users who turned off "send raw audio to Omi" keep the previous behaviour: frames are marked synced and never queued for a later upload.
  2. P2, degraded state surviving a primary teardown (composite_transcription_socket.dart): degraded state and the retry timer are now cleared on a primary close or error, and at the start of connect(). A reused composite therefore retries Omi again after a reconnect.
  3. P2, default not tested: the "default behaviour is unchanged" test now uses the plain constructor and asserts keepPrimaryWhenSecondaryFails is false.
    ...

@meath1981 All four look addressed — I verified each against the current diff:

  1. P1 raw-audio opt-out: deliversToOmi → !secondaryDegraded || !forwardRawAudioToSecondary is right. Opt-out users keep frames synced while degraded, so nothing unsynced queues for a later upload they never consented to. The doc comment captures the rationale well.
  2. Degraded state on teardown: _clearDegraded() now runs on primary close and error, plus at the top of connect(), so a reused composite retries Omi again after a reconnect. Matches the original intent.
  3. Default constructor test: the strict-behaviour test uses the plain constructor and asserts the flag is false — good.
  4. deliversToOmi coverage: the service-level tests now exercise degraded-with-forwarding (false), degraded-without-forwarding (true), and the reconnect path. That covers the gap.

The new tests in the group line up with the behaviour claims (no audio/transcripts to Omi while degraded, backoff restore, cancel on stop, primary teardown), and the TestWidgetsFlutterBinding.ensureInitialized() addition for the service-level listeners makes sense.

One small, non-blocking race I'd note: _clearDegraded() doesn't reset _secondaryRetryInFlight, and an in-flight retry can't be cancelled by stop(). If the composite is stopped and reconnected while a retry connect is still pending, the stale retry can finish after the new session started and either reschedule a timer or (if its connect succeeded) _clearDegraded() a freshly re-entered degraded state. In practice it converges, but a session generation counter — or resetting _secondaryRetryInFlight in _clearDegraded() — would make that interleaving impossible. Not worth blocking this PR over.

And yes, the degraded-UI question (no transcripts shown from the primary while degraded) is a sensible follow-up — the durability fix here is the right scope.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

A background secondary retry still pending when the composite was
stopped, torn down or reconnected could finish later and act on the
new session (reset the in-flight flag, reschedule a timer, or clear a
freshly re-entered degraded state).

Bump a degraded epoch on every _clearDegraded() (connect, stop,
disconnect, primary teardown, restore), reset the in-flight flag there,
and ignore a retry whose epoch is stale. Only an idle composite cleans
up a stale successful connect. A retry now trusts the secondary's own
connected status. Adds a regression test for a retry pending across
stop and reconnect.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VwRBbPmTir6bzqEQdRF9un
@meath1981

Copy link
Copy Markdown
Author

Thanks @cubic-dev-ai. I've taken up the non-blocking retry-race note in the latest commit:

  • _clearDegraded() now bumps a degraded epoch and resets _secondaryRetryInFlight. It runs on connect, stop, disconnect, primary teardown and restore.
  • _retrySecondary() captures the epoch before awaiting connect(). If the epoch has changed by the time the connect returns, the retry does nothing to the current session: it doesn't reset the flag, reschedule a timer or clear degraded state. It only disconnects a stale successful connect if the composite is idle.
  • A retry now checks the secondary's own status rather than the boolean returned by connect(), so it also adopts a socket that another attempt already connected.
  • New test: a retry still pending across stop() and connect() doesn't disconnect the new session's secondary or reschedule retries, and audio flows to Omi afterwards.

flutter test test/unit/composite_transcription_socket_test.dart: 22/22 pass. The 16 related test files pass 351/351. dart analyze: no issues on the changed files.

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks @cubic-dev-ai. I've taken up the non-blocking retry-race note in the latest commit:

  • _clearDegraded() now bumps a degraded epoch and resets _secondaryRetryInFlight. It runs on connect, stop, disconnect, primary teardown and restore.
  • _retrySecondary() captures the epoch before awaiting connect(). If the epoch has changed by the time the connect returns, the retry does nothing to the current session: it doesn't reset the flag, reschedule a timer or clear degraded state. It only disconnects a stale successful connect if the composite is idle.
  • A retry now checks the secondary's own status rather than the boolean returned by connect(), so it also adopts a socket that another attempt already connected.
    ...

@meath1981 Confirmed — the epoch fix closes the race I flagged. I checked it against the current diff:

  • _clearDegraded() bumps _degradedEpoch and resets _secondaryRetryInFlight on every exit route (connect start, stop, disconnect, primary teardown, restore), so no stale in-flight flag can leak into a new session.
  • _retrySecondary() captures the epoch before awaiting connect(), and the epoch-mismatch branch skips the flag reset, timer reschedule, and status-based restore. The finally guard deliberately only resets _secondaryRetryInFlight when the epoch still matches, which is what protects a genuinely new in-flight retry from being cleared by an old one.
  • The idle-only disconnect of a stale successful connect is the right cleanup: after stop()/teardown the sockets were already disconnected, so the only case needing it is a connect that completed after teardown, and gating it on idle keeps it off a live new session. The one edge left — a stale success landing while a new session is mid-connect() — converges via the secondary refusing the new connect and the retry loop adopting the socket through its own status check, which is exactly what the "trust the socket, not the boolean" change was for.
  • The new gated test is the right shape for this: a Completer makes the stop/reconnect interleaving deterministic, unlike the delay-based tests, so the assertion connectCalls == 3, disconnectCalls == 1, and audio flowing afterwards actually pins the race.

The _retrySecondary() status-based restore and the backoff accounting (attempt counter reset in _enterDegraded, so the log counts retries only) also line up with the PR description. Nothing blocking from me.

One optional follow-up for later, not this PR: the backoff timer doubling happens at schedule time, so a connect that hangs for a long time pauses the backoff clock — the schedule after a failed retry picks up from the already-doubled delay. Fine as-is for a 5→60 s cap, just worth knowing if the retry window ever needs to be time-bounded.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @meath1981 — reviewed the full diff on 3c2b424. This is a well-scoped fix for a real UX failure mode (a healthy custom STT being torn down every 15s because Omi's /v4/listen socket is unreachable), and the prior review's findings (raw-audio opt-out semantics, degraded-state survival across teardown, retry races) are all addressed on this head.

File-by-file:

  • app/lib/services/sockets/composite_transcription_socket.dart — the opt-in keepPrimaryWhenSecondaryFails mode is cleanly isolated (default false, so existing composites keep strict behavior). The epoch guard in _retrySecondary() correctly neutralizes retries that straddle a stop/reconnect, and _clearDegraded() runs on every lifecycle exit path. Primary close/error still tears the composite down, as it should.
  • app/lib/services/sockets/transcription_service.dart — deliversToOmi handles the important privacy case correctly: when forwardRawAudioToSecondary is false, frames keep being marked synced so a degraded window can't queue audio for a later upload the user didn't consent to.
  • app/lib/services/capture/capture_controller.dart — all three phone-mic markFrameSynced sites are gated consistently on deliversToOmi.
  • app/test/unit/composite_transcription_socket_test.dart — good coverage: degraded connect, mid-session drop, teardown, retry/restore, stop-cancels-retry, opt-out semantics, and the stop/reconnect race via _GatedSocket.
  • app/changelog/unreleased/20261002-custom-stt-survives-omi-outage.json — accurate, user-facing.

Two non-blocking notes:

  1. While degraded, suggested transcripts from the custom STT are dropped rather than queued for replay after restore (only raw audio is preserved via the WAL). The code documents this tradeoff; just worth a maintainer confirming it's the intended product behavior for live sessions.
  2. The retry backoff (5s → 60s) has no jitter — minor thundering-herd consideration if many clients reconnect after a backend outage.

CI hasn't reported on this head yet, so leaving the merge decision to the maintainers. Nice first contribution — the WAL sync-marking discipline around the degraded window is exactly the kind of detail that's easy to get wrong, and you got it right.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added flutter flutter work positive-signal Automation verified a genuine fix/quality contribution labels Oct 2, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Confirmed real bug (closes #20381), well-tested, but no CI checks have run yet and diff is 515 lines — confidence 3/5, approve-only.

@undivisible

Copy link
Copy Markdown
Collaborator

@meath1981 this conflicts with main now. Please rebase and push; it still looks valid.

YinkaAdepoju pushed a commit to YinkaAdepoju/omi that referenced this pull request Oct 28, 2026
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 (BasedHardware#15500, BasedHardware#20381). Port of the approved BasedHardware#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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom STT stops completely whenever Omi's own live socket fails

4 participants