Skip to content

fix(backend): record STT failover recovered only after a transcript - #15218

Merged
Git-on-my-level merged 2 commits into
mainfrom
fix/stt-failover-recovered-on-transcript
Sep 20, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
fix/stt-failover-recovered-on-transcript

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Mid-session STT failover no longer records omi_fallback_total outcome=recovered when the replacement socket merely connects. Recovered waits for the first transcript from the new leg; if the vendor closes first, the hop is exhausted with a typed reason (quota for budget/payment).
  • Soniox organization_monthly_budget_exhausted (and sibling 402 / monthly-cap frames), Deepgram HTTP 402, and Velma monthly/quota text unify as provider_budget_exhausted. Vendor close frames increment bounded omi_stt_stream_close_total{provider,reason} — raw vendor messages are never label values.
  • PAGE on budget/quota exhaustion (omi-stt-provider-budget, ≥5 closes in 5m for 2m). Complement omi-stt-fallback-leg-dead so it watches stt_selection|stt_live_session (mid-session hops used to bucket to component=other). Panel 18 + runbook entry for raising a monthly cap.

This is the 2026-09-19 02:52Z–2026-09-20 06:28Z Soniox monthly-budget incident: every hop connected, the vendor then closed the stream, recovered was recorded at connect, and nobody was paged for 27.5h. #15189's dead-leg alert keys on recovered==0 for stt_selection and would not have fired.

What already existed vs what this PR adds

