Repository navigation
fix(backend): record STT failover recovered only after a transcript - #15218
Merged
Merged
Conversation
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
deleted the
fix/stt-failover-recovered-on-transcript
branch
September 20, 2026 18:18
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.
Summary
omi_fallback_totaloutcome=recoveredwhen the replacement socket merely connects. Recovered waits for the first transcript from the new leg; if the vendor closes first, the hop isexhaustedwith a typed reason (quotafor budget/payment).organization_monthly_budget_exhausted(and sibling 402 / monthly-cap frames), Deepgram HTTP 402, and Velma monthly/quota text unify asprovider_budget_exhausted. Vendor close frames increment boundedomi_stt_stream_close_total{provider,reason}— raw vendor messages are never label values.omi-stt-provider-budget, ≥5 closes in 5m for 2m). Complementomi-stt-fallback-leg-deadso it watchesstt_selection|stt_live_session(mid-session hops used to bucket tocomponent=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_selectionand would not have fired.What already existed vs what this PR adds
Already on
origin/main@16fc207534(#15189):omi_fallback_totalwith connect-timestt_selectionrecovered/exhaustedomi-stt-fallback-leg-deadwatching onlycomponent="stt_selection"recovered==0soniox_death_reasontypedorganization_balance_exhaustedassoniox_account_state; monthly budget fell through toconnection_lostand logged WARNINGSoniox stream closed:omi_fallback_event component=other from=modulate to=soniox outcome=recoveredbecausestt_live_sessionwas not inALLOWED_COMPONENTSAdded:
PendingLiveFailover: recovered once on first transcript; exhausted + typed reason if the new leg dies first (listen + PTT)stt_live_sessioninALLOWED_COMPONENTSprovider_budget_exhausteddeath reason (replacessoniox_account_state); circuit still opensomi_stt_stream_close_total+record_stt_stream_closeomi-stt-provider-budgetPAGE; dead-leg expr includesstt_live_session; dashboard panel 18Failure-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 recordevaluated_bad/evaluated_goodfrom Cloud Logging of the exact incident lines. The new series has no Prometheus history; evaluation of the exactincrease()expressions is still owed.Invariants
none —
scripts/pr-preflight --suggestreported no product-invariant path glob matches. Merge base is currentorigin/main@fdcae0aa16(#15208 changelog on top of #1518916fc207534).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 readoftextPayload:"organization_monthly_budget_exhausted"andomi_fallback_event … to=soniox outcome=recovered. Sample recovered line:component=other from=modulate to=soniox reason=other outcome=recovered. New seriesomi_stt_stream_close_totaland truthfulstt_live_sessionrecovered have no Prometheus history. Do not treat these log counts as a PromQL result.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-budgetevaluated_bad: 64 / 87 / 106 closes in 5m (proxy for the new series). evaluated_good: 0. Would PAGE.omi-stt-fallback-leg-deadafter this change, evaluated_bad:to_mode=sonioxrecovered 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:
sum(increase(omi_stt_stream_close_total{job="backend-listen-metrics",reason="provider_budget_exhausted"}[5m])) or vector(0)over the 5m windows abovesum by (to_mode) (increase(omi_fallback_total{job="backend-listen-metrics",component=~"stt_selection|stt_live_session",outcome="recovered"}[6h]))vs attempts, especiallyto_mode=sonioxduring 2026-09-19 03:00–2026-09-20 06:28ZOwner: whoever has Grafana
monitor.omi.meread 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):
GET /v1/usage-summaryreturns dailytotal_cost_usdby model.monthly_budget_usdis 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.GET /v1/projects/{project_id}/usageand/usage/breakdown; prepaid remaining via/balances.4029covers quota or concurrency.Test plan
BACKEND_UNIT_TEST_FILE_LIST+bash backend/test.shon 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)omi-stt-provider-budgetand the updated dead-leg expr🤖 Generated with Claude Code