Skip to content

fix(listen): don't count cancelled Parakeet sessions as connection_lost - #22372

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/opus-parakeet-cancelled
Oct 19, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/opus-parakeet-cancelled

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Since 10-14 the STT routing disruption gate (STT_ROUTING_DISRUPTION_GATE=0.08) has benched Parakeet for 10–16 h/day. That sends English sessions to Soniox first, at about $75/day. The bench trigger is Parakeet-window failovers counted as connection_lost. At peak (14–21Z) they went from 2.1% of successes to 10.2%.

The suspected mechanism is a reason-vocabulary gap. When listen cancels a Parakeet window's pump task (owner close, recovery switch, teardown), the window latches death_reason='cancelled' (parakeet_window.py _pump CancelledError branch and _on_pump_done). cancelled was not in LIVE_STT_REASONS, so normalize_live_stt_reason defaulted it to connection_lost. That is a provider failure, and it fed both the cost-routing gate and the serving circuit.

This PR makes cancelled a known, censored reason:

  • backend/utils/stt/live_reason.py: adds 'cancelled' to LIVE_STT_FAILURE_REASONS. provider_observation already returns None (censored) for every reason outside PROVIDER_FAILURE_REASONS, so a cancelled failover moves neither the gate's numerator nor its denominator. record_session returns before transition. It also does not open the serving circuit (_SERVE_FAILURE_REASONS is unchanged).
  • backend/utils/stt/parakeet_window.py: omi_stt_window_session_outcome_total now records reason="cancelled" instead of none for a cancelled session. There is also a comment on the cancel branch. The reason flows through the window's bounded raw death_reason, which LiveLegSocket.normalized_death_reason, live_stt_terminal_reason and PendingLiveFailover.from_socket already read. It is deliberately not exposed as typed_death_reason: in LiveLegSocket.typed_death_reason a raw typed reason outranks _local_death_reason, so a typed cancelled would mask a listen-local send_failed or vad_failed latched just before the transport was finished. The existing precedent for this channel is test_window_bounded_raw_reason_wins_even_without_typed_proxy.
  • The 0.08 threshold is unchanged.

Unchanged (genuine provider-side drops still count): a pump that ends without listen closing or cancelling it is still connection_lost. POST 5xx, 413, bad JSON and transport exceptions are still provider_5xx, and timeouts are still timeout. An unknown or free-text reason still defaults to connection_lost.

Metric label split (low cardinality: one new value per existing label set)

reason="cancelled" now appears as its own value on:

  • omi_stt_cost_routing_observations_total{target,outcome="censored",reason="cancelled"}, which is the gate input.
  • omi_stt_cost_routing_settlements_total{target,outcome="censored",reason="cancelled",path}
  • omi_fallback_total{component="stt_live_session",from_mode="parakeet",reason="cancelled",...}
  • omi_stt_window_session_outcome_total{outcome,reason="cancelled"}
  • omi_live_stt_terminal_failures_total (phase connection, the same bucket as before)

Alert and recording-rule impact

I searched backend/charts/monitoring/ (alerts, alert-rules.json, dashboards). No alert or recording rule selects reason="connection_lost".

  • omi_stt_window_session_outcome_total alerts (live-stt.json): the no-text ratio sums over reason, so it is unchanged. Only the label value moves from none to cancelled.
  • The omi_live_stt_terminal_failures_total{phase=~"connection|send"} rate: cancelled maps to phase connection, so it is unchanged.
  • omi_fallback_total alerts select outcome, to_mode, or specific reasons (capacity_full, gate_unavailable, cache-write reasons). They are unchanged.
  • The cost-routing settlement and evidence-error alerts sum over reason, so they are unchanged.
  • Dashboards or ad-hoc queries that read reason="connection_lost" for target="parakeet-window" will drop by the cancelled share. That is the intended correction, and the drop now appears under reason="cancelled".

Coordination

#22365 ("perf(listen): close idle Soniox sockets sooner") touches Soniox socket and idle code. This PR touches none of the same files or functions. The only shared module is the reason vocabulary (live_reason.py), which #22365 does not edit.

Product invariants affected