Already on origin/main @ 16fc207534 (#15189):

  • omi_fallback_total with connect-time stt_selection recovered/exhausted
  • omi-stt-fallback-leg-dead watching only component="stt_selection" recovered==0
  • soniox_death_reason typed organization_balance_exhausted as soniox_account_state; monthly budget fell through to connection_lost and logged WARNING Soniox stream closed:
  • Mid-session hops logged omi_fallback_event component=other from=modulate to=soniox outcome=recovered because stt_live_session was not in ALLOWED_COMPONENTS

Added:

  • PendingLiveFailover: recovered once on first transcript; exhausted + typed reason if the new leg dies first (listen + PTT)
  • stt_live_session in ALLOWED_COMPONENTS
  • provider_budget_exhausted death reason (replaces soniox_account_state); circuit still opens
  • omi_stt_stream_close_total + record_stt_stream_close
  • omi-stt-provider-budget PAGE; dead-leg expr includes stt_live_session; dashboard panel 18

Failure-Class

Failure-Class: FC-alert-never-provably-fired

#15189's dead-leg rule is valid PromQL that could never fire on this incident: recovered was incremented at connect, and the hops were labeled component=other. The new PAGE and the complemented dead-leg record evaluated_bad / evaluated_good from Cloud Logging of the exact incident lines. The new series has no Prometheus history; evaluation of the exact increase() expressions is still owed.

Invariants

none — scripts/pr-preflight --suggest reported no product-invariant path glob matches. Merge base is current origin/main @ fdcae0aa16 (#15208 changelog on top of #15189 16fc207534).

Line-Count-Exception

Line-Count-Exception: backend/routers/chat.py | 2201 -> 2214 | PTT mid-session failover used the same recovered-at-connect lie; settle through PendingLiveFailover without a second copy of the logic.
Line-Count-Exception: backend/utils/stt/streaming.py | 1932 -> 1941 | Split Velma budget/quota from 5xx serve-error and emit the bounded stream-close metric on Modulate frames and Deepgram HTTP 402.

Evidence (Cloud Logging, project based-hardware, backend-listen)

Evidence layer is gcloud logging read of textPayload:"organization_monthly_budget_exhausted" and omi_fallback_event … to=soniox outcome=recovered. Sample recovered line: component=other from=modulate to=soniox reason=other outcome=recovered. New series omi_stt_stream_close_total and truthful stt_live_session recovered have no Prometheus history. Do not treat these log counts as a PromQL result.

window (UTC) budget closes Soniox connections established recovered-to-soniox (lying, at connect)
2026-09-18 09:00–09:02 (good) 0 16 17
2026-09-19 01:00–01:02 (pre) 0 20 21
2026-09-19 03:00–03:02 (bad) 30 30 6
2026-09-19 04:40–04:42 (bad) 32 32 30
2026-09-19 16:00–16:02 (bad) 42 42 58
2026-09-20 04:00–04:02 (bad) 40 39 88
2026-09-20 07:30–07:32 (good) 0 13 13
2026-09-20 16:38–16:40 (good) 0 26 25

5-minute budget-close counts (PAGE threshold ≥5): 2026-09-19 03:00Z=64, 04:40Z=87, 16:00Z=106 vs 2026-09-18 09:00Z=0 and 2026-09-20 07:30Z=0.

omi-stt-provider-budget evaluated_bad: 64 / 87 / 106 closes in 5m (proxy for the new series). evaluated_good: 0. Would PAGE.

omi-stt-fallback-leg-dead after this change, evaluated_bad: to_mode=soniox recovered would be 0 (every hop vendor-closed before a transcript) with attempts ≫ 50 over 6h — the lying series showed 58 recovered in 2m at 16:00Z next to 42 budget closes. Deepgram recovered=0 / exhausted≥20000 in 2026-09-19 04:40–10:40Z still holds. evaluated_good: 0 budget closes on 2026-09-18 09:00Z and after 2026-09-20 07:30Z (hops that transcribe would recover); Deepgram remains a standing dead leg.

Prometheus evaluation still owed

Whoever can query prod Prometheus/Grafana read-only should evaluate these after deploy (the close-total series does not exist until then) and replace the log-derived annotation numbers if they differ:

  1. sum(increase(omi_stt_stream_close_total{job="backend-listen-metrics",reason="provider_budget_exhausted"}[5m])) or vector(0) over the 5m windows above
  2. sum by (to_mode) (increase(omi_fallback_total{job="backend-listen-metrics",component=~"stt_selection|stt_live_session",outcome="recovered"}[6h])) vs attempts, especially to_mode=soniox during 2026-09-19 03:00–2026-09-20 06:28Z

Owner: whoever has Grafana monitor.omi.me read access (platform / on-call). This agent must not.

Not in this PR — proactive remaining-budget signal

A burn/remaining-budget gauge needs each vendor's usage API (authenticated; not called here):

  • Soniox public docs: GET /v1/usage-summary returns daily total_cost_usd by model. monthly_budget_usd is a Console org/project cap, not a remaining-budget field — remaining is cap minus the current UTC month's summed cost. Caps reset at calendar month start.
  • Deepgram public docs: GET /v1/projects/{project_id}/usage and /usage/breakdown; prepaid remaining via /balances.
  • Modulate public docs: Usage dashboard only. No public usage API found. Monthly audio-hour quota is support-set; optional org monthly credit limit is admin-controlled in Organization settings. WebSocket close 4029 covers quota or concurrency.

Test plan

  • BACKEND_UNIT_TEST_FILE_LIST + bash backend/test.sh on Python 3.11.15 uv venv (backend/.venv): 8 files, 187 collected, all passed (test_stt_session_failover.py, test_soniox_typed_rejections.py, test_modulate_serve_error_deaths.py, test_fallback_observability.py, test_monitoring_alert_rule_contract.py, test_soniox_streaming.py, test_deepgram_terminal_rejection.py, test_modulate_connection_fallback.py)
  • Grafana provision of omi-stt-provider-budget and the updated dead-leg expr
  • After deploy: Prometheus evaluation listed above; confirm panel 18 during a real budget-close (do not induce one)

🤖 Generated with Claude Code

Review in cubic

Git-on-my-level and others added 2 commits September 21, 2026 00:22
Connect-time recovered hid 27.5h of Soniox monthly budget exhaustion.
Settle recovered on the first result, count typed vendor closes, and PAGE on budget.

Failure-Class: FC-alert-never-provably-fired
Co-authored-by: Cursor <[email protected]>
…ceiver

Onboarding's custom-STT enqueue path skips __init__, so it must set the field enqueue now reads.

Failure-Class: FC-alert-never-provably-fired
Co-authored-by: Cursor <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 527d9b4 into main Sep 20, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/stt-failover-recovered-on-transcript branch September 20, 2026 18:18
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