Repository navigation
fix(stt): fail fast on prerecorded Modulate quota errors, breaker and burn counter (P58 Phase 0) - #23263
Conversation
Incident 2026-10-22 02:00Z: Modulate 429 "Insufficient credits" made every
prerecorded segment cost 5 POSTs (bytes path retried 3x on any exception,
URL wrapper recursed and re-entered it), and LID probe failures were
indistinguishable from unknown language.
- STT_PRERECORDED_VENDOR_FAIL_FAST (default on, call-time read, pure
config/prerecorded_vendor.py): only explicit false restores the exact
legacy 3-POST bytes / 5-POST URL retry ladder.
- utils/stt/vendor_guard.py: ModulateQuotaError (RuntimeError subclass,
'Modulate transcription failed' prefix kept) for 401/402/403/429 or an
insufficient-credits body (body never logged); per-endpoint thread-safe
circuit breaker (5 quota errors / 60s, one half-open trial) with gauge
omi_prerecorded_vendor_breaker_open{provider,endpoint}; burn counter
omi_prerecorded_vendor_audio_seconds_total{provider,endpoint,outcome}
fed by WAV-header seconds (STT) and probe seconds (LID).
- modulate_prerecorded_from_bytes: quota raises immediately; other
transient errors retry at most once behind 0.25-0.75s jitter;
verification-deadline and held-single-attempt guards unchanged.
- modulate_prerecorded: retries only the download, never re-enters the
bytes path; <=2 Modulate POSTs per URL call.
- detect(): exactly one omi_batch_pipeline_language_probe_total{outcome}
increment per call (accepted/invalid_response/quota/http_5xx/http_4xx/
timeout/transport/unsupported_format/no_key/skipped/breaker_open/error);
decisions unchanged; quota feeds the lid breaker.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A non-quota trial failure (5xx, timeout) left trial_in_flight set, so the breaker stayed open until the process restarted and blocked every Modulate call. Release the trial and re-open for a window on any non-quota failure, and expire an abandoned trial after 360 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0143cc038d
ℹ️ 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".
| def is_quota_error(exc: BaseException) -> bool: | ||
| if not isinstance(exc, httpx.HTTPStatusError): | ||
| return False |
There was a problem hiding this comment.
Classify 2xx credit envelopes as quota errors
When Modulate returns HTTP 200 with an error envelope containing insufficient credits, raise_for_status() succeeds and the breaker is marked successful before response validation; the malformed shape then becomes a plain RuntimeError, which this early type check rejects. That causes another paid POST and prevents the response from contributing to the quota breaker, even though the parser explicitly anticipates 2xx JSON error envelopes. Inspect the successful response body for the credit marker before resetting the breaker.
Useful? React with 👍 / 👎.
| if attempts < 1 and _verification_deadline.get() is None and not _held_single_attempt.get(): | ||
| _fail_fast_retry_sleep() | ||
| return modulate_prerecorded_from_bytes( | ||
| audio_bytes, sample_rate, diarize, attempts + 1, return_language, language | ||
| ) |
There was a problem hiding this comment.
Preserve non-quota failures from half-open trials
When the half-open STT trial receives a 5xx or timeout on a normal attempts=0 call, record_breaker_other_failure() reopens the breaker and this recursive retry immediately fails the next breaker_allows() check, raising ModulateQuotaError before entering the try block. The caller therefore receives a quota-typed exception with no chain to the actual transient failure, despite the class being documented for quota/auth rejections only. Avoid recursing after a half-open failure, or propagate the original generic failure when the retry is blocked by the breaker.
Useful? React with 👍 / 👎.
| if not vendor_fail_fast_enabled(): | ||
| return | ||
| state = _breaker_for(endpoint) | ||
| with state.lock: | ||
| state.failures.clear() |
There was a problem hiding this comment.
Retain quota failures across ordinary successes
With intermittent successful requests, this unconditional clear means the breaker does not implement the documented “5 quota errors in 60s” window: any success between 429 responses erases all prior failures, so the breaker opens only after five uninterrupted quota failures. Under partial throttling or a nearly exhausted shared account, occasional successes can therefore prevent the breaker from ever opening while paid retries continue. Preserve the rolling failure window for ordinary closed-state successes and clear it only when a successful half-open trial closes the breaker.
Useful? React with 👍 / 👎.
…3234) #23234 types Modulate out-of-credits (402, or 429 with a credits body) as a terminal TranscriptionFailure(PROVIDER_BUDGET_EXHAUSTED). Keep that outcome; Phase 0 now records its burn and feeds the breaker, and an open breaker tripped by budget refusals raises the same typed outcome. A plain 429 is a rate limit: transient, at most 2 POSTs. Quota (ModulateQuotaError) narrows to 401/403 and a credits marker on any other status. #23234's plain-429 test keeps its 3-attempt assertion under STT_PRERECORDED_VENDOR_FAIL_FAST=false. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ancel in-budget shards (#23270) ## Summary `Backend unit suite` intermittently fails with `backend unit shards result was 'cancelled'` (example: run 39741901310, PR #23263). Root cause: a solo `backend-unit-shard` job crosses the job-level `timeout-minutes: 15` ceiling and GitHub cancels it, so the matrix aggregate is `cancelled` and the gate fails closed with no actionable message. The 15m job ceiling includes runner setup, while the 720s step regression budget deliberately excludes it ("Setup is outside this timer"), leaving only 180s of setup allowance. Measured setup across recent shard jobs: 73-92s typical, but 227s worst (run 39741901310 attempt 2: checkout 72s + apt-get 155s — the apt step is step-capped at 3m and completed within its cap). 227s + 720s = 947s > 900s, so the job was cancelled mid-run while the test step was still inside its budget (687s elapsed, tests actively passing when the runner was killed). This raises the shard job ceiling to 20m, which holds the 720s step budget plus worst-plausible setup and teardown. The 720s step budget check is untouched and remains the regression gate — a slow test step still fails loudly with its slow-tail summary, so the job ceiling stays a hang bound, not the gate. This is a CI flake fix under David's standing 10-22 ask (CI flake fixes fixed at the root; caching/budget changes with evidence approved). The `.github` edit touches only this flake's own step/job; no workflows are added. ## Flake evidence (same signature/mechanism, 4 occurrences in the week to 2026-10-22) Every occurrence is a solo shard cancelled at a 917-920s wall (the 900s ceiling plus teardown): - run 39741901310 attempt 2 (PR #23263): shard 2/6 cancelled at 920s; gate failed with exactly `backend unit shards result was 'cancelled'`; attempt 3 re-ran identical code and shard 2/6 passed — flake, not regression. - run 39739120103 attempt 1 (PR lane/p65-index-prebuild): shard 4/6 cancelled at 918s (gate aggregate said `failure` because another shard also had a real test failure in that attempt). - run 39676205452 attempt 1 (PR lr/01-m3-final-sync2): shard 6/6 cancelled at 918s. - run 39668020536 attempt 1 (PR lane/dream-429-resume): shard 1/6 cancelled at 917s; the run later passed on re-run. Whole-run cancellations (all six shards cancelled together, PR supersede via `cancel-in-progress`) are a separate, by-design path and unaffected by this change. ## Changes - `.github/workflows/backend-unit-tests.yml`: `backend-unit-shard` `timeout-minutes: 15` → `20`, with the measured evidence recorded as a comment at the key. No trigger, matrix, runner, step, or budget-semantics changes; the 720s step budget and the fail-closed gate are untouched. - `scripts/ci/test_nightly_main_workflow.py`: record the change in `INTENTIONAL_BUDGET_CHANGES`, the documented protocol for reviewed budget changes to nightly-reusable jobs (same pattern and failure class as the `ios-compile-check` 40→50 entry); `budget_p50_minutes: 8` in `.github/ci-budget.yaml` is unchanged since the p50 wall does not move. ## Verification - `actionlint -shellcheck "" .github/workflows/backend-unit-tests.yml` — clean. - `backend/tests/unit/test_workflow_contracts.py` — 94 passed (includes `test_backend_unit_suite_is_sharded_with_a_literal_gate_and_budget`, which pins the shard/gate/budget contract; nothing pins the old ceiling). - `scripts/ci/test_nightly_main.py` (15) and `scripts/ci/test_nightly_main_report.py` (10) — pass with the recorded `INTENTIONAL_BUDGET_CHANGES` entry. - `scripts/pr-preflight --pr-body-file` — full check selection passes, including `ci-budget`, `ci-budget-fixtures`, and `main-push-ci-economy-contract`; `make preflight` runs the same selection through the pre-push hook. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/23270?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/23270?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23270&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
…P58) (#23264) ## Summary **Stacked on PR A (#23263, `p58/phase0-vendor-fail-fast`, merged in with a merge commit): merge PR A first; this PR's own change is everything after it.** Self-hosted spoken-language gate for prerecorded STT routing (P58, approved by David 2026-10-22). Today a vendor (Modulate) LID probe decides whether `multi`-language audio may go to Parakeet, which transcribes only 25 European languages. That probe costs ≈$34/day, blocked English entirely when Modulate ran out of credits (10-22 02:00–04:00Z), and misroutes: staging canary 10-22 05:29Z sent 6 s Arabic to Parakeet as `en` 0.926, and soak003 sent 6 s Chinese as `en` 0.80–0.84. - **Parakeet** `POST /v2/language`: Whisper-base language-token head (fp16, Apache-2.0) through the GPU worker queue, loaded before the VRAM baseline; returns `p_supported` (summed probability of the 25 TDT languages), the top language and a route. Parakeet only if `p_supported ≥ 0.95` (≥6 s) or `≥ 0.985` (1–6 s); never under 1 s. `PARAKEET_LID_MODEL` defaults to `whisper-base` in code (the chart is unchanged, per the #21910 pod-template guard); `off` is the kill switch. A load failure leaves transcription serving. `/v2/transcribe` also counts transcript text language (`parakeet_output_language_total`) as the wrong-language alarm. - **Backend shadow** (default on, `STT_PRERECORDED_LANGUAGE_GATE_SHADOW=false` kills it): every unknown-language probe also asks the gate; `omi_stt_language_gate_shadow_total` records self vs vendor; the dangerous direction logs `event=language_gate_shadow_disagreement` with bounded codes and scores only. Routing unchanged. - **Enforcement** `STT_PRERECORDED_LANGUAGE_GATE_PERCENT` (default 0; uid cohort on legacy sync, audio-hash cohort for voice): the gate replaces the vendor probe. The backend re-derives the threshold rather than trusting the service `route`, and requires the top language to be supported. Any gate failure falls back to today's vendor probe path. Batch intake stays shadow-only until its GPU worker accepts `self_lid` evidence (Phase 4). MMS-LID-126 scored better offline but is CC-BY-NC-4.0, so it is not used. ## Evidence (offline, through this serving code; not prod audio) FLEURS 15 languages × 60 clips (full, 6 s, 3 s, 8 kHz copies) + owned synthetic corpus, 4,191 clips, 2,349 unsupported (`/Volumes/Ephemeral/scratch/p58-language-routing/eval/out/gate-whisper-base.final.jsonl`): | | Result | |---|---| | Unsupported → Parakeet at 0.95/0.985 | **0 / 2,349** (2 at 0.90/0.97: hi→ro 0.922, id 3 s→it 0.978) | | Non-speech → Parakeet | 0 / 27 | | Arabic canary (Modulate `en` 0.926) | `ar`, p_supported 0.0072 → multilingual | | soak003 zh 6 s (all 9 codec/noise variants) | `zh`, p_supported ≤ 0.011 → multilingual | | Supported leak to paid | full 6/420 · 6 s 21/420 · 3 s 189/420 · 8 kHz 100/420 | | Latency | p50 0.08 s per clip on Apple MPS (L4 fp16 to be measured on the canary pod) | Production enforcement is gated on the shadow readout (dangerous-direction disagreement ≤0.1% of self-Parakeet segments, output alarm no worse than baseline) and a serving-SHA staging multilingual mini-soak. ## Ramp plan (`STT_PRERECORDED_LANGUAGE_GATE_PERCENT`) - Cohorts: 5% → 25% → 100%, ~30 min holds (David: fully rolled out or ruled not worth doing by 2026-10-22 11:50Z). - Clean metrics: shadow dangerous-direction ≤0.1%; `parakeet_output_language_total` non-P25 share ≤ baseline; sync `upstream_error` and empty-ASR rates flat; multilingual share within ±2 pp of shadow; Parakeet p99/GPU in bounds. - Expander: two-lane lead; p58 owns the evidence. Rollback: percent 0 (vendor probe path unchanged); gate off: `PARAKEET_LID_MODEL=off` or `STT_PRERECORDED_LANGUAGE_GATE_SHADOW=false`. ## Deploy Parakeet GPU image (prod-omi-backend; no chart change): 1 pod first, check VRAM after load (Whisper-base fp16 ≈150 MB) and `/v2/transcribe` p99, then fleet. Cloud Run backend services (config train) for the backend half. No new env needed for shadow; enforcement percent is a later env flip. Failure-Class: FC-deterministic-provider-rejection-burns-connect-retries Line-Count-Exception: backend/utils/sync/pipeline.py | 3659 -> 3660 | passes the uid as the language-gate cohort key at the existing resolve_file call ## Test plan - `BACKEND_UNIT_TEST_FILE_LIST` via `backend/test.sh`: `test_prerecorded_language_gate.py` (38), `test_batch_audio_language.py` (62), `test_parakeet_endpoints.py` (62), `test_parakeet_gpu_worker.py` (72), `test_parakeet_language_gate.py` (19), all pass. - `make preflight` (local lane) passed; feature-flag registry OK. - Real model: `language_gate.load('mps')` over the 4,191-clip eval (table above). - Independent GLM review (SHIP-WITH-FIXES, no below-threshold Parakeet path found); its fixes are in the last commit: GPU priority lane for language ID, `/v1` prerecorded wrong-language alarm, 16 MiB probe cap. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
…sync, move ramp to 10-23 (#23282) ## Summary Three P58 language-gate follow-ups (lead rulings 2de1ea, ca3cc3): 1. **Sync metrics were dropped (fix).** `backend/deploy/cloud_run_gmp_sync.yaml` keeps only allowlisted `omi_*` names on backend-sync and backend-sync-backfill. `omi_stt_language_gate_*` (#23264) and `omi_prerecorded_vendor_*` (#23263) were not on the list. Legacy sync makes almost all prerecorded probes. Prod 10:05–10:35Z after train T: 23,015 vendor probes on sync with 0 shadow series, against 43/43 on backend. So the shadow readout that gates enforcement, and the Phase 0 vendor burn and breaker metrics, were invisible there. The PR adds both prefixes, plus a test that reads the real keep regex and asserts every such collector matches it. 2. **`/v2/language` was never routed (fix).** The `parakeet.omi.me` Ingress lists only `/v1/transcribe`, `/v2/transcribe`, `/v3/stream` and `/health`. Every gate call 404ed at the internal load balancer: on 10:47Z, the new cfbcf20 pods served `/v2/transcribe` and received zero `/v2/language` requests. This PR adds the path in prod and dev values. The #21910 pod-template guard now admits exactly that one Ingress path, on the same backend as `/v2/transcribe`; new mutation cases reject a different backend or any other path. It ships with a `gcp_parakeet` helm apply (an Ingress URL-map change, no pod restart from it). Rollback: `helm rollback prod-omi-parakeet`. Callers fall back to the vendor probe either way. 3. **Registry (chore).** The `STT_PRERECORDED_LANGUAGE_GATE_PERCENT` ramp `done_by` moves 2026-10-22 → 2026-10-23, with the ruling in the notes. On 10-22, the lead (ruling ca3cc3, under David's 6 h rule) ruled the same-day rollout not worth finishing: shadow accrues and enforcement ramps 5/25/100 off-peak on 10-23. The rendered doc was regenerated, and `check_feature_flag_registry.py` reports OK. No behaviour change. The sync allowlist takes effect on the next Cloud Run deploy of backend-sync and backfill, which must land before the 10-23 ramp readout. Failure-Class: FC-metric-dropped-by-scrape-allowlist ## Verification - `test_batch_audio_language.py` (new allowlist test), `test_attach_cloud_run_gmp_sidecar.py`, `test_fleet_deployment.py`, `test_parakeet_request_metrics.py`, `test_monitoring_gmp_shadow.py`: pass via `test.sh`. - `test_audio_fleet_helm.py` and the other 11 files that render Parakeet/Ingress charts: pass (dev and prod against current main). - Prod (ro-prod GMP): `omi_stt_language_gate_*` series exist only for service_name=backend. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
P58 Phase 0 (approved by David 2026-10-22): prerecorded Modulate calls fail fast instead of amplifying a vendor
outage. On 10-22 02:00–04:00Z Modulate returned 429 "Insufficient credits"; every failed segment cost 5 POSTs
(bytes path attempts 0/1/2, then the URL wrapper re-entered at 1/2) and the LID probe swallowed the 429 as
und.TranscriptionFailure(PROVIDER_BUDGET_EXHAUSTED, retryable=False)after 1 POST; Phase 0 adds its burnaccounting and breaker feed. Other auth/quota rejections (401/403, or a credits marker on another status) raise
ModulateQuotaError(aRuntimeErrorkeeping theModulate transcription failedprefix, so classification isunchanged:
UPSTREAM_ERROR, retryable) after 1 POST. A plain 429 is a rate limit and stays transient.URL wrapper retries only the download and never re-enters the paid path.
stt,lid), process-local: 5 quota errors in 60 s open it; while open, callsmake no HTTP request; after 60 s one half-open trial (success closes, quota re-opens, non-quota failure releases the
trial and keeps it open; an abandoned trial expires after 360 s). A breaker opened by budget refusals raises the same
typed
PROVIDER_BUDGET_EXHAUSTEDoutcome, so fix(stt): classify Modulate out-of-credits (429 "Insufficient credits", 402) as provider_budget_exhausted #23234's page and sync outcome counting hold. Gaugeomi_prerecorded_vendor_breaker_open.omi_batch_pipeline_language_probe_total{outcome}(one perdetect()call: accepted, quota,http_5xx, http_4xx, timeout, transport, invalid_response, unsupported_format, no_key, skipped, breaker_open,
error) and
omi_prerecorded_vendor_audio_seconds_total{provider,endpoint,outcome}(Modulate burn, the missingspend signal).
detect()returns exactly the same decisions as before.STT_PRERECORDED_VENDOR_FAIL_FAST(default on; onlyfalserestores today's exact retry ladderand disables the breaker).
Not done: the voice-message
stt_providermislabel needs the selected provider surfaced from the transcriptioncall; out of the contained budget, left for a follow-up.
Failure-Class: FC-deterministic-provider-rejection-burns-connect-retries
Test plan
backend/test.shwithBACKEND_UNIT_TEST_FILE_LIST:test_prerecorded_vendor_fail_fast.py(35: quota → 1 POST,503/timeout → 2 POSTs, URL 429 → 1 GET + 1 POST, kill switch → legacy 3/5 POSTs, breaker open/half-open/re-open/
wedge/expiry, every
detect()outcome),test_modulate_prerecorded_language.py(49),test_batch_audio_language.py(62); 14-file related set 182 passed.test_modulate_prerecorded_language.py, fix(stt): classify Modulate out-of-credits (429 "Insufficient credits", 402) as provider_budget_exhausted #23234'stest_plain_429_stays_a_retryable_upstream_error) now pin it withSTT_PRERECORDED_VENDOR_FAIL_FAST=false(assertions unchanged); the new behaviour (2 POSTs) is asserted in the new file. After merging main: 280 pass across
the fail-fast, modulate STT, modulate language, batch language and transcription-outcome suites.
scan_async_blockers.py,scan_import_time_side_effects.py, feature-flag registry: clean.Deploy / rollback
Cloud Run backend services (backend, backend-sync, backend-sync-backfill, backend-integration) via the normal train.
Rollback:
STT_PRERECORDED_VENDOR_FAIL_FAST=false.🤖 Generated with Claude Code