none. This is health attribution and telemetry only. It changes no transcript content, audio custody or client-facing behavior. Failover itself is unchanged; only its classification changes.

Failure class (fixes)

Failure-Class: new

New definition added in this PR: .github/failure-classes/FC-listen-cancellation-counted-as-provider-failure.json. When listen cancels a live STT leg itself, the leg's death token must be a bounded, censored reason. A token outside the vocabulary defaults to connection_lost and charges the provider in the routing gate and the serving circuit. No existing class covers this; the closest, FC-rollout-state-counted-as-failover, covers selection state, not death attribution.

Tests

backend/tests/unit/test_live_health_reason_reconciliation.py:

  • CASES adds Parakeet cancelled (censored), a free-text unknown (falls back to connection_lost, provider_failure) and a raw connection_lost (provider_failure). Each runs across the monitor, send_false and send_exception observers and the recovered, degraded and exhausted settlements.
  • test_listen_cancelled_real_window_is_censored_not_connection_lost[task_cancel|transport_finish]: a real WindowedParakeetSocket is cancelled during an in-flight POST. The leg's reason is cancelled, the failover hop carries cancelled, the censored observation and settlement counters each increment once, window_session_outcome{reason="cancelled"} increments, and the gate state is untouched.
  • test_window_pump_ending_on_its_own_is_still_connection_lost: a provider-side drop still counts against the provider (n == failures == 1).
  • test_cancelled_failovers_cannot_trip_the_disruption_gate: 50% cancelled failovers across 400 distinct users leave the gate at stage 100 with failures == 0, and n counts only the text sessions. The threshold stays 0.08.
  • test_connection_lost_failovers_still_trip_the_disruption_gate: the same mix with connection_lost benches the target.
  • test_unknown_failover_reason_still_counts_against_the_provider[None|free text]: an unknown or missing reason still counts against the provider.
  • The vocabulary test now expects 32 reasons, and cancelled is asserted censored.

Local runs (backend test.sh, nice -n 19):

  • test_live_health_reason_reconciliation.py: 193 passed. With the live_reason.py change reverted, 13 of the new and updated cases fail.
  • The 42 unit files that reference the reason vocabulary, the window metric, live_failure or parakeet_window all pass.

Verify in prod after deploy

  1. sum by (outcome, reason) (increase(omi_stt_cost_routing_observations_total{job="backend-listen-metrics",target="parakeet-window",reason=~"cancelled|connection_lost"}[1h])). reason="cancelled" appears as outcome="censored", and provider_failure,connection_lost should fall by about the same amount if the hypothesis holds.
  2. sum by (reason) (increase(omi_fallback_total{job="backend-listen-metrics",component="stt_live_session",from_mode=~"parakeet.*"}[1h])) gives the cancelled vs connection_lost split of window failovers.
  3. max by (target) (omi_stt_cost_routing_stage{job="backend-listen-metrics",target="parakeet-window"}) should stay at 100 through the 14–21Z peak, and omi_stt_cost_routing_decisions_total{reason="cost_primary",target="soniox"} should return toward about 14k/day.
  4. Guard: Parakeet transcript-outcome no_text (omi_stt_window_session_outcome_total{outcome="no_text"} ratio) does not rise.

If cancelled turns out to be a small share of connection_lost, the hypothesis is wrong, and the config fallback (raising the gate to 0.15) stays on the table.

Rollback: revert this commit.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits October 19, 2026 11:16
A Parakeet window whose pump task listen cancels (owner close, recovery
switch, teardown) latches death_reason='cancelled'. That token was not in
the bounded live-STT vocabulary, so normalization defaulted it to
connection_lost: a provider failure that feeds the STT routing disruption
gate and the serving circuit.

Add 'cancelled' as a known, censored reason. It now appears as its own
label value on the cost-routing observation/settlement counters, the
fallback counter and the window session outcome counter, and it moves
neither the gate numerator nor its denominator. A pump that ends on its
own, POST errors and unknown free-text reasons keep their provider
classification. The 0.08 threshold is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T04:31:23.094006Z 7966f2c PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level merged commit e963f8a into main Oct 19, 2026
62 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/opus-parakeet-cancelled branch October 19, 2026 05:26
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