Repository navigation
fix(backend): PTT transcribe-stream fails over at the audio send path - #12492
Merged
Git-on-my-level merged 2 commits intoAug 31, 2026
Merged
Git-on-my-level merged 2 commits into
Git-on-my-level merged 2 commits into
Conversation
Live 24h realtime_voice on the PTT surface: 4 success, 13 provider_error terminals, all paired with "Modulate streaming error" frames. BasedHardware#12469 gave listen a send-path failover; PTT still terminated the session on the first rejected send, so a Velma/Modulate socket that accepts the upgrade and dies ~300ms later on the first audio chunk ended the session with 1011 even while the chain held a healthy replacement (14 ptt provider_terminal_failure in 24h, zero mid-session failovers on the PTT path). Port the listen pattern instead of forking it: send_stt_audio_or_close now routes through utils/stt/live_failure.send_live_stt_audio with an attempt_failover callback that rebuilds the socket on the next provider in the chain (selector exclude set, MAX_STT_FAILOVERS bound, liveness-proven before adoption). A successful failover reports the chunk unsent and the bounded retry sends it against the replacement socket, so no audio is dropped. The terminal path now shares terminate_live_stt_session with listen: journey fail('provider_error') via the shared session adapter, a terminal service_status event, then close 1011 — previously the PTT close carried no status event and a different reason string, and both desktop PTT clients ignore non-array frames (Array.isArray guard in omiListen.ts). The event=ptt_transcription_stream outcome=provider_terminal_failure log line is kept on every terminal. Codec/paywall/budget/idle-timeout paths are unchanged; MAX_STT_FAILOVERS moved to utils/stt/live_failure.py so both surfaces share one bound. Verification: - backend/tests/unit/test_desktop_transcribe.py: 71 passed (RED confirmed by reverting routers/chat.py: the new failover test fails with a 1011 close and no transcript; GREEN with the fix). - test_live_stt_failure.py + test_stt_session_failover.py: 27 passed standalone (test_excluding_every_provider_selects_nothing fails in a combined run identically on pristine origin/main — pre-existing, untouched). - Live self-test: real uvicorn serving the endpoint, local fake Parakeet /v3/stream, dummy Modulate key — healthy segment received; killing the provider mid-session produced the connect-time fallback telemetry, the failover attempt, the terminal service_status event, close 1011, and the provider_terminal_failure log line. Failure-Class: FC-recoverable-provider-failure-terminal
Member
Author
|
CI Backend unit suite is red on This is a circular import, not a missing symbol ( Fix on this branch (keep product behavior):
Do not revert the send-path failover. Push to |
…test cycle Module-level import of utils.stt.live_failure from routers.chat pulled observability.transcription while chat unit tests imported the router, raising ImportError: cannot import name record_live_stt_failure. 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
Live 24h
realtime_voiceon the PTT surface (/v2/voice-message/transcribe-stream): 4 success, 13 failure — allprovider_error, 5 cancelled. Cloud Logging pairs 14event=ptt_transcription_stream outcome=provider_terminal_failurewith 14Modulate streaming error, clustered 13:00–14:56 UTC. Not a metrics lie, not a Beta-vs-prod app gap: the same Cloud Run backend serves both, and the serving SHA (e1eca38) already carries #12469.#12469 fixed listen mid-session STT failover at the send path. PTT still did this on the first rejected send:
Velma/Modulate accepts the WebSocket upgrade and only then dies ~300ms later on the first audio send — the exact shape #12469 closed for listen. PTT's connect-time
connect_stt_socket_with_fallbackcannot help there, so a recoverable death terminated the session with 1011 while the chain still held a healthy replacement. The 13 failures never received a nonempty transcript;ClientJourneyAttempt.finishbeing one-shot is why the 4 working sessions stayed successes.Not Beta vs prod. Not dashboard math. Out of scope by design: Grafana/
client_kind(SCA-388), success-rate PromQL, provider chain order, desktop client changes.Fix
Port the listen send-path failover onto PTT — reuse, not a fork:
send_stt_audio_or_closenow routes throughutils/stt/live_failure.py::send_live_stt_audio(..., attempt_failover=...)._failover_stt_socket: dead-provider exclusion set fed toget_stt_service_for_language(..., surface=PTT, exclude=...), bounded byMAX_STT_FAILOVERS(moved toutils/stt/live_failure.pyso both surfaces share one bound), replacement proven serving (fallback_socket_is_serving) before adoption, rejected rebuilds released.terminate_live_stt_sessionwith listen via a small_PTTStreamSessionadapter: journeyfail('provider_error')only when the chain is exhausted (or no socket was ever initialized), one terminalservice_statusevent, then close 1011 — the same wire contract as/v4/listen. Both desktop PTT lane parsers ignore non-array frames (Array.isArrayguard indesktop/windows/src/main/ipc/omiListen.ts), and the e2e suites collect segment arrays only.succeed()on first nonempty transcript; theevent=ptt_transcription_stream outcome=provider_terminal_failurelog line on every terminal; codec/paywall/budget/idle-timeout cancel behavior.Verification
backend/tests/unit/test_desktop_transcribe.py— 71 passed. New behavioral tests:test_ws_send_path_death_fails_over_and_retries_chunk(GREEN: swaps parakeet→modulate, retries the same chunk verbatim, noprovider_error, later transcriptsucceed()s; RED against the pre-fix endpoint: same test 1011s with no failover — verified by revertingrouters/chat.py).test_ws_send_path_death_with_exhausted_chain_closes_1011(replacement that never serves is released;provider_error+ 1011; no usage charge).test_live_stt_failure.py+test_stt_session_failover.py(listen failover) — 27 passed.test_excluding_every_provider_selects_nothingfails when these files run combined withtest_desktop_transcribe.py, identically on pristineorigin/main— pre-existing selection-order interaction, untouched by this PR.uvicornserving the real endpoint (auth bypassed viaapp.dependency_overridesonly), local fake Parakeet/v3/streamWebSocket, dummy Modulate key. Healthy phase: connect-time fallbackfrom=modulate to=parakeet outcome=recovered, transcript segment received over the live socket. Killed the provider mid-session: send-path death latched, failover attempted, chain exhausted, terminalservice_status stt_failedevent received, close 1011,event=ptt_transcription_stream outcome=provider_terminal_failurelogged.scripts/backend-python-format --check,backend/scripts/scan_async_blockers.py,backend/scripts/check_module_stub_pollution.py: clean.Failure-Class: FC-recoverable-provider-failure-terminal
Line-Count-Exception: backend/routers/chat.py | 1935 -> 2097 | PTT send-path failover is session closure state over ~15 endpoint locals (socket, provider selection, journey, buffers), mirroring listen whose equivalent lives inside its receiver class; splitting the endpoint out of chat.py is a separate mechanical PR. +3 lines are a lazy live_failure import to break the chat-test circular import.