Skip to content

fix(users): gate multi-language mode by the live STT capability policy - #10097

Merged
undivisible merged 3 commits into
BasedHardware:mainfrom
aryanorastar:fix/10022-multilang-eligibility
Jul 21, 2026
Merged

undivisible merged 3 commits into
BasedHardware:mainfrom
aryanorastar:fix/10022-multilang-eligibility

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • PATCH /v1/users/language now derives single_language_mode from the live STT capability policy (config.stt_provider_policy.supports_live_multilingual_mode) instead of the retired Deepgram Nova-3 multi-language list.
  • The client mirror (app/lib/providers/home_provider.dart) is updated to the same base-code set with the same regional-variant normalization, and documents which policy file it mirrors.
  • Users whose language the live Modulate auto-detection supports but the old 19-locale Deepgram list did not — Vietnamese, Korean, Turkish, Arabic, Thai, and ~40 others — can now actually enter live multi-language mode.

Fixes #10022.

Root cause

Two stale copies of a capability decision. #10023 moved live multi-language capability to the policy boundary (supports_live_multilingual_mode, consumed by the serving path in utils/stt/streaming.py), but the preference gate — the route that decides single_language_mode when a user picks a language — still consulted deepgram_nova3_multi_languages, as did its client-side mirror. A supported user was silently locked into single-language mode at preference-set time, before serving policy ever ran.

Failure class

Failure-Class: none

The nearest theme is again divergent read-side policy copies rather than mutable-state transition ownership (FC-split-mutation-authority's scope) — same call as #10094/#10095.

What stays untouched, and why

  • utils/stt/streaming.py's Deepgram runtime branch keeps deepgram_nova3_multi_languages: that code selects Deepgram serving parameters, the one place the Deepgram-specific vocabulary legitimately lives.
  • migrations/006_auto_set_transcription_mode.py is a historical migration; rewriting it would change what a past migration meant.

Product invariants affected

none (verified with scripts/pr-preflight --suggest)

Validation

  • New coverage extends tests/unit/test_stt_provider_policy.py (the guard surface for this policy boundary): behavioral checks that the live policy admits the newly eligible languages (vi, vi-VN, ko, tr, ar, th, pt-BR, en) and rejects unsupported ones (my, am, lo), plus a labeled static tripwire that the route derives single_language_mode from supports_live_multilingual_mode and that deepgram_nova3_multi_languages no longer appears in the route module. The tripwire fails on pre-fix code by construction.
  • The route wiring itself is one line; a full route-handler harness for routers/users.py's heavy import graph would have required module-scope sys.modules stubbing, which the backend-module-isolation checker bans outside the frozen legacy allowlist — hence policy-seam behavioral tests + tripwire, per the repo's testing guidance.
  • Repo runner (file-isolated, as CI executes): tests/unit/test_stt_provider_policy.py → 20 passed.
  • Dart unit test (app/test/unit/multilingual_eligibility_test.dart) covers the client mirror's eligibility set and normalization. Not run locally — this machine has no Flutter SDK; the test is hermetic and the app CI lane discovers app/test/unit/. Backend coverage of the same decision did run locally.
  • make preflight (local lane, this PR body) → all selected checks pass.
  • black clean on changed backend files.

Not exercised live: the full app→backend language-selection flow on a device (no Flutter toolchain here). The behavior change is the server-side gate, covered by the policy-seam tests and tripwire above.

Out of scope, named

  • The duplicated client list still exists by necessity (Dart cannot import the Python policy); a follow-up could serve eligibility from the backend response instead of mirroring the set. The route response already returns single_language_mode, so clients that trust the server need no list at all — the mirror only affects optimistic local state.

Review in cubic

PATCH /v1/users/language derived single_language_mode from the retired
Deepgram Nova-3 multi-language list (19 locales), while live serving
admits the much broader Modulate auto-detection set via
supports_live_multilingual_mode. A user picking a supported language
outside the old list — Vietnamese, Korean, Turkish, Arabic, Thai, and
~40 others — was silently forced into single-language mode and could not
use live multi-language transcription (BasedHardware#10022).

The route now derives the gate from the policy boundary
(config.stt_provider_policy.supports_live_multilingual_mode), which also
normalizes regional variants. The client mirror in home_provider.dart is
updated to the same base-code set with the same normalization, replacing
its stale Deepgram list, and links the policy file it mirrors.

The Deepgram-specific runtime branch in utils/stt/streaming.py keeps its
own list: that code selects Deepgram serving parameters and is the one
place the Deepgram vocabulary legitimately lives.

Tests: policy-boundary behavioral coverage for the newly admitted and
still-rejected languages plus a labeled static tripwire that the route
derives from the live policy and the retired list is gone from the route
module; Dart unit coverage for the client mirror's eligibility and
normalization.

Fixes BasedHardware#10022.

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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the core invariant of this fix: the new client multiLanguageSupported set is byte-for-byte identical to the backend config.stt_provider_policy.MODULATE_SUPPORTED_LANGUAGES (61 base codes on each side, same membership), and the regional-variant normalization (split('-').first.split('_').first.toLowerCase()) matches normalized_stt_language exactly. So the client mirror and the route gate now both agree with the live serving policy — the stale Deepgram Nova-3 copy that was silently locking vi/ko/tr/ar/th (and ~40 others) into single-language mode is gone from the preference path.

Nice touches:

  • Keeping deepgram_nova3_multi_languages only in utils/stt/streaming.py (Deepgram serving params) and leaving the historical migration untouched is the right call.
  • The static tripwire asserting the route derives single_language_mode from supports_live_multilingual_mode and that deepgram_nova3_multi_languages no longer appears in routers/users.py will catch future regressions of exactly this class.

One observation (non-blocking): the duplicated client list is unavoidable today since Dart can't import the Python policy, but the route already returns single_language_mode in its response — so the app could eventually trust the server response for local state and drop the mirror entirely. Worth a follow-up but correctly out of scope here.

Not formally approving because this sits on the STT provider-routing / user-preference-persistence boundary; flagging for a maintainer's final call. The fix itself looks correct and well-tested.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Jul 20, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed by automated PR reviewer — approving; holding merge (see notes).

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level @undivisible This PR is fully approved and ready to merge. Could you please trigger the merge when you have a moment? Thank you!

@undivisible
undivisible merged commit 5319c3e into BasedHardware:main Jul 21, 2026
29 of 30 checks passed
@undivisible

Copy link
Copy Markdown
Collaborator

looks good ty :))

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Thanks! On the non-blocking observation — the app could trust the server's single_language_mode and drop the mirror entirely — I did exactly that in #10126, stacked on this branch. Merge this first and #10126 collapses to just the mirror deletion.

