Skip to content

fix(auth): use native branding for server names - #126

Merged
Quick104 merged 2 commits into
mainfrom
codex/native-branding-server-name
Aug 7, 2026
Merged

Quick104 merged 2 commits into
mainfrom
codex/native-branding-server-name

Conversation

@Quick104

@Quick104 Quick104 commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The Apple client saves and displays GET /api/v1/health.server_name. That field is currently backed by the Jellyfin compatibility setting, so an iOS or tvOS client can show “StreamApp” even when Jellyfin compatibility is disabled.

Fixes #125.
Related to Silo-Server/silo-server#553.

Approach

  • Resolve native server identity from the public GET /api/v1/theme/branding endpoint.
  • Fall back to GET /api/v1/health for older servers.
  • Refresh saved names when the active server changes, with an identity guard so a delayed response cannot rename a different server.
  • Preserve the existing URL fallback when neither endpoint returns a usable name.

Validation

  • xcodegen generate
  • iOS simulator: ServerIdentityResolverTests — 3 tests passed
  • tvOS simulator: SiloTV build succeeded
  • Reviewed the shared SwiftUI boundary with the repository's SwiftUI guidance; no view-level changes were needed.

Risk

Low. Both identity requests are public, best-effort reads. Existing servers remain compatible through the health fallback, and failures retain the existing URL display name.

AI use

Implemented and validated with Codex on behalf of the repository maintainer.

Summary by CodeRabbit

  • New Features

    • Server names now load from native branding information when available.
    • Older servers continue to display their name through a health-check fallback.
    • Active server names refresh automatically when switching or reactivating servers.
    • TV controls now update when the active server’s display name changes.
  • Bug Fixes

    • Improved handling of blank, unavailable, or outdated server-name responses.
    • Prevented stale responses from overwriting the currently active server’s name.
    • Reduced unnecessary logging for expected unavailable-server responses.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The app now resolves server names from native branding, falls back to the health endpoint when needed, and refreshes names during active-server transitions. tvOS control advertisements also track name changes. Tests cover fallback behavior and stale asynchronous responses.

Changes

Server identity resolution

Layer / File(s) Summary
Branding response and resolver
iosApp/iosApp/Screens/Auth/AuthModels.swift, iosApp/iosApp/Networking/ServerIdentityResolver.swift, iosApp/iosApp/Networking/HTTPClient.swift
Adds the branding response model. Resolves trimmed, non-empty names from branding before using the health endpoint. Supports quiet handling for selected unauthenticated HTTP statuses.
Authentication and active-server refresh
iosApp/iosApp/Screens/Auth/AuthService.swift, iosApp/iosApp/ContentView.swift, iosApp/iosApp/Networking/ServerRegistry.swift
Uses the resolver during server checks and refreshes the active registry entry after transitions. Discards cancelled or stale results.
tvOS identity advertisement updates
iosApp/iosApp/Control/tvOS/TVControlReceiver.swift, iosApp/iosApp/tvOS/Navigation/TVMainTabView.swift
Tracks the advertised server name and restarts the control receiver when the active display name changes.
Resolver and refresh race tests
iosApp/Tests/ServerIdentityResolverTests.swift
Tests branding preference, health fallback, blank names, request handling, and protection against stale refresh responses.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ContentView
  participant AuthService
  participant ServerIdentityResolver
  participant BrandingEndpoint
  participant HealthEndpoint
  participant ServerRegistry
  participant TVControlReceiver
  ContentView->>AuthService: Activate or refresh server
  AuthService->>ServerIdentityResolver: Fetch server name
  ServerIdentityResolver->>BrandingEndpoint: Request native branding
  BrandingEndpoint-->>ServerIdentityResolver: Usable or blank server_name
  ServerIdentityResolver->>HealthEndpoint: Request health when branding is unusable
  HealthEndpoint-->>ServerIdentityResolver: Legacy server_name
  ServerIdentityResolver-->>AuthService: Resolved name or nil
  AuthService->>ServerRegistry: Update active server name
  ServerRegistry-->>TVControlReceiver: Active display name changes
  TVControlReceiver->>TVControlReceiver: Restart advertisement
Loading

Possibly related issues

Possibly related PRs

  • Silo-Server/silo-apple#82 — Modifies TVControlReceiver identity tracking and listener reuse.
  • Silo-Server/silo-apple#120 — Overlaps in server identity transition handling across AuthService, ContentView, ServerRegistry, HTTPClient, and TVControlReceiver.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.81% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: using native branding for server names.
