Skip to content

fix(settings): apply audio language from the profile so it affects playback - #104

Closed
Quick104 wants to merge 4 commits into
mainfrom
fix/settings-audio-language-scope
Closed

Quick104 wants to merge 4 commits into
mainfrom
fix/settings-audio-language-scope

Conversation

@Quick104

@Quick104 Quick104 commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

The Audio Language picker in Settings did nothing. Verified P1 from Silo-Server/silo-server#376.

It wrote playback.audio_language as a device setting, but nothing anywhere read that value back — repository-wide it was only loaded, cached, displayed, and written inside the settings layer. No detail, session-start, route-planning, or player-selection path touched it. The server picks the initial audio track from the profile's language field, which WireFormatModels.asUserProfile was explicitly dropping and UpdateProfileBody had no way to write.

What changed

Carry the profile language through the wire layer

  • WireFormatModels.swift — Profile.language now flows into UserProfile.language instead of being discarded
  • ProfileModels.swift — UpdateProfileBody gains language so the client can write it

Point the setting at the profile

  • SettingsViewModel.swift, TVSettingsViewModel.swift — the device-backed preferredAudioLanguage is replaced by a profile editor field plus saveAudioLanguage(), which PUTs to /api/v1/profiles/{id}, refreshes the local activeProfile snapshot, and flushes the item ResponseCache (and tvOS ItemDetailCache) so an already-visited detail screen stops showing the stale track

Remove the dead write path

  • PlayerSettings.swift — the device-scoped audioLanguage property, setter, registered default, init read, and snapshot entries are gone. PlayerDeviceSettingKey.audioLanguage is kept so "Reset Playback Overrides" still clears rows written by older builds

Fix the picker contents

  • PlaybackSettingsView.swift, TVPlaybackSettingsView.swift, TVSettingsComponents.swift — both pickers build from the shared PlaybackLanguageOption.all list the subtitle and metadata pickers already use, deleting two duplicated 9-entry lists. Required, not cosmetic: a language set from the web client (zh/ru/ar/hi) rendered as a blank row before. Footers now say the setting is profile-wide.

No server change needed — PUT /profiles/{id} already accepts language for self-service, stores it, and returns it. silo-android already reads activeProfile?.language.

Review pass — four defects in the new picker

All four end with the server and the UI disagreeing and nothing telling the user.

No write coalescing. saveAudioLanguage had none, unlike saveMetadataLanguage twenty lines above it, which has an explicit queue for exactly this. The picker fires on every change, so two quick selections raced across the await: the second task read an activeProfile.language the first had not written back yet, concluded nothing had changed, and returned. The server kept the first value, the picker showed the second, and prefSaveState stayed on .saving forever. Both platforms now drain a pending value the way the metadata save does, and record the write before the early return so a follow-up save compares against the right baseline.

Failures were invisible. Neither Playback screen rendered prefSaveState — the only readers were the Subtitles screens — so a failed save showed nothing and its message surfaced on a different screen. A PIN-gated primary profile gets a 403 here and saw nothing at all. The save-state view is extracted so both platforms' Playback panes report their own result, replacing two near-identical private copies.

A nil activeProfile swallowed edits before prefSaveState was ever set, so an offline settings visit silently discarded every selection. It now reports.

The language list was narrower than the field it writes. Listed below as an accepted limit, with the note that an unmatched selection "does not overwrite the stored value" — that turned out not to hold. tvOS rendered a literal —, iOS rendered blank, and the first tap did replace the stored language. Rather than duplicating the web's ~37-entry table, the pickers now include whatever the field currently holds — including the original sentinel the server honours at profile scope — and name unknown codes via Locale instead of shouting the raw code back.

isPrimary, also listed below as deliberately left alone, is fixed. Six sites (three iOS, three tvOS — two of them added by this PR) reconstructed UserProfile by hand and dropped it, because Swift fills an omitted defaulted parameter silently, so the household parent demoted themselves on every preference save. Replaced with a with(...) copy helper: omitting a parameter now means "keep it", so the next field added cannot be dropped.

Both reset footers claimed to reset "this device and profile"; the reset clears device rows and does not touch the profile's audio language. Reworded to match what it does.

Second review pass — two defects introduced by the first one

