Repository navigation
fix(listen): fail a live STT session over to the next provider - #12459
Merged
Merged
Conversation
mdmohsin7
added a commit
that referenced
this pull request
Aug 31, 2026
…12462) ## Problem The serving order was pinned to Deepgram-first in nine places: ``` dg-nova-3,modulate-velma-2,parakeet ``` That no longer matches how production runs, and the next `helm upgrade` or Cloud Run deploy would silently revert live serving to Deepgram-primary. The chart values are **not** the source of truth — `DEFAULT_MODELS_BY_SURFACE` in `config/stt_provider_policy.py` is, and both `test_backend_listen_helm_defaults.py` and `validate-backend-runtime-env.py` assert every deployment matches it. Changing the charts alone fails those contracts, so this changes the policy and propagates it everywhere. ## New order ``` modulate-velma-2,soniox,dg-nova-3,parakeet ``` - **Velma primary** — lowest cost per hour of audio. - **Soniox second** — with mid-session failover (#12459) merged, a Velma error frame now hands the stream to Soniox instead of ending the session. This slot is what that fix relies on. - **Deepgram last** — kept deliberately. Selection requires a `dg-*` entry in the list, so removing it would strip BYOK users of Deepgram entirely. - **Parakeet dropped** — streaming Parakeet is English-only and live sessions are overwhelmingly auto-detect, so it was never selected on this surface. ## Everything updated | file | role | |---|---| | `config/stt_provider_policy.py` | policy source of truth | | `charts/backend-listen/{prod,dev}` | live listen serving | | `charts/pusher/{prod,dev}` | pusher serving | | `deploy/runtime_env/{_base,dev.overlay,prod.overlay}.yaml` | deploy sources | | `deploy/runtime_env.yaml` | regenerated via `compose_runtime_env.py` | | `deploy/_generate_runtime_env_sources.py` | generator default | | `.github/workflows/gcp_backend_pusher.yml` | pusher deploy workflow | | 4 unit test files | expectations that hardcoded the old order | `validate-backend-runtime-env.py --env prod` and `--env dev` both pass, and the affected contract tests pass under `test.sh`. ## Parakeet stays last Dropping Parakeet broke the explicit client route: `/v4/listen?stt_service=parakeet` is honored only while Parakeet is present in the model list, so removing it silently disabled that route. The hermetic e2e wire-contract test caught this. It is now last in the chain — never selected by default (streaming Parakeet is English-only and live sessions are overwhelmingly auto-detect), but still reachable on request. ## Pusher Included because the validator requires every GKE workload's `STT_SERVICE_MODELS` to equal the streaming policy. Its `DEEPGRAM_SELF_HOSTED_ENABLED=true` / `DEEPGRAM_SELF_HOSTED_URL=https://dg.omi.me` settings are stale: there is no `deepgram-self-hosted` deployment in the cluster, the endpoint does not accept connections, and pusher logs show no Deepgram traffic. Nothing is lost by reordering it. Failure-Class: none The `fix:` commit in this branch repairs a regression introduced earlier in the same branch (dropping Parakeet disabled the explicit `?stt_service=parakeet` route) and caught by the hermetic e2e wire contract before merge. No shipped behaviour ever carried the defect, so there is no production failure class to record. ## Product invariants affected - **INV-DATA-1** — production-family customer data-plane continuity. Unaffected: this changes STT provider ordering only. No Firebase project, Firestore database, account universe, or serving endpoint changes; every environment keeps the plane it already had. - **INV-MEM-4** — canonical promotion is the sole Long-term authority. Unaffected: no intake, consolidation, or promotion path is touched. Transcript content reaches memory by the same route regardless of which provider produced it.
mdmohsin7
added a commit
that referenced
this pull request
Aug 31, 2026
…d failover survival test The two send-failure e2e tests asserted the pre-#12459 contract (any provider death is immediately terminal). The new expected behavior is the merged #12459 failover design: a death is terminal only once reselection finds no provider. Both tests now pin reselection to an exhausted chain — the receiver's own namespace drives it, and left unpatched it reads the real provider chain and reaches for un-faked network clients, which is why they timed out in CI. New wire test: a death with a provider left in the chain moves the session — the buffered audio reaches the replacement socket in the same flush, a transcript flows from it, and the client never sees stt_failed. Failure-Class: FC-recoverable-provider-failure-terminal
mdmohsin7
added a commit
that referenced
this pull request
Aug 31, 2026
…itor poll (#12469) ## Problem #12459 added mid-session STT failover, but wired it only into `_monitor_stt_death`, which polls the death latch every 1.0s. The audio send path (`send_live_stt_audio`) checks the same latch on every chunk and terminated the session directly (`stt_failed` + WebSocket 1011). With audio flowing, the send path observes a provider death within ~100–300ms of the error frame — always before the 1s poll — so the failover was structurally unreachable exactly when it was needed. Measured in production during the 2026-08-31 Velma outage (chain `velma → soniox → dg`, image `f125bb8` with #12459 deployed): ``` omi_live_stt_terminal_failures_total{provider="modulate", phase="connection"}: +3,110 in 30 min 'STT failover mid-session' log events: 0 ``` Pod logs show the loop users sat in: Velma accepts the upgrade → `Modulate streaming error: Internal server error` ~300ms later → session closed ~200ms after that → the client reconnects → repeat, every ~2 seconds per device. ## Fix - `send_live_stt_audio` — the single termination authority for the live send path — now accepts an `attempt_failover` callback and only declares a recoverable death terminal once the chain is exhausted. After a successful failover the chunk is reported unsent with the caller's buffer intact. `socket_unavailable` (no socket ever initialized) stays terminal: there is nothing to fail over from. - `_flush_stt_buffer` passes `_failover_stt_socket` and retries in a bounded loop so the buffered audio reaches the replacement socket in the same call — the next client chunk can be a VAD-gated silence away. - `_failover_stt_socket` is serialized behind a lock: the death monitor and the send path can observe the same death within milliseconds of each other, and the loser adopts the winner's replacement instead of burning a second chain slot on a redundant rebuild. `MAX_STT_FAILOVERS` still bounds the walk. - Multi-channel and custom-STT sessions are unchanged; #12459's single-channel-only scope still applies. The guard surface for this class is now behavioral, not positional: the termination authority itself refuses to declare a recoverable death terminal without offering the failover, and `tests/unit/test_live_stt_failure.py` pins that contract for every current and future caller of the send path. ## E2E wire-contract update Two hermetic e2e tests asserted the pre-#12459 contract — any provider send failure is *immediately* terminal — and correctly failed on this branch. Per the rewritten-test rule, the external source for the new expected value is the merged #12459 failover design plus the production measurement above: a death is terminal only once reselection finds no provider. Both tests now pin the receiver's reselection to an exhausted chain and keep their exact terminal payload assertions (`stt_failed`, bounded reason, close 1011). The reselection pin is also a harness necessity: failover reselects via the receiver's namespace, which the fakes previously left unpatched, so it read the real provider chain and reached for un-faked network clients (the CI timeouts). Added `test_web_listen_streaming_stt_send_failure_fails_over_and_the_session_survives`: the wire-level guard for this fix — first socket dies on first send, the session moves to the replacement, the same buffered chunk reaches it in the same flush, a transcript flows, and the client never sees `stt_failed`. ## Verification Run with the pinned backend venv (`pylock.macos.toml`): - `pytest testing/e2e/test_listen_stt.py` — 12 passed (new survival test included; terminal test unchanged assertions). - `pytest testing/e2e/test_listen_pusher_wire_contract.py` — 7 passed. - `pytest tests/unit/test_stt_session_failover.py` — 11 passed (4 new: a death observed by the send path fails over and delivers the buffered audio to the replacement in the same call; an exhausted chain still terminates; the lock loser adopts the already-installed replacement instead of rebuilding). - `pytest tests/unit/test_live_stt_failure.py` — 16 passed (3 new: a successful failover is not terminal and preserves the unsent buffer; an exhausted failover stays terminal with the bounded close; a death latched during send also offers failover). - `pytest tests/unit/test_listen_stt_death_monitor.py` — 4 passed (monitor path unchanged). Not exercised against live Modulate: reproducing the outage needs Velma to emit mid-session error frames on demand. The regression tests drive the production code through the controllable seam the outage used (`live_stt_socket_is_dead` latch on the socket the flush path holds), and the production numbers above pin the failure mode this would have caught. ## Product invariants affected none — `scripts/pr-preflight --suggest`: changed paths match no locked invariant globs. Failure-Class: FC-recoverable-provider-failure-terminal
aryanorastar
pushed a commit
to aryanorastar/omi
that referenced
this pull request
Aug 31, 2026
send_live_stt_audio observes a provider death on the very next audio chunk — hundreds of milliseconds before the 1s death-monitor poll — and terminated the session there, so the monitor's mid-session failover (BasedHardware#12459) was structurally unreachable for any session with audio flowing. During the 2026-08-31 Velma outage that meant 3,110 modulate sessions terminated in 30 minutes with zero failovers fired. The termination authority now accepts the session's attempt_failover callback and only declares a recoverable death terminal once the chain is exhausted. A successful failover reports the chunk unsent with the buffer intact so the caller retries it against the replacement socket. Failure-Class: FC-recoverable-provider-failure-terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
connect_stt_socket_with_fallbackruns once, at connect time. Modulate accepts theWebSocket upgrade and then sends an error frame seconds later, so its outages land
mid-session, where the fallback chain cannot reach them. When the primary dies mid-stream
the session is terminated (
stt_failed+ WebSocket 1011) rather than moved to the nextprovider.
Measured in production on 2026-08-30, with the chain configured
velma → soniox → dg:The chain was correct and structurally unable to fire. Users ate the full 82%.
Fix
_monitor_stt_deathnow attempts a failover before terminating. On death it marks thedead provider, reselects excluding it, rebuilds the socket via the existing
_create_stt_socketpath, and swaps it in; the session continues. Termination happensonly once the chain is exhausted.
Supporting pieces:
get_stt_service_for_language(..., exclude=...)skips providers that already died, soa failover can't reselect the one that just failed.
provider_for_service()— inverse ofprovider_for_model_tokenfor callers holding aresolved service.
re-deriving them or the VAD gate.
Guards:
MAX_STT_FAILOVERS = 2walks the 3-provider chain once; a flappingprovider can't loop.
fallback_socket_is_serving, so a replacement that isaccepted then rejected ~150ms later isn't counted as recovery.
channel; swapping one mid-stream needs its own design and is unchanged here.
Emits
record_fallback(component='stt_live_session', outcome='recovered')so failoversare visible rather than silent.
Tests
8 new tests: successful failover, exclusion picks the next provider, exhausted chain
selects nothing, a replacement that dies immediately is not recovery, multi-channel is
skipped, the bound holds, and provider/service mapping round-trips. Existing Soniox
tests still pass (19 total).
Note: the full
tests/unitrun dumps core in this environment on a clean checkout ofmainas well, so it is pre-existing and unrelated.Failure-Class: FC-recoverable-provider-failure-terminal
Line-Count-Exception: backend/utils/stt/streaming.py | 1707 -> 1715 | exclude parameter and its guard at the selection point