Linked Issues check ✅ Passed The changes satisfy issue #125 by implementing branding preference, health fallback, refresh, URL fallback, identity guards, and focused tests.
Out of Scope Changes check ✅ Passed All changes support server identity handling, refresh behavior, tvOS listener updates, fallback logging, or related test coverage.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/native-branding-server-name

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

@Quick104
Quick104 marked this pull request as ready for review August 7, 2026 15:50

@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

🤖 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/Screens/Auth/AuthService.swift`:
- Around line 121-132: Add focused tests for AuthService.refreshActiveServerName
covering both a normal active-server name update and a delayed response for
server A after switching to server B; verify the stale response does not update
server B, while the active response updates its matching registry entry.
🪄 Autofix

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: e9e5414f-2795-4b85-b2a2-626a0b6c44b7

📥 Commits

Reviewing files that changed from the base of the PR and between 682530b and 8804c74.

📒 Files selected for processing (6)
  • iosApp/Tests/ServerIdentityResolverTests.swift
  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Networking/ServerIdentityResolver.swift
  • iosApp/iosApp/Networking/ServerRegistry.swift
  • iosApp/iosApp/Screens/Auth/AuthModels.swift
  • iosApp/iosApp/Screens/Auth/AuthService.swift

Comment on lines +121 to +132
/// Refreshes the active registry entry from the server's native branding.
/// The identity check prevents a slow response from one server renaming a
/// different server after the user switches destinations.
func refreshActiveServerName() async {
guard let server = ServerRegistry.shared.activeServer else { return }
let serverId = server.id
guard let name = await serverIdentityResolver.fetchServerName(serverURL: server.url),
ServerRegistry.shared.activeServerId == serverId else {
return
}
ServerRegistry.shared.updateFetchedName(for: serverId, fetchedName: name)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Add refresh-path identity-guard coverage.

The supplied tests cover resolver responses only. They do not exercise refreshActiveServerName(), its registry update, or its stale-server guard.

Add a focused test that delays a refresh for server A, switches to server B, then verifies that the delayed result cannot change server B. Also test a normal active-server refresh.

As per coding guidelines, “for shared-logic changes, add focused tests only for critical or high-risk behavior.”

🤖 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/Auth/AuthService.swift` around lines 121 - 132, Add
focused tests for AuthService.refreshActiveServerName covering both a normal
active-server name update and a delayed response for server A after switching to
server B; verify the stale response does not update server B, while the active
response updates its matching registry entry.

Source: Coding guidelines

@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: 8804c7489a

ℹ️ 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".

return name
}

