Skip to content

fix(desktop): put the vocabulary list back when saving it fails - #22403

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

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

Conversation

@apoorvdarshan

Copy link
Copy Markdown
Collaborator

What changed and why

Fixes #22402

In Settings > Transcription > Custom Vocabulary on macOS, adding or removing a word changes the list on screen and the local copy in AssistantSettings right away. updateTranscriptionPreferences(vocabulary:) then sends the whole list to PATCH /v1/users/transcription-preferences in a detached Task. When that request failed (offline, a server error, an expired session), the catch only logged it. The pane and the local copy kept a list the account never stored, so the word looked saved. Live transcription never used it, because a listen session loads the vocabulary from the account. The next Settings load showed the account's list again and the word was gone, with no message. A failed removal had the same problem.

  • The pane now keeps the list the account last confirmed (savedVocabularyList). loadBackendSettings() sets it when it shows the account's list, and each successful save sets it from the list the account returns.
  • When a vocabulary save fails, that list goes back in the pane and the local copy, and "Couldn't save your vocabulary change. Try again." shows under the field, styled like the existing recap-depth save error. If Settings has not read the account's list yet, nothing is known to put back, so only the error shows.
  • A failure is ignored when a newer edit was made while it ran (AssistantSettings.transcriptionVocabularyRevision moved on). That edit's save sends the whole list again, this change included, so its result decides what the pane shows.
  • The decision is in TranscriptionVocabularySaver, in the shape of TranscriptionLanguageWriter, so it can be tested without the view. Language-mode saves (updateTranscriptionPreferences(singleLanguageMode:)) send the same request as before.

My open #22356 fixes the other half: an add or remove made when the list failed to load wiped the account's list. The two PRs change different lines, a trial merge of both branches is clean, and with both, #22356's saveVocabulary(_:) still goes through this save path. #22354 is the same save-failure fix on mobile. With my open #22401, the backend refuses a list over 100 terms with a 400 instead of trimming it; on macOS that refusal now also puts the list back and shows the error.

Product invariants affected

none

How it was verified

  • Traced the flow on main (e963f8af08). addVocabularyWord() and removeVocabularyWord(_:) edit vocabularyList; saveVocabulary() writes it to AssistantSettings.shared.transcriptionVocabulary and calls updateTranscriptionPreferences(vocabulary:), whose catch only called logError. APIClient.updateTranscriptionPreferences throws when the PATCH or its follow-up GET fails. On the backend, set_user_transcription_preferences replaces transcription_preferences.vocabulary (first 100 terms), and listen_session_bootstrap reads the account's transcription preferences for each listen session. loadBackendSettings() writes the account's list over the pane and the local copy.
  • Pinned swift-format 602.0.0: format and lint --strict on the changed Swift files are clean (the commit hook also ran it, with no changes). xcrun swiftc -parse on them is clean.
  • Typechecked the new type, the changed updateTranscriptionPreferences (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, Swift 6.4): clean. This was not a build of the app.
  • check_desktop_ux_contract.py, check_brand_ui.py and check_desktop_test_quality.py pass on the change.
  • 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/TranscriptionVocabularySaverTests.swift, in the style of TranscriptionLanguageWriteOrderTests. Its fake account replaces its whole list on every save, like the backend, and refuses saves while offline.

  • testFailedSavePutsBackTheListTheAccountHolds: Settings read ["alpha"], the pane shows ["alpha", "omi"], and the save fails. ["alpha"] must go back.
  • testFailedRemovalPutsBackTheRemovedWord: the same for a removal.
  • testFailureIsReportedEvenBeforeSettingsReadTheAccount: with no confirmed list, nothing goes back but the failure is still reported.
  • testFailurePutsBackAListConfirmedWhileTheSaveRan: a save confirmed while this one was in flight is what goes back.
  • testFailureIsLeftToANewerEdit and testSavedListIsTheListTheAccountHolds cover the superseded and success paths.

The tests use the new type, so they do not compile on main. The old code treated a failed save like a stored one (the edited list stayed and no error showed); expressed as these outcomes, that fails the first four tests. They run in CI and have not been run locally.

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

UI evidence

UI-Evidence: none -- one caption line under the vocabulary field, styled like the recap-depth save error; no simulator or device here, and the save outcomes are covered by the hermetic tests above

Failure class (fixes)

Failure-Class: FC-refused-mutation-bool-confirmed-as-success

Same contract as #22354 on mobile: a UI that shows a save must act on what the save reported. Here the helper throws instead of returning false.

🤖 Generated with Claude Code

