Skip to content

fix(google): validate the STT adaptation before applying update_options - #8172

Open
ShivamSharma43 wants to merge 1 commit into
livekit:mainfrom
ShivamSharma43:fix/google-stt-validate-adaptation-first
Open

ShivamSharma43 wants to merge 1 commit into
livekit:mainfrom
ShivamSharma43:fix/google-stt-validate-adaptation-first

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Problem

google.STT.update_options assigns languages, detect_language, interim_results, punctuate, spoken_punctuation and profanity_filter first, and only then checks that the adaptation fits the model's API version:

from google.cloud.speech_v1.types import resource as resource_v1

stt = google.STT(model="chirp_3", languages="en-US")
stt.update_options(languages="fr-FR", punctuate=False, adaptation=resource_v1.SpeechAdaptation())
# ValueError: adaptation must be cloud_speech_v2.SpeechAdaptation for v2 models, got SpeechAdaptation

The call raises, but the STT now has languages == ["fr-FR"] and punctuate == False. Streams opened afterwards use them, although the caller was told the update failed. A model switch that the current adaptation doesn't fit leaves the same partial state (for example, update_options(model="long", languages="de-DE") on a STT that holds a v2 adaptation).

Fix

update_options now resolves the target API version and validates the adaptation before it assigns anything. Nothing else changes: the same calls are accepted, the error messages are the same, and open streams are updated only after the checks pass, as before.

Tests

Two tests added to tests/test_plugin_google_stt.py:

  • test_update_options_rejected_adaptation_changes_nothing: a v1 adaptation on chirp_3, passed with every option assigned before the check, leaves all of them unchanged.
  • test_update_options_rejected_model_switch_keeps_languages: switching to a v1 model while a v2 adaptation is set leaves the languages, punctuate and the model unchanged.

Both fail on main.

pytest tests/test_plugin_google_stt.py --plugin google    # 27 passed
ruff check / ruff format --check on the changed files
mypy -p livekit.plugins.google                              # Success: no issues found

🤖 Generated with Claude Code

STT.update_options applied languages, detect_language, interim_results,
punctuate, spoken_punctuation and profanity_filter before checking that
the adaptation fits the model's API version. A rejected adaptation (or a
model switch the current adaptation doesn't fit) raised ValueError with
those options already changed on the STT, so later streams used them
although the call failed. Resolve and validate the adaptation first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ShivamSharma43
ShivamSharma43 requested a review from a team as a code owner October 27, 2026 13:27
Copilot AI balanced review requested due to automatic review settings October 27, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
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.

2 participants