if let health: HealthStatus = try? await httpClient.getUnauthenticated(

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 Restrict health fallback to unsupported branding endpoints

When a current server's branding request transiently fails with a timeout, 5xx, or malformed response, try? collapses that failure and this unconditional fallback accepts /health.server_name. Because that health field is the Jellyfin compatibility label this change is intended to avoid, refreshActiveServerName() can then overwrite a previously correct native name with the wrong product name. Fall back only when branding is definitively unsupported, such as a 404, and preserve the existing name for transient or decoding failures.

Useful? React with 👍 / 👎.

Comment thread iosApp/iosApp/ContentView.swift Outdated
// queued and must perform no work for the stale destination.
guard await HTTPClient.shared.waitForRequestDispatchOpen() else { return }
guard !Task.isCancelled else { return }
await AuthService.shared.refreshActiveServerName()

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 Clear server-scoped state before refreshing the name

When the destination's branding or health endpoint is slow, awaiting this best-effort refresh delays the rest of the server-change task by one or two network timeouts. During that delay, OverlayPrefsStore still has the previous server's hydrated values because overlayPrefs.clear() has not run, so views rebuilt for the new server can render the old server's preferences and may temporarily ignore the destination server's overlay kill switch. Perform the boundary reset before waiting for the display-name refresh, or run the refresh independently of the required cleanup.

Useful? React with 👍 / 👎.

ServerRegistry.shared.activeServerId == serverId else {
return
}
ServerRegistry.shared.updateFetchedName(for: serverId, fetchedName: name)

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 Republish the tvOS identity after updating the name

On tvOS, when activation replaces a stale fetchedName with native branding, this line only updates the registry. TVMainTabView starts TVControlReceiver on the activeServerId change before the asynchronous refresh finishes, and TVControlReceiver.start returns at TVControlReceiver.swift:68 whenever the listener already advertises that server ID without comparing its advertised name. The Bonjour TXT record therefore keeps the old health-derived name, so iPhone remote discovery continues showing it until the listener is recreated; refresh the advertisement or make the receiver observe name changes after a successful update.

Useful? React with 👍 / 👎.

- Only fall back to the legacy health server name when branding returns
  404 (or a blank name); other failures keep the stored name so transient
  errors can't resurface the Jellyfin-compat label
- Run refreshActiveServerName after server-scoped state clearing in
  ContentView, fire-and-forget, so a slow server never delays the
  diagnostics reset and token/overlay switch
- Restart the tvOS control listener when the advertised server name
  changes for the same server id
- Add a test covering the stale-server identity guard via a minimal
  AuthService injection seam

Implemented by OpenAI Codex (gpt-5.6-sol), reviewed and verified locally.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Quick104

Quick104 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 67767f8 addressing the review findings:

  1. Health fallback now fires only on branding 404 or a blank branding name; timeouts/5xx/decode failures return nil so a transient error can't resurface the Jellyfin-compat label (ServerIdentityResolver).
  2. refreshActiveServerName() moved after the server-scoped state clearing in ContentView and made fire-and-forget, restoring the feat: add synced navigation and card customization #120 ordering (diagnostics reset first).
  3. tvOS TVControlReceiver now tracks the advertised name and restarts the Bonjour listener when it changes for the same server id, with a matching .onChange in TVMainTabView.
  4. Added a test for the stale-server identity guard (fetch for server A in flight, switch to B, assert neither entry is renamed) via a minimal AuthService injection seam.

Verified: focused identity tests 6/6 passing, iOS and tvOS simulator builds succeed.

@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: 67767f87f8

ℹ️ 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 +69 to +71
if listener != nil,
advertisedServerId == serverId,
advertisedServerName == serverName {

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 the advertisement without stopping control

When the asynchronous branding refresh changes the active server’s saved name while a phone is controlling the TV, the new name comparison makes start(router:) fall through to stop(). That method calls closeActiveSession(sendClose: false), so merely updating the Bonjour TXT name disconnects the active remote-control session and cancels any in-progress handoff. Rebuild only the listener advertisement, as refreshAdvertisement() does, while preserving the accepted session.

Useful? React with 👍 / 👎.

@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

🤖 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/Control/tvOS/TVControlReceiver.swift`:
- Line 125: Update refreshAdvertisement() where advertisedServerName is assigned
to reuse the same fallback resolver as start(router:), preserving the
server.displayName fallback when effectiveServerName is unavailable instead of
hardcoding "Silo".
🪄 Autofix

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: 6ebff79b-f704-4012-bed6-9ab5d6d57a46

📥 Commits

Reviewing files that changed from the base of the PR and between 8804c74 and 67767f8.

📒 Files selected for processing (7)
  • iosApp/Tests/ServerIdentityResolverTests.swift
  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Control/tvOS/TVControlReceiver.swift
  • iosApp/iosApp/Networking/HTTPClient.swift
  • iosApp/iosApp/Networking/ServerIdentityResolver.swift
  • iosApp/iosApp/Screens/Auth/AuthService.swift
  • iosApp/iosApp/tvOS/Navigation/TVMainTabView.swift
🚧 Files skipped from review as they are similar to previous changes (3)
  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Networking/ServerIdentityResolver.swift
  • iosApp/iosApp/Screens/Auth/AuthService.swift

listener.start(queue: .main)
self.listener = listener
advertisedServerId = serverId
advertisedServerName = serverName

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve the URL fallback during listener refresh.

start(router:) uses server.displayName when effectiveServerName is unavailable. refreshAdvertisement() uses "Silo" instead. After an advertisement refresh, line 125 can cache "Silo" and publish the wrong Bonjour server name.

Use the same fallback resolver in both paths.

Proposed fix
-        let serverName = RemotePlaybackIdentityManager.shared.effectiveServerName ?? "Silo"
+        let serverName = RemotePlaybackIdentityManager.shared.effectiveServerName
+            ?? ServerRegistry.shared.activeServer?.displayName
+            ?? "Silo"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
advertisedServerName = serverName
let serverName = RemotePlaybackIdentityManager.shared.effectiveServerName
?? ServerRegistry.shared.activeServer?.displayName
?? "Silo"
🤖 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/Control/tvOS/TVControlReceiver.swift` at line 125, Update
refreshAdvertisement() where advertisedServerName is assigned to reuse the same
fallback resolver as start(router:), preserving the server.displayName fallback
when effectiveServerName is unavailable instead of hardcoding "Silo".

@Quick104
Quick104 merged commit f33e674 into main Aug 7, 2026
1 check passed
@Quick104
Quick104 deleted the codex/native-branding-server-name branch August 7, 2026 17:30
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.

Use native branding for saved server names

1 participant