Both were found on this branch by a follow-up review and are fixed in a5d1c1b. Each was present on both platforms.

The coalescing fix could skip the completion path for a write that landed. Guarding .saved on pendingAudioLanguageValue == nil looked like "don't report a stale result", but it misfires when the queued value equals the one being written — A → B → B before the first PUT returns. At completion B is still queued, so the success path returns before .saved and before flushing the caches; the drained pass then matches the freshly-recorded activeProfile.language and returns at its own equality guard. Nothing ever reports: the footer reads "Saving…" indefinitely, and cached detail screens keep the old track — the exact symptom the coalescing was added to eliminate. The write is now recorded first and reported unconditionally, since a genuinely newer value overwrites the message when it lands. saveMetadataLanguage had the same shape through its editor-value comparison and got the same treatment.

One untagged save state served three different writes. prefSaveState was written by the subtitle, metadata, and audio paths and never cleared. That was survivable while only the Subtitles screen read it; making Playback render it too turned it into cross-screen misattribution — a failed subtitle save shows "Couldn't save: …" under Audio Language, and an audio result sits pinned under the Subtitles footer on next visit. Worse on tvOS, where the rail switches panes on focus alone with no navigation to stale it out. Split into audioSaveState / subtitleSaveState / metadataSaveState, each rendered under the row that produces it. Metadata Language gains its own footer line as a result; it had been borrowing the subtitle trio's.

Two other bot findings were checked and not acted on: extracting the duplicated save machinery is a maintainability nitpick whose duplication predates this PR, and refreshing live tvOS detail models rather than only clearing ItemDetailCache is a real but pre-existing display-consistency limit that saveMetadataLanguage already shares — not a regression from this branch, and out of scope here.

Verification

Built and tested on mac-builder (macOS 26.5.1, Xcode 26.4) from an isolated
checkout at this branch's exact source state. Re-run after a5d1c1b.

$ xcodebuild -scheme Silo   -destination 'generic/platform=iOS Simulator'   build   ** BUILD SUCCEEDED **
$ xcodebuild -scheme SiloTV -destination 'generic/platform=tvOS Simulator'  build   ** BUILD SUCCEEDED **
$ xcodebuild -scheme SiloMac -destination 'platform=macOS'                  build   ** BUILD SUCCEEDED **

$ xcodebuild -scheme Silo -destination 'platform=iOS Simulator,id=…' test
     Executed 761 tests, with 0 failures (0 unexpected) in 30.035 seconds
** TEST SUCCEEDED **

Known limits and follow-ups

  • Not device-verified. Compiles everywhere; the picker → profile → server → track-selection round trip was not exercised against a live server.
  • Stranded device rows — this one matters for the contract. Existing playback.audio_language rows in user_device_settings from earlier builds are now orphaned. Harmless today, but the settings contract resolves that key profile_device → profile, so a stale row would shadow the new profile value — and it would be a value the user set months ago and demonstrably saw no effect from. Needs an explicit server-side migration disposition; deliberately not papered over with a client-side DELETE.
  • Language list is still narrower than the web's. Fixed in the review commit. The claim that an unmatched selection "does not overwrite the stored value" was wrong — tvOS showed —, iOS showed blank, and the first tap replaced it. Pickers now carry the current value plus the twelve.
  • No write coalescing. Fixed in the review commit — the divergence was worse than "land out of order": the second save skipped itself and prefSaveState stranded on .saving. The coalescing itself then needed a second fix (a5d1c1b): its completion guard could strand the same footer when the queued value equalled the in-flight one.
  • Save results were reported through one shared, untagged field. Fixed in a5d1c1b — split per write, so the Playback screen rendering it no longer misattributes subtitle and metadata results.
  • Pre-existing bug, deliberately left alone: isPrimary dropped on reconstruction. Fixed in the review commit at all six sites (there were six, not four) via a with(...) copy helper. Still latent in effect — nothing reads activeProfile.isPrimary today — but the trap is gone.
  • UI change worth a screenshot: picker goes 9 → 13 rows, and the empty label changes from "Default" to "No Preference" — matching the web, and honest now that the value is profile-wide.
  • Live tvOS detail models aren't refreshed, only their cache is cleared. ItemDetailCache.clearAll() drops cache references but does not refresh a resident TVItemDetailView's @State model, so a detail screen visited earlier in the session can keep showing the old track until it reloads. Pre-existing — saveMetadataLanguage has had exactly this treatment — and display-only, since playback refetches /watch. Fixing it properly needs a refresh broadcast covering both writes, which is a separate change.

