fix(deepgram): validate updated model with stored language#1755
fix(deepgram): validate updated model with stored language#1755rosetta-livekit-bot[bot] wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 893b698 The changes in this PR will be included in the next version bump. This PR includes changesets to release 34 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| const model = | ||
| opts.model !== undefined ? this.#validateModel(opts.model, language) : this.#opts.model; |
There was a problem hiding this comment.
🟡 Model validation skipped when only language is updated via updateOptions
In updateOptions, the model is only validated when opts.model !== undefined. If a caller changes only the language (e.g., updateOptions({ language: 'fr' })) while the current model is an English-only one like 'nova-2-meeting', the validation is skipped and the incompatible model/language combination persists. This defeats the purpose of the PR, which is to ensure model validation happens in updateOptions.
For example: a user creates new STT({ model: 'nova-2-meeting', language: 'en-US' }) (valid), then calls updateOptions({ language: 'fr' }). The model variable at line 124 takes the this.#opts.model path (no validation), resulting in 'nova-2-meeting' being used with French — exactly the case #validateModel is supposed to catch.
| const model = | |
| opts.model !== undefined ? this.#validateModel(opts.model, language) : this.#opts.model; | |
| const model = this.#validateModel(opts.model ?? this.#opts.model, language); | |
Was this helpful? React with 👍 or 👎 to provide feedback.
| updateOptions(opts: Partial<STTOptions>) { | ||
| const language = | ||
| opts.language !== undefined ? normalizeLanguage(opts.language) : this.#opts.language; | ||
| const model = | ||
| opts.model !== undefined ? this.#validateModel(opts.model, language) : this.#opts.model; | ||
|
|
||
| this.#opts = { | ||
| ...this.#opts, | ||
| ...opts, | ||
| language, | ||
| model, | ||
| }; |
There was a problem hiding this comment.
🚩 detectLanguage flag not handled in updateOptions
The constructor at line 108-109 sets this.#opts.language = undefined when detectLanguage is true, and skips model validation. However, updateOptions does not mirror this behavior — if a caller passes updateOptions({ detectLanguage: true }), the language won't be cleared and the model validation still runs against the stale language. This is a pre-existing issue (the old code also didn't handle it), and may be intentionally left as a caller responsibility, but it creates an inconsistency between construction-time and update-time semantics.
Was this helpful? React with 👍 or 👎 to provide feedback.
Ports livekit/agents#6041 to agents-js.\n\nSummary:\n- Reuses Deepgram STT model validation from construction when updateOptions changes the model.\n- Uses an explicitly provided language for validation, otherwise falls back to the stored language.\n- Adds a patch changeset for the Deepgram plugin.\n\nTests:\n- pnpm exec prettier --write "plugins/deepgram/src/stt.ts"\n- pnpm --filter @livekit/agents-plugin-deepgram... build\n\nNo tests added, matching the requested port constraint.
Ported from livekit/agents#6041
Original PR description
`STT.update_options` and `SpeechStream.update_options` both call `_validate_model(model, language)` using the caller's `language` parameter. When only the model is changed, `language` is `NOT_GIVEN`, so `_validate_model` skips its English-only model check entirely — allowing an incompatible model/language pair to be stored silently.
For example, after `STT(language="fr")`, calling `update_options(model="nova-2-meeting")` would accept `nova-2-meeting` (English-only) with no warning, instead of falling back to `nova-2-general`.
Fix: pass `self._opts.language or NOT_GIVEN` when the caller omits `language`, so the stored language is used for validation.
Fixes #6047
Test plan
```
uv run pytest tests/test_plugin_deepgram_stt.py --plugin deepgram -v
```