@undivisible

Copy link
Copy Markdown
Collaborator

holy em dash

undivisible added a commit that referenced this pull request Jul 24, 2026
…on (#10074) (#10170)

# Summary

The regression test #10100 deferred. #10100 fixed the quick-template
sheet so a failed install is surfaced as an **error** instead of a false
success (#10074), but shipped **without a regression test** — the
decision lived inline in the widget's post-`await` branch, unreachable
by a hermetic test without a full widget harness (five stubbed API calls
plus `path_provider` platform channels).

This extracts **only that decision** — the success/error polarity of the
terminal outcome — into `templateCreationOutcomeIsError`, a pure
function the sheet now derives its install-branch snackbar from.
Everything else is byte-identical to #10100.

- New `TemplateCreationOutcome` enum + `templateCreationOutcomeIsError`
(one pure file, no Flutter deps).
- The sheet's install branch sources its success/error choice from the
classifier instead of an inline `bool`; the arm order flips
(error-first) but the behavior is identical.
- Unit tests pin the full outcome table, including `installFailed →
error` — the #10074 guarantee — so the failed-install-reads-as-success
regression cannot be silently reintroduced.

## Behavior identity (verified line-by-line)

Diff is the import line + the install-branch arm-swap; **nothing else in
`_createTemplate` changed**. Confirmed unchanged vs the #10100 baseline:
`quickTemplateCreated` analytics timing (still fires on submit success,
before install), `getApps()` ordering (still before install), the `if
(mounted && createdApp != null)` gating (so a mid-flow sheet dismissal
still cancels install exactly as before), the
`createdWithoutInstall`/`submitFailed` branches, and the catch block.

- `success → installed → not error → appCreatedAndInstalled +
summarized-apps sheet`
- `!success → installFailed → error → failedToInstallApp` (provider
already showed its dialog)

## Failure class

Failure-Class: none

`test:` commit — adds the regression coverage a prior `fix:` (#10100)
deferred; no new triggering defect.

## Product invariants affected

none (verified with `scripts/pr-preflight --suggest`)

## Validation

- Five hermetic unit tests
(`app/test/unit/template_creation_outcome_test.dart`) pin the table:
`installFailed → true` and `submitFailed → true` (errors); `installed →
false` and `createdWithoutInstall → false` (success); plus an
exhaustiveness assertion that exactly `{submitFailed, installFailed}`
read as errors. Each calls the exact function production calls —
flipping the classifier fails the test.
- **Not run locally — no Flutter SDK on this machine** (same stated
constraint as #10097/#10100/#10126, all merged/approved); tests are
hermetic and the app CI lane runs them.
- Behavior identity and analyzer-cleanliness (imports used, exhaustive
switch, no `use_build_context_synchronously` regression,
`createdApp.name` non-null promotion intact) independently reviewed
against the #10100 baseline before opening.
- `make preflight` (local lane, this PR body) → all selected checks
pass.

## Out of scope, named

- The `submitFailed`/`createdWithoutInstall` outcomes are classified and
tested but the sheet's other two branches still snackbar inline (they
were never the #10074 surface and have a single, unconditional
polarity). Routing them through the classifier too would be ceremony,
not safety.
- A broader flow-orchestration extraction was considered and dropped: it
drifted analytics timing, `getApps()` ordering, and mid-dismiss install
behavior for no gain over this focused pin.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/10170?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="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
undivisible pushed a commit that referenced this pull request Jul 24, 2026
…nt mirror

Follow-up to #10097, doing what its out-of-scope note and review both
pointed at: PATCH /v1/users/language already returns the
single_language_mode the server derived from the live STT capability
policy, so the client list mirroring MODULATE_SUPPORTED_LANGUAGES — and
the drift risk that comes with every future policy change — is deleted.

setUserPrimaryLanguage now returns the server-decided mode (null on
failure) and updateUserPrimaryLanguage syncs local state from that
response. No eligibility decision remains client-side.

The mirror's unit test is replaced by a wire-contract test pinning that
the response carries single_language_mode and fails loudly when absent —
the property that makes trusting the server safe.

Not run locally (no Flutter SDK on this machine); hermetic, app CI lane
compiles and runs it. Depends on #10097 (stacked on its branch).

Co-Authored-By: Claude Fable 5 <[email protected]>
undivisible added a commit that referenced this pull request Jul 24, 2026
…nt mirror (after #10097) (#10126)

# Summary

Follow-up to #10097, doing exactly what its out-of-scope note and
Git-on-my-level's review both pointed at: the client-side mirror of
`MODULATE_SUPPORTED_LANGUAGES` is deleted, and the app trusts the
`single_language_mode` the server already returns from `PATCH
/v1/users/language`.

- `setUserPrimaryLanguage` now returns the server-decided mode (`bool?`,
null on any failure) instead of discarding the parsed field;
`updateUserPrimaryLanguage` syncs local state from that response.
- No eligibility decision remains client-side — future policy changes
(new languages, provider swaps) reach the app with zero client releases
and zero drift risk.
- **Stacked on #10097** (its branch is the base of this diff; merge it
first — this PR then shows only the one commit).

# Why now

#10097 made the mirror byte-for-byte correct; the review verified that
equality manually. That manual verification is exactly the maintenance
burden this removes: the wire response is the contract, so the list and
its normalization helper go away entirely.

# Failure class

Failure-Class: none

This PR's own commit is a `refactor:` with no triggering defect; the
declaration covers the stacked #10097 `fix:` commit in this diff range
(same call as #10097's own body — divergent read-side policy copies, no
registered class).

# Product invariants affected

none (verified with `scripts/pr-preflight --suggest`)

# Validation

- The mirror's unit test is replaced by a wire-contract test
(`app/test/unit/language_update_response_test.dart`): the response
carries `single_language_mode`, both values round-trip, and a response
missing the field **fails loudly instead of defaulting** — the property
that makes trusting the server safe.
- **Not run locally — no Flutter SDK on this machine** (same stated
constraint as #10097/#10100, both since approved/merged); the test is
hermetic and the app CI lane compiles and runs it.
- Call-site sweep: `setUserPrimaryLanguage` has exactly one consumer
(`updateUserPrimaryLanguage`);
`supportsLiveMultilingualMode`/`multiLanguageSupported` have zero
remaining references after deletion.
- `make preflight` (local lane, this PR body) → all selected checks
pass.

# Out of scope, named

- Offline-set language: with no client list, local
`single_language_mode` state updates only on a successful server
response — identical to today's behavior for the persisted preference
(the server was already the only writer of the durable value; the mirror
only fed optimistic local state).

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/10126?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="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align multi-language preference eligibility with live STT capability policy

4 participants