Part of Silo-Server/silo-server#376. Server-side contract: Silo-Server/silo-server#479. Supersedes #103, closed when its branch was renamed.

AI Disclosure

  • Tool(s): Claude Code
  • Model(s): claude-opus-5[1m]
  • Involvement: AI-assisted, under maintainer direction
  • Adversarial review: Reviewed by a parallel multi-agent pass plus an independent adversarial pass using Codex. Both independently found the missing save serialization. The parallel pass additionally found the invisible failure state, the nil-profile swallow, that the language-list limitation was worse than this PR's own body claimed, and that isPrimary was dropped at six sites rather than four. Reviewers also confirmed by inspection that UpdateProfileBody's optional fields cannot wipe siblings — encodeIfPresent omits them and the server patches per-field — so that concern was checked and dropped rather than "fixed". A second review pass over the review commit itself found the two defects fixed in a5d1c1b; both had been introduced by the first pass's fixes, which is the argument for reviewing review commits.

Builds and tests were run on mac-builder and the real output is quoted above, rather than reported from the implementing agent, which has no Swift toolchain. One self-inflicted bug was caught before building: both new view structs used State as a generic parameter name, shadowing SwiftUI's @State; renamed to SaveState.

Summary by CodeRabbit

  • New Features

    • Added profile-wide audio language preferences across iOS and tvOS.
    • Audio language changes now save through the profile and display saving, success, or error status.
    • Language pickers now retain and display custom or previously selected language codes.
    • Updated settings explanations clarify that audio language is profile-wide and unaffected by device resets.
  • Bug Fixes

    • Improved localized labels for unknown language codes.
    • Ensured subtitle and metadata language selections remain available in picker lists.

The Audio Language picker wrote `playback.audio_language` as a
device-scoped setting that nothing read — not this repo, not the server.
The server resolves the initial audio track from the profile's
`language` field (silo-server `internal/catalog/detail.go` emits it as
`effective_audio_track_index`, which `PlaybackSessionBridge` forwards at
session start), and `WireFormatModels.asUserProfile` was deliberately
dropping that field on the way into `UserProfile`.

Carry `language` through into `UserProfile`, let `UpdateProfileBody`
write it, and point the iOS/macOS and tvOS pickers at the profile value
through a new `saveAudioLanguage()` on both settings view models. Both
pickers now build from the shared `PlaybackLanguageOption.all` list the
subtitle and metadata pickers already use, so a language set from the web
client (zh/ru/ar/hi) renders instead of showing a blank row, and the two
hardcoded nine-entry copies are gone.

The choice is profile-wide rather than per-device, so the Streaming
footer now says so and the dead device-scoped `PlayerSettings`
audio-language state is removed. `PlayerDeviceSettingKey.audioLanguage`
stays so "Reset Playback Overrides" still deletes rows written by older
builds.

Refs Silo-Server/silo-server#376

AI-use disclosure: implemented with Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d6e852a-587d-4549-811c-b6e6e57c68e2

📥 Commits

Reviewing files that changed from the base of the PR and between a5d1c1b and af802be.

📒 Files selected for processing (2)
  • iosApp/iosApp/Screens/Settings/SettingsViewModel.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift
📝 Walkthrough

Walkthrough

Audio language is moved from device-scoped playback settings to profile-backed storage. iOS and tvOS gain serialized profile saves, dynamic options for unknown codes, updated profile models and wire payloads, cache invalidation, and shared save-state UI.

Changes

Profile-backed audio language