Settings > Transcription > Custom Vocabulary shows an add or remove,
and writes it to the local copy in AssistantSettings, before
PATCH /v1/users/transcription-preferences answers. When that PATCH
failed, updateTranscriptionPreferences only logged the error. The pane
and the local copy kept a list the account never stored: the word
looked saved, live transcription (which reads the account's list)
never used it, and the next Settings load dropped it without a message.

A failed vocabulary save now puts the list the account last confirmed
(read by the Settings load, or returned by the last successful save)
back in the pane and the local copy, and shows an error under the
field. A failure that a newer edit has superseded changes nothing,
because that edit's save sends the whole list again.

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

The production change here is correct and nicely scoped; leaving formal approval to a human maintainer because it changes how user vocabulary data is restored and shown.

Verified per file:

  • SettingsContentView+SettingsUpdates.swift — the new TranscriptionVocabularySaver.save is a clean, view-independent extraction (saved/failed/superseded). The revision guard is sound: saveVocabulary() (SettingsContentView+Transcription.swift:414) writes AssistantSettings.shared.transcriptionVocabulary before dispatching, and that setter increments transcriptionVocabularyRevision (AssistantSettings.swift:346), so a stale failure can never clobber a newer edit. The nil-vocabulary early-return branch preserves the prior wire shape (vocabulary key omitted, not an empty array) — important given fix(desktop): keep the vocabulary list when it failed to load #22356.

  • SettingsContentView+BillingHelpers.swift:905 — savedVocabularyList is seeded only when Settings actually read the account's list; correct nil-until-read semantics.

  • SettingsPage.swift — the two new @State vars are documented; fine.

  • SettingsContentView+Transcription.swift — inline error caption in Ink.errorRed with an accessibility identifier; good.

  • TranscriptionVocabularySaverTests.swift — six tests cover failed add, failed removal, nil-confirmed, mid-flight confirmation, superseded, and success. Nice that the saver's shape makes this testable without the view.

  • changelog fragment present and accurate.

  • UX: users will see failed vocabulary edits snap back with an inline error instead of a silent fake-success. Blast radius: macOS Settings transcription pane only.

  • Two minor observations, non-blocking: a stale vocabularySaveError is only cleared when the next vocabulary save is dispatched (a language-mode-only save in between leaves the old message up), and on success the pane is not refreshed from the read-back stored list, so backend-side normalization would not re-render.

USER IMPACT: when saving a custom vocabulary change fails (offline, server error), Settings now puts the previous list back and shows "Couldn't save your vocabulary change. Try again." instead of silently keeping a change the account never stored.

Still wanted from a reviewer: nothing blocking — the two observations above are optional polish; the behavior itself is well covered by the new tests.

Human maintainer sign-off wanted for the restore-on-failure UX direction (what the pane shows after a failed save is a small product call); no security concerns found in the diff itself.


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 positive-signal Automation verified a genuine fix/quality contribution macOS labels Oct 19, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: the production change is correct and nicely scoped; nothing blocking. Formal approval stays with a human maintainer for this surface.

Findings, file by file:

  • SettingsContentView+SettingsUpdates.swift — the core. TranscriptionVocabularySaver.save() maps the PATCH outcome to .saved(stored:)/.failed(restore:)/.superseded. On success, savedVocabularyList is set from the list the account returns, so the pane's baseline is what the server holds, not what it optimistically displayed. On failure, the guard on transcriptionVocabularyRevision means an older save never clobbers a newer edit's list (that edit's save re-sends the whole list). The nil-vocabulary branch keeps the old single-request language-mode path — behavior there is unchanged.
  • SettingsContentView+BillingHelpers.swift (+1) — sets savedVocabularyList when loadBackendSettings() shows the account's list, giving the restore a correct baseline; without it the failure path would only show the error.
  • SettingsPage.swift (+4) — savedVocabularyList/vocabularySaveError @State with accurate doc comments; nil-means-unread semantics handled in the saver.
  • SettingsContentView+Transcription.swift (+7) — error caption styled like the existing captions, with an accessibilityIdentifier ("vocabulary-save-error") for UI testing.
  • TranscriptionVocabularySaverTests.swift — six cases: failed add, failed removal, failure before the account list is read, a confirmation landing mid-flight, superseded-by-newer-edit, and success. Good coverage of the race semantics.
  • changelog/unreleased/20261019-vocabulary-save-failure.json — accurate user-facing fragment.

One non-blocking nit: on .saved you don't re-check isLatestEdit, so a slow older save completing after a newer one sets savedVocabularyList to the older list. Since the account then holds whichever PATCH landed last, the value stays consistent under last-write-wins; just noting the ordering assumption.

UX: this is the point of the PR — a failed save now visibly reverts and explains itself instead of silently pretending. Security: same authenticated PATCH, no new inputs or surfaces. Blast radius: macOS Settings ▸ Transcription pane only. Related: #22356 covers the complementary load-failure case; the author reports a trial merge is clean, worth a re-check at merge time.

Still wanted as a reviewer: nothing blocking; a UI-level assertion on the error caption would be nice-to-have.

USER IMPACT: When saving a custom vocabulary change fails (offline, server error, expired session), macOS Settings now puts the list back to what the account actually holds and shows "Couldn't save your vocabulary change. Try again." instead of silently showing the change as saved and dropping it later.


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.

Desktop bug fix (owner-override): puts the vocabulary list back on save failure instead of silently losing it. CLEAN, CI green, tests added.

@kodjima33
kodjima33 merged commit 9e9a114 into BasedHardware:main Oct 19, 2026
42 of 43 checks passed
kodjima33 added a commit that referenced this pull request Oct 20, 2026
…led save (#22780) (#22798)

Daily Summary, Store Recordings, and Private Cloud Sync bind their switch
directly to the value shown on screen. A failed save (offline, server error,
expired session) was only logged: the switch stayed on the side the user
picked while the account kept its old value, and the next Settings load
quietly flipped it back with no message — for Store Recordings/Private Cloud
Sync this means a user believes they changed a privacy-relevant setting when
the account never stored the change.

#22403 fixed the same symptom for Custom Vocabulary by tracking the value
the account last confirmed and restoring it on failure. This extracts that
pattern into a small, directly testable BooleanSettingSaver and applies it
to the three toggles.

Tested: added BooleanSettingSaverTests (new file) exercising save/restore
through the production save function with a fake account that can refuse
a write; xcrun swift build succeeds; swift-format lint clean.
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: a change that fails to save still shows as saved, then disappears on the next load

3 participants