Skip to content

fix(desktop): keep the vocabulary list when it failed to load - #22356

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
apoorvdarshan:fix/macos-vocabulary-wipe
Oct 19, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
apoorvdarshan:fix/macos-vocabulary-wipe

Conversation

@apoorvdarshan

Copy link
Copy Markdown
Collaborator

What changed and why

Fixes #22355

Custom Vocabulary saves the whole list: every add or remove sends the full list to PATCH /v1/users/transcription-preferences, and the backend stores it as the account's vocabulary. Settings > Transcription on macOS shows the local copy in AssistantSettings until loadBackendSettings() has read the account's list. That load reads several settings in one try await, so when any of them fails the pane keeps the local copy, and it also shows that copy while the load is still running. The copy is empty on a new Mac or after a reinstall, and out of date after edits on the phone or the web. Adding a word then saved the copy plus the word, so the account's list became just that word (or the stale list plus it) and the other saved words were gone, with no error. Removing a word had the same problem.

  • The pane now tracks whether its list came from the account (vocabularyLoadedFromAccount). loadBackendSettings() clears it when it shows the local copy and sets it once the account's list arrives.
  • Adds and removes go through TranscriptionVocabularyWriter, next to TranscriptionLanguageWriter in the same file. It edits the pane's list only once that list came from the account. Otherwise it reads the account's list first (getTranscriptionPreferences). If that read fails, nothing is saved and the typed word stays in the field. Only one read runs at a time; an edit made during it is ignored.
  • Adding a word that is already on the list (case-insensitive) saves nothing, as before. Removing a word that is not on the account's list saves nothing either.

This is the same rule as #15244 on web and #22309 on mobile: a list that was not read from the account is never saved back as the whole list. Like mobile, macOS reads the list at edit time instead of disabling the field, because the Settings load is all-or-nothing: one unrelated failed request would otherwise block vocabulary edits until Settings is opened again.

Product invariants affected

none

How it was verified

  • Read the flow on current main (b343f3303a). loadBackendSettings() sets vocabularyList from AssistantSettings.shared.transcriptionVocabulary, then awaits the daily summary, language, recording, private cloud sync and transcription preference requests together. On any failure it only clears the loading flag. addVocabularyWord() appended to vocabularyList, and saveVocabulary() sent it through updateTranscriptionPreferences(vocabulary:) to APIClient.updateTranscriptionPreferences, which PATCHes the full list. On the backend, update_transcription_preferences_endpoint calls set_user_transcription_preferences, which writes transcription_preferences.vocabulary = vocabulary[:100]. Apart from the automation bridge's vocabulary_set_terms, only a successful Settings load fills the local copy.
  • Ran xcrun swiftc -parse on the changed Swift files and the new test: clean. The commit hook ran the pinned swift-format 602.0.0 on them, with no changes, and lint --strict with the same binary is clean.
  • Typechecked the new writer, the changed view methods (on a stub View with the same @State properties) and the new test class in a scratch file, with the target's flags (-swift-version 6 -strict-concurrency=complete -warnings-as-errors): clean. This was not a build of the app.
  • I did not build the app or run tests locally, to save local compute. CI with ci:full runs the new tests and the full desktop Swift suite.

Tests

desktop/macos/Desktop/Tests/TranscriptionVocabularyWriterTests.swift, in the style of TranscriptionLanguageWriteOrderTests. Its fake account replaces its whole list on every save, like the backend.

  • testAddSavesNothingWhenTheAccountListCannotBeRead: empty local copy and a failed read. The old behavior saved ["omi"].
  • testAddReadsTheAccountListFirstSoItsWordsAreKept: stale copy ["alpha"], account ["alpha", "beta"]. Saves ["alpha", "beta", "omi"]; the old behavior saved ["alpha", "omi"].
  • testRemoveSavesNothingWhenTheAccountListCannotBeRead and testRemoveReadsTheAccountListFirstSoTheOtherWordsAreKept: the old behavior saved [].
  • testLoadedListIsEditedWithoutReadingTheAccountAgain and testAddingAWordAlreadyOnTheListSavesNothing keep the loaded path and the duplicate check as they were.

I wrote the tests to fail without the fix: applying the edit to the pane's list as it stands, which is what the pane did, fails the four tests with a list that did not come from the account. They run in CI and have not been run locally.

Changelog: desktop/macos/changelog/unreleased/20261019-vocabulary-load-failure.json.

UI evidence

UI-Evidence: none -- no layout or visual change; what gets saved is covered by the hermetic tests above, and no simulator or device was available here

Failure class (fixes)

Failure-Class: none

🤖 Generated with Claude Code

Custom Vocabulary saves the whole list: the backend replaces the
account's vocabulary with the list it is sent. Settings > Transcription
shows the local copy in AssistantSettings until loadBackendSettings()
has read the account's list, and kept showing it when that load failed
or was still running. The copy is empty on a new Mac or after a
reinstall, and out of date after edits on the phone or the web, so
adding a word saved the copy plus that word and erased every other
word on the account. Removing a word did the same.