Layer / File(s) Summary
Language contracts and dynamic options
iosApp/iosApp/Screens/Profiles/ProfileModels.swift, iosApp/iosApp/Networking/WireFormatModels.swift, iosApp/iosApp/Networking/PlaybackPrefsModels.swift
Profiles and update requests carry language; language pickers localize unknown codes and retain currently selected values.
Device setting removal and profile mapping
iosApp/iosApp/Screens/Player/PlayerSettings.swift, iosApp/iosApp/Screens/Settings/SettingsViewModel.swift, iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift
Legacy device audio-language persistence is removed, and profile language saves share outbound sentinel mapping and targeted profile updates.
Serialized profile audio saves
iosApp/iosApp/Screens/Settings/SettingsViewModel.swift, iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift
Audio-language edits use queued async saves, update the active profile, expose save states, and invalidate relevant caches.
Settings UI integration
iosApp/iosApp/Screens/Settings/*, iosApp/iosApp/tvOS/Screens/Settings/*
iOS and tvOS pickers use editor values and dynamic options, while shared save-state components replace local footer implementations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SettingsPicker
  participant SettingsViewModel
  participant ProfileEndpoint
  participant Cache
  SettingsPicker->>SettingsViewModel: select audio language
  SettingsViewModel->>ProfileEndpoint: update profile language
  ProfileEndpoint-->>SettingsViewModel: return updated profile
  SettingsViewModel->>Cache: invalidate cached metadata
  SettingsViewModel-->>SettingsPicker: render save state and selected value
Loading

Suggested reviewers: zzebrahz

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: moving audio language to the profile so it affects playback.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/settings-audio-language-scope

Comment @coderabbitai help to get the list of available commands.

Four defects in the new Audio Language picker, all of which end with the server
and the UI disagreeing and nothing telling the user.

saveAudioLanguage had no in-flight coalescing, unlike saveMetadataLanguage
twenty lines above it, which has an explicit queue for exactly this. The picker
fires on every change, so two quick selections raced across the await: the
second task read an activeProfile.language that the first had not written back
yet, concluded nothing had changed, and returned. The server kept the first
value, the picker showed the second, and prefSaveState stayed on .saving
forever. Both platforms now drain a pending value the way the metadata save
does, and record the write before the early return so a follow-up save compares
against the right baseline.

Neither Playback screen rendered prefSaveState — the only readers were the
Subtitles screens — so a failed save was invisible and its message appeared on a
different screen. A PIN-gated primary profile gets a 403 here and saw nothing at
all. The save-state view is extracted so both platforms' Playback panes report
their own result, replacing two near-identical private copies.

A nil activeProfile dropped the edit before prefSaveState was ever set, so an
offline settings visit silently swallowed every selection. It now reports.

The pickers offered twelve languages while the web client writes any of ~37 to
the same profile field, and the server stores whatever it is given. A value from
outside the twelve rendered as an empty selection on iOS and a literal "—" on
tvOS, and the first tap replaced it. Pickers now include whatever the field
currently holds — including the `original` sentinel the server honours at
profile scope — and name unknown codes via Locale instead of shouting the code
back.

Separately, every hand-written UserProfile reconstruction dropped isPrimary,
because Swift fills an omitted defaulted parameter silently. Latent today since
nothing reads activeProfile.isPrimary, but it means the household parent
demoted themselves on every preference save. Replaced with a `with(...)` copy
helper at all six sites, so the next field added cannot be dropped.

The reset footers claimed to reset "this device and profile"; the reset clears
device rows and does not touch the profile's audio language. Reworded to match.

Verified on macOS 26.5.1 / Xcode 26.4: Silo (iOS Simulator), SiloTV (tvOS
Simulator) and SiloMac all build, and the 761-test SiloTests suite passes with
no failures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Quick104
Quick104 marked this pull request as ready for review July 26, 2026 15:20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
iosApp/iosApp/Screens/Settings/SettingsViewModel.swift (1)

289-390: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Consider extracting the duplicated profile-language save machinery. saveAudioLanguage, saveAudioLanguageValue, projectActiveProfileIntoEditor, and outboundProfileLanguage are now character-for-character identical in both view models, along with the isSaving* / pending* state pairs. The subtle parts (updating activeProfile before the pending check, reporting failures even when a newer value is queued) now have to stay in sync by hand across platforms.

  • iosApp/iosApp/Screens/Settings/SettingsViewModel.swift#L289-L390: move the serialize-and-save logic into a shared helper (e.g. a ProfileLanguageSaver actor/struct or a protocol extension over an activeProfile + prefSaveState requirement) and delegate to it.
  • iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift#L332-L390: delegate to the same helper, keeping only the tvOS-specific ItemDetailCache.shared.clearAll() at the call site.

Reasonable to defer — the duplication predates this PR for the subtitle/metadata paths and the new code follows it consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/Screens/Settings/SettingsViewModel.swift` around lines 289 -
390, Extract the duplicated audio-language save machinery into a shared helper
and have both view models delegate to it. In
iosApp/iosApp/Screens/Settings/SettingsViewModel.swift lines 289-390, move the
serialization, pending-value handling, profile update, state reporting, and
cache invalidation logic out of saveAudioLanguage, saveAudioLanguageValue,
projectActiveProfileIntoEditor, and outboundProfileLanguage; in
iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift lines 332-390,
delegate to the same helper while retaining only the tvOS-specific
ItemDetailCache.shared.clearAll() behavior at the call site. Keep the
isSaving*/pending* state behavior and subtle activeProfile update and
queued-failure handling identical across platforms.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@iosApp/iosApp/Screens/Settings/SettingsViewModel.swift`:
- Around line 289-390: Extract the duplicated audio-language save machinery into
a shared helper and have both view models delegate to it. In
iosApp/iosApp/Screens/Settings/SettingsViewModel.swift lines 289-390, move the
serialization, pending-value handling, profile update, state reporting, and
cache invalidation logic out of saveAudioLanguage, saveAudioLanguageValue,
projectActiveProfileIntoEditor, and outboundProfileLanguage; in
iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift lines 332-390,
delegate to the same helper while retaining only the tvOS-specific
ItemDetailCache.shared.clearAll() behavior at the call site. Keep the
isSaving*/pending* state behavior and subtle activeProfile update and
queued-failure handling identical across platforms.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1718538f-648c-4471-9dbe-4d37fea6e6d1

📥 Commits

Reviewing files that changed from the base of the PR and between 659a267 and 9113f97.

📒 Files selected for processing (12)
  • iosApp/iosApp/Networking/PlaybackPrefsModels.swift
  • iosApp/iosApp/Networking/WireFormatModels.swift
  • iosApp/iosApp/Screens/Player/PlayerSettings.swift
  • iosApp/iosApp/Screens/Profiles/ProfileModels.swift
  • iosApp/iosApp/Screens/Settings/PlaybackSettingsView.swift
  • iosApp/iosApp/Screens/Settings/PrefSaveStateLabel.swift
  • iosApp/iosApp/Screens/Settings/SettingsViewModel.swift
  • iosApp/iosApp/Screens/Settings/SubtitleSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVPlaybackSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSettingsComponents.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9113f97959

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +341 to +343
guard activeProfile?.id == profileId,
pendingAudioLanguageValue == nil else {
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Finalize a coalesced save that matches the completed write

When the profile starts at A and the user selects B, another value, then B again before the first PUT completes, pendingAudioLanguageValue is B when that PUT succeeds. This guard returns without marking the save complete or invalidating metadata; the queue then drains B, but the equality guard at the start of saveAudioLanguageValue skips it because activeProfile is already B. The UI therefore remains on “Saving…” and previously cached detail metadata remains stale. The identical guard in TVSettingsViewModel.saveAudioLanguageValue has the same behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed in a5d1c1b, on both platforms.

The failure mode is narrower than "a newer value is queued" but real: it needs the queued value to equal the one being written (A → B → B before the first PUT returns). At completion pendingAudioLanguageValue is B, so this guard returns before .saved and before the cache flush — and the drained pass then matches the freshly-recorded activeProfile.language and returns at its own equality guard. Nothing ever reports, so the footer sits on "Saving…" indefinitely and cached detail screens keep the old track.

Fixed by recording the write first and then reporting unconditionally, rather than suppressing the report. A queued value that genuinely differs overwrites the message when it lands, so nothing stale survives. saveMetadataLanguage had the same shape via its outboundProfileLanguage(editor…) == newValue comparison and got the same treatment.

Comment on lines +105 to +106
if let state = viewModel.prefSaveState {
PrefSaveStateLabel(state: state)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep audio save feedback separate from other profile saves

This footer renders the view model’s shared prefSaveState, which is also mutated by subtitle and metadata saves and is never cleared or tagged with the operation that produced it. Because the same view model persists across settings navigation, saving or failing a subtitle preference and then opening Playback displays that old result under Audio Language as if the audio setting produced it; audio results likewise remain visible on the Subtitles screen. Use operation-specific state or clear/filter the shared state when changing panes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed in a5d1c1b, on both platforms.

You're right that the field is untagged and never cleared, and that the view model outlives navigation. Splitting it rather than tagging: audioSaveState / subtitleSaveState / metadataSaveState, each rendered under the row that writes it. Same enum, so PrefSaveStateLabel and TVPrefSaveFooter are unchanged.

One knock-on worth noting: Metadata Language had been borrowing the subtitle trio's footer for its result. With the split it gets its own line on both platforms rather than losing its surface.

// always refetches `/watch`, so this is display consistency
// only — it is not what makes the setting take effect.
ResponseCache.shared.invalidateAllItemMetadata()
ItemDetailCache.shared.clearAll()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refresh live tvOS detail models instead of only clearing the cache

When Settings is pushed from an item-detail route on tvOS, the underlying TVItemDetailView retains its @State ItemDetailViewModel. clearAll() only removes references from ItemDetailCache; it neither refreshes that live model nor clears its existing detail, and the detail view’s .task(id: contentId) does not restart merely because the settings route is popped. Returning from Settings therefore continues to display the old server-resolved audio track even though this save succeeded. Refresh resident models before eviction or notify the uncovered detail view to reload.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Accurate about the mechanism — clearAll() drops cache references and does not refresh a resident TVItemDetailView's @State model — but not something this PR introduces, so leaving it.

The pre-existing saveMetadataLanguage twenty lines up uses exactly this invalidateAllItemMetadata() + clearAll() treatment and has the same limitation; the audio path was written to match it deliberately. Refreshing live detail models needs a broadcast the settings layer doesn't currently have, and it would want to cover both writes rather than only the new one.

Scope is also narrow: on tvOS, Settings is reached from the rail, so the common path has no resident detail screen behind it. The affected case is a detail screen visited earlier in the same session, and the effect is a stale displayed track — playback refetches /watch and is unaffected. Noted in the PR body as a display-consistency follow-up rather than fixed here.

…ing…"

Two defects from the review pass on this PR, each present on both
platforms.

**The completion path could be skipped for a write that landed.** The
success guard returned early unless `pendingAudioLanguageValue` was nil,
so re-selecting the value already in flight — A → B → B before the first
PUT returns — left B queued at completion time, skipping `.saved` and the
cache flush. The drained pass then matched the freshly-recorded
`activeProfile.language` and returned at its own equality guard, so
nothing ever reported: the footer read "Saving…" indefinitely and cached
detail screens kept showing the old track. The write is now recorded
first and reported unconditionally; a genuinely newer value overwrites
the message when it lands. `saveMetadataLanguage` had the same shape via
its editor-value comparison and gets the same treatment.

**One untagged save state served three writes.** `prefSaveState` was
written by the subtitle, metadata, and audio paths and never cleared, so
once the Playback screen started rendering it, a failed subtitle save
appeared under Audio Language and an audio result sat pinned under the
Subtitles footer. Worse on tvOS, where the rail switches panes on focus
alone with no navigation to stale it out. Split into `audioSaveState` /
`subtitleSaveState` / `metadataSaveState`, each rendered under the row
that produces it — which also gives Metadata Language its own footer
line, where before it borrowed the subtitle trio's.

Verified on mac-builder (macOS 26.5.1, Xcode 26.4): Silo, SiloTV, and
SiloMac all BUILD SUCCEEDED; 761 tests, 0 failures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift (1)

250-268: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Serialize subtitle preference writes.

Each change sends a full subtitle payload independently, so requests can complete out of order and restore an older language/mode/forced-subs combination. Queue a snapshot of the latest subtitle payload and only update local state if activeProfile.id still matches the request’s captured profile ID.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift` around lines
250 - 268, Update the subtitle save flow around the updateProfile call to
serialize writes: queue the latest UpdateProfileBody snapshot and process
requests sequentially, ensuring newer changes supersede queued older payloads.
Capture the profile ID for each request and only update activeProfile and
ProfilePrefsStore when activeProfile.id still matches that captured ID.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift`:
- Around line 301-322: Update the preferred-metadata save flows around the PUT
success and failure handling to resolve metadataSaveState when the saved profile
is no longer active instead of returning while it remains .saving. Keep the
profile-ID guard around activeProfile mutation, but perform ResponseCache
invalidation and ItemDetailCache clearing after every successful PUT, including
when the active profile changed; apply the same bookkeeping to the corresponding
flow around the second reported range.

---

Outside diff comments:
In `@iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift`:
- Around line 250-268: Update the subtitle save flow around the updateProfile
call to serialize writes: queue the latest UpdateProfileBody snapshot and
process requests sequentially, ensuring newer changes supersede queued older
payloads. Capture the profile ID for each request and only update activeProfile
and ProfilePrefsStore when activeProfile.id still matches that captured ID.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3faee9e8-5e83-4e99-9253-41a72bf5fa81

📥 Commits

Reviewing files that changed from the base of the PR and between 9113f97 and a5d1c1b.

📒 Files selected for processing (7)
  • iosApp/iosApp/Screens/Settings/PlaybackSettingsView.swift
  • iosApp/iosApp/Screens/Settings/PrefSaveStateLabel.swift
  • iosApp/iosApp/Screens/Settings/SettingsViewModel.swift
  • iosApp/iosApp/Screens/Settings/SubtitleSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVPlaybackSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSettingsViewModel.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift
🚧 Files skipped from review as they are similar to previous changes (6)
  • iosApp/iosApp/tvOS/Screens/Settings/TVPlaybackSettingsView.swift
  • iosApp/iosApp/Screens/Settings/PrefSaveStateLabel.swift
  • iosApp/iosApp/Screens/Settings/SubtitleSettingsView.swift
  • iosApp/iosApp/tvOS/Screens/Settings/TVSubtitleSettingsView.swift
  • iosApp/iosApp/Screens/Settings/PlaybackSettingsView.swift
  • iosApp/iosApp/Screens/Settings/SettingsViewModel.swift

…d-write

The post-await `activeProfile?.id == profileId` guards returned while the
save state was still `.saving`, so a save that completed after the user
switched profiles left the footer reading "Saving…" with nothing able to
clear it — the same stranding the previous commit fixed for the queued-value
case, reached by a different route. The guards now reset the state to nil:
the write is no longer this screen's to report, so the row reports nothing
rather than reporting forever.

Cache invalidation moves ahead of the guard for the same reason. The PUT
succeeded, so the cached item payloads are stale regardless of which profile
is active by the time it returns; skipping the flush on the switched-away
path left `ResponseCache` holding entries the server had already superseded.
Both `invalidateAllItemMetadata()` and `ItemDetailCache.clearAll()` are pure
drops that refetch on demand, and a profile switch is if anything a stronger
reason to drop them.

Applied to the audio and metadata saves on both platforms — the finding was
reported against tvOS, but the iOS view model carried the same two guards
verbatim. `saveProfilePrefs` needs no change: it has no post-await guard and
always resolves its state.

Verified on mac-builder (macOS 26.5.1, Xcode 26.4): Silo, SiloTV, and
SiloMac all BUILD SUCCEEDED; 761 tests, 0 failures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Copy link
Copy Markdown
Contributor Author

Closing this as superseded by the canonical settings architecture introduced by Silo-Server/silo-server#479 and the subsequent Apple settings/Playback V3 work. The current branch is no longer safe to rebase or merge: it moves Audio Language back through the legacy profile DTO and removes the device override path that the canonical contract now owns.

The underlying bug is still valid, however: Apple stores playback.audio_language at profile_device, while the server's catalog and Playback V3 audio selection currently resolve without a device ID, so that override is omitted. I’m filing a replacement server issue and will link the implementation PR there.

Copy link
Copy Markdown
Contributor Author

Replacement work is now tracked in Silo-Server/silo-server#595 and implemented in draft PR Silo-Server/silo-server#596. The fix keeps Apple’s picker device-scoped and makes the server include the explicit device ID in canonical catalog and Playback V3 audio-language resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant