Skip to content

refactor(app): trust the server's single_language_mode, drop the client mirror (after #10097) - #10126

Merged
undivisible merged 3 commits into
BasedHardware:mainfrom
aryanorastar:refactor/10022-drop-client-language-mirror
Jul 24, 2026
Merged

undivisible merged 3 commits into
BasedHardware:mainfrom
aryanorastar:refactor/10022-drop-client-language-mirror

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

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 fix(users): gate multi-language mode by the live STT capability policy #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 fix(users): gate multi-language mode by the live STT capability policy #10097/fix(app): stop reporting a failed template install as success #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).

Review in cubic

…nt mirror

Follow-up to BasedHardware#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 BasedHardware#10097 (stacked on its branch).

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

Clean refactor — trusting the server's single_language_mode response and deleting the client-side 19-locale mirror is the right direction. Single source of truth eliminates the drift risk on every future STT policy change, and the wire-contract test (fails loudly instead of defaulting when the field is absent) pins exactly the property that makes that trust safe.

Quick notes for the maintainer:

Leaving for human maintainer review given the stack dependency and the product-level multilingual-eligibility policy. No changes requested on this PR's own commit.


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

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level Noted. We'll wait for #10097 to merge first.

- primary_language_widget.dart: capture the bool result of
  updateUserPrimaryLanguage(); show a failure snackbar and block
  navigation on false instead of silently ignoring errors
- test_ws_b_short_term_lifecycle.py: replace frozen
  datetime(2026, 6, 20, ...) with datetime.now(timezone.utc)
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Thanks. Confirmed — this is stacked on #10097; merge that first and this collapses to the single app-side commit. updateUserPrimaryLanguage is the only consumer of the new bool? return and handles the null (failure) path, and the wire-contract test pins that the response carries single_language_mode.

…lient-language-mirror

# Conflicts:
#	app/lib/providers/home_provider.dart

@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.

Refactor(app): trust server single_language_mode, drop client mirror (after #10097) — approve only per policy (mobile refactor)

@Git-on-my-level

Copy link
Copy Markdown
Member

Update on the stack: #10097 merged (2026-07-21), so the "stacked on an unmerged base" concern is resolved — this PR now stands on its own two commits against main.

The refactor still looks right:

  • Trusting the server's single_language_mode from the PATCH /v1/users/language response and deleting the 66-entry client mirror is the correct single-source-of-truth direction — future STT policy changes no longer need an app release.
  • The bool? (null-on-any-failure) return on setUserPrimaryLanguage is handled correctly by its sole consumer (updateUserPrimaryLanguage), and the new onboarding failure path (snackbar + block navigation) is a genuine UX improvement.
  • The replacement wire-contract test is the right shape — especially the "fails loudly instead of defaulting when the field is absent" assertion, which pins exactly the property that makes trusting the server safe.

One minor note (not blocking): the second commit bundles a one-line fix to backend/tests/unit/test_ws_b_short_term_lifecycle.py (frozen datetime(2026, 6, 20) → datetime.now(timezone.utc)), which is unrelated to the language refactor. It's tiny and clearly beneficial, so not worth splitting — just flagging it for review awareness.

Leaving formal approval to a human maintainer per needs-maintainer-review, since this shifts ownership of the multi/single-language-mode decision entirely to the server.


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

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — kodjima33 approved, and #10097 (the base) is now merged, so this stands on its own two commits against main. Ready for a maintainer to merge.

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — this PR is approved, rebased onto latest main today, and all checks are green (mergeable, clean). Ready for a maintainer to merge (regular merge, no squash). Thanks!

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
undivisible merged commit 60413dc into BasedHardware:main Jul 24, 2026
28 checks passed
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.

4 participants