Edits now go through TranscriptionVocabularyWriter. It applies an edit
to the pane's list only once that list came from the account, and
otherwise reads the account's list first. If that read fails, nothing
is saved and the typed word stays in the field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@apoorvdarshan apoorvdarshan added the ci:full Maintainer-granted: run full CI on this fork PR label Oct 19, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: this is a correct, well-scoped fix for the vocabulary data-loss bug in #22355 — verified against the diff, no blocking issues. One non-blocking UX note below.

Correctness:

  • SettingsContentView+Transcription.swift — TranscriptionVocabularyWriter.apply is the right shape: when the pane's list did not come from the account it reads the account's list first (getTranscriptionPreferences) and applies the edit to that; on read failure it saves nothing and returns nil, so the typed word stays in the field to retry. The isReadingVocabulary guard closes the race where an edit during a read would start from the list that read replaces. saveVocabulary(_:) now takes explicit terms, removing the implicit "whatever is on screen" semantics that caused the wipe.
  • SettingsContentView+BillingHelpers.swift — flag placement verified in loadBackendSettings(): set false when seeding from the local copy, set true once the account read lands; in the revision-guard fallback branch the local copy reflects the newest mutation (a save already pushed it), so treating it as loaded is correct.
  • SettingsPage.swift — two documented @State vars, minimal and sufficient.
  • TranscriptionVocabularyWriterTests.swift — seven tests cover the exact regression (read failure saves nothing), stale-local-copy add/remove, no re-read when loaded, and the duplicate no-op. Good coverage of the reported failure mode.
  • changelog/unreleased/20261019-vocabulary-load-failure.json — user-facing fragment present and accurate.

Consistency: same rule as the merged web fix #15244 and the mobile fix #22309 — a list not read from the account is never saved back as the whole list. Good cross-platform alignment.

UX: when the account list can't be read, an add now silently no-ops (log only, word kept in the field). Acceptable parity with the other platforms; a future follow-up could surface a small inline error so users know why nothing happened.

Blast radius: desktop/macos Settings pane only; the change strictly narrows when the full-list PATCH is sent. If wrong, the failure mode is a skipped edit rather than data loss.

USER IMPACT: adding or removing a custom vocabulary word no longer silently erases your other saved words when Settings hasn't loaded the account list yet; if that list can't be loaded, the edit simply isn't saved and the word stays in the input field.

Nothing blocking from my side. Optional nice-to-have: an inline hint when a save is skipped due to a failed read. Human maintainer sign-off needed before merge — this edits the account-wide vocabulary persistence path (user-data surface).


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

Copy link
Copy Markdown
Member

Verdict: correct, well-scoped fix for a real data-loss path — nothing blocking; leaving formal approval to a human maintainer since this changes an account-data persistence flow.

Per-file findings:

  • SettingsContentView+Transcription.swift — the core change is sound: add/remove now go through editVocabulary -> TranscriptionVocabularyWriter.apply, which saves only a list that came from the account or was freshly read via getTranscriptionPreferences, and returns nil (nothing saved, word stays in the field) when that read fails. That failure mode is real: the backend's set_user_transcription_preferences replaces transcription_preferences.vocabulary wholesale. Two verified non-blockers: an edit attempted during the one-at-a-time account read is dropped (retry works, and the typed word is kept); after a successful edit the pane list is marked account-loaded, which is correct since it now IS the saved account list.
  • SettingsContentView+BillingHelpers.swift — right placement: vocabularyLoadedFromAccount is cleared when loadBackendSettings shows the local copy and set once the account's transcription preferences arrive. It is set even when shouldApplyTranscriptionVocabularyHydration rejects the hydration, but in that branch the local copy is newer by revision, so treating it as authoritative matches the existing guard's logic.
  • SettingsPage.swift — two new @State flags, nothing else touched.
  • TranscriptionVocabularyWriterTests.swift — six hermetic tests that fail on the old behavior; they cover add and remove on the unloaded path, the loaded fast path (zero account reads), and the case-insensitive duplicate check. Desktop Swift Build & Tests ran them green at head.
  • changelog/unreleased/20261019-vocabulary-load-failure.json — present and accurate.

UX: the word now stays in the field when the save can't happen — visible, and the right trade. Blast radius: only the macOS Settings > Transcription > Custom Vocabulary pane; worst case if wrong is a skipped edit, not data loss. Data handling: this strictly narrows what gets written to the account's vocabulary.

Consistency: same rule as #15244 (web) and #22309 (mobile); #22403 covers the save-failure path on a different code path, no overlap with this diff.

USER IMPACT: adding or removing a custom vocabulary word on macOS no longer silently erases your other saved words when Settings hasn't loaded them yet; if the list can't be read, the word stays in the input so you can retry.

Still want as a reviewer: nothing blocking — optional polish would be a pane-level test for the isReadingVocabulary drop-during-read path, since the current tests exercise the writer in isolation. Ready for maintainer merge review.


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

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

Automated review: scoped bug fix, CI green, root-caused, test-covered. Approving per policy.

@kodjima33
kodjima33 merged commit bcd1a29 into BasedHardware:main Oct 19, 2026
42 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Maintainer-granted: run full CI on this fork PR macOS positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS Custom Vocabulary: adding a word when the saved list failed to load replaces the whole list with that word

3 participants