Skip to content

fix(apiv2): decode v2 models as the server sends them - #353

Merged
Quick104 merged 1 commit into
mainfrom
apiv2-stack/05-fix-v2-model-decoding
Sep 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
apiv2-stack/05-fix-v2-model-decoding

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

Several APIv2 models that no app code calls yet do not match the server's contract (contracts/api/v2/openapi.json at 84ed9e596). The later PRs that wire them would have hit these bugs:

  • APIv2PlaybackControlCapabilities required ownerLeaseAdmission. The server never sends that member (playback_control_socket_test.go:110, 124 checks that it is absent), so playbackControlRequest fails to decode every capability response. The model also skipped allowed, state and revision.
  • APIv2CatalogSearchCapabilities required provider, which the contract marks optional. It treated allowed, which the contract requires, as optional. It also lacked people_media_scope and person_prefetch. A server with search not configured omits provider, and the whole read failed.
  • APIv2MetadataAICapability ignored allowed. A principal the server refuses would still see the translate affordance.
  • Stored subtitles could only be projected one row at a time with try. A list read would fail entirely because of one row whose opaque string ID does not fit the player's integer handle.
  • APIv2Client.catalogFilters captured its owner inside requestGet. The caller could not supply the owner it caches results under, and the read did not require the profile that openapi requires (X-Profile-Id).

Solution

  • APIv2PlaybackControlCapabilities now decodes available, protocol, revision, state and allowed. servesControlHandshake requires allowed && state == "available" && available && protocol == "silo.playback-control.v2". playbackControlRequest checks the 200 status before it decodes and mints a ticket only under that gate. The TLS rule (D11) is left for W2-D.
  • APIv2CatalogSearchCapabilities: provider is optional and allowed is required. It adds peopleMediaScope, personPrefetch and an isAvailable gate (allowed && state == "available", invariant I9).
  • APIv2MetadataAICapability requires allowed. playerValue is enabled only when allowed && state == "available". on_view stays tolerant: an unknown value decodes to .off, as before.
  • APIv2StoredSubtitles.playerValues(mediaFileID:) returns the rows the player can address and drops rows with opaque, oversized or non-canonical IDs, or rows for another file. The single-row projection and the AI job projection stay strict. No code force-unwraps an ID. W5-Q uses this list projection when it moves downloadedSubtitles to v2.
  • catalogFilters(libraryId:includeTechnical:auth:) takes the caller's captured owner. It requires a profile, checks that the owner is still current before dispatch, and runs under withOwnerFence, the same pattern as calendar and similarCards. The fence count in iosApp/iosApp rises by one. There are no app callers yet; W5-L wires CatalogFacets.

Fixtures: on top of F0's pin, this PR vendors get_catalog_search_capabilities_ok, get_metadata_ai_capability_ok and get_catalog_filters_ok from server commit 84ed9e596. It adds their bodies, their index.json entries and their names to SELECTED in scripts/sync-apiv2-fixtures.sh, and regenerates SOURCE (36 vendored files). The server publishes no control-capabilities fixture, so playback_control_capabilities.json is written by hand from the openapi schema and added to AUTHORED, next to playback_stop_draining.

Validation

All runs used a local xcodebuild runner (simulator builds with ad-hoc signing):

  • build ios, build tvos, build macos: PASS.
  • test ios SiloTests/APIv2ContractTests SiloTests/CatalogV2Tests SiloTests/APIv2SubtitleTests SiloTests/PlaybackProtocolV3Tests: PASS, 135 tests, 0 failures.
  • test ios SiloTests/AIModelDecodingTests: PASS, 24 tests.
  • test tvos on the same five classes (SiloTVTests): PASS, 159 tests, 0 failures.

New or changed tests:

  • APIv2ContractTests.testCatalogSearchCapabilitiesFixture: the server fixture, a minimal unconfigured body, a denied principal, and a missing allowed, which must fail to decode.
  • APIv2ContractTests.testMetadataAICapabilityFixture: the server fixture, an unknown on_view value, and allowed: false.
  • APIv2ContractTests.testPlaybackControlCapabilitiesFixture and testPlaybackControlRequestMintsOnlyWhenTheServerServesTheHandshake: an allowed capability mints a ticket; a denied capability never sends the ticket POST.
  • APIv2SubtitleTests.testStoredListDropsRowsThatDoNotFitPlayerHandles.
  • CatalogV2Tests.testCatalogFiltersAreBoundToTheCallersOwner: the server fixture, the path, the query and X-Profile-Id; a replaced owner is refused before dispatch; an owner change while the read is in flight is discarded.
  • The vendored-index count in APIv2ContractTests goes from 31 to 34. The owner-fence table in CatalogV2Tests now calls requestGet directly.

scripts/ci/check-no-api-v1.sh: ok. This PR adds no v1 path.

  • Final stack: with all 50 PRs applied, the full iOS suite (1981 tests) and tvOS suite (1792 tests) passed with 0 failures, the macOS build passed, and the v1 path guard passed. Every branch in the stack, this one included, builds on its own.

Risks and follow-ups

  • A server that denies control sockets, or does not configure them, still produces PlaybackSequencedError.invalidResponse, as before. W2-D decides how the remote UI presents that case.
  • None of these models has an app caller yet, so no user-visible behavior changes. W2-D, W5-I, W5-J, W5-L, W5-Q and W5-S wire them.

AI disclosure

Code and description written by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.


Part 5 of 50 in the Apple API v2 stack. Base: apiv2-stack/04-delete-dead-v1-reads. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 67c143c3-7b0f-431d-b01f-14fb84bc5b1c

📥 Commits

Reviewing files that changed from the base of the PR and between fc31513 and 16cb951.

📒 Files selected for processing (15)
  • iosApp/Tests/APIv2ContractTests.swift
  • iosApp/Tests/APIv2SubtitleTests.swift
  • iosApp/Tests/CatalogV2Tests.swift
  • iosApp/Tests/Fixtures/APIv2/SOURCE
  • iosApp/Tests/Fixtures/APIv2/get_catalog_filters_ok.json
  • iosApp/Tests/Fixtures/APIv2/get_catalog_search_capabilities_ok.json
  • iosApp/Tests/Fixtures/APIv2/get_metadata_ai_capability_ok.json
  • iosApp/Tests/Fixtures/APIv2/index.json
  • iosApp/Tests/Fixtures/APIv2/playback_control_capabilities.json
  • iosApp/iosApp/Networking/APIv2/APIv2CatalogModels.swift
  • iosApp/iosApp/Networking/APIv2/APIv2Client.swift
  • iosApp/iosApp/Networking/APIv2/APIv2PlaybackModels.swift
  • iosApp/iosApp/Networking/APIv2/APIv2SubtitleModels.swift
  • iosApp/iosApp/Networking/APIv2/APIv2SupportModels.swift
  • scripts/sync-apiv2-fixtures.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:33:18.596960Z 16cb951 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: 84c89347 (apiv2-stack/05-fix-v2-model-decoding).

Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration.

Verified findings: none.

Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no /api/v1 request from the new builds except the retained health probe.

Remaining: no open verified findings. Merge in stack order.

Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack.

Review by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code).

@Quick104
Quick104 force-pushed the apiv2-stack/04-delete-dead-v1-reads branch from 43c7772 to 9fff17c Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/05-fix-v2-model-decoding branch from 84c8934 to 8f69772 Compare September 23, 2026 13:19

@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: 8f697728e2

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

/// player handle, or that names another file, is left out instead of
/// failing the whole list.
func playerValues(mediaFileID: Int) -> [DownloadedSubtitle] {
subtitles.compactMap { try? $0.playerValue(mediaFileID: mediaFileID) }

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 Preserve subtitle ordinals when filtering IDs

When an opaque, oversized, or wrong-file row precedes a valid row, compactMap shifts the valid row's position. Downloaded subtitle stream URLs are addressed by the row's original position in the server listing—not by its database ID—so a downstream firstIndex followed by synthesizedDescriptor(position:) will request the wrong subtitle track. Preserve each row's original ordinal while filtering, or return a projection that carries that ordinal.

AGENTS.md reference: AGENTS.md:L16-L17

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/04-delete-dead-v1-reads branch from 9fff17c to 1231237 Compare September 23, 2026 13:29
Several unwired APIv2 models disagreed with the server's openapi document.
The playback control capabilities model required an ownerLeaseAdmission
member the server never sends, so every control-ticket request failed to
decode. Catalog search capabilities required provider (optional on the
wire) and treated allowed (required) as optional. Metadata AI status
ignored allowed. A stored subtitle list could only be projected all or
nothing, and catalogFilters captured its own owner instead of taking the
caller's, so facet results could not be tied to the profile that asked.

Match each model to the 84ed9e596 contract: drop ownerLeaseAdmission and
gate the ticket on allowed, state, available and protocol; make provider
optional, allowed required and add people_media_scope and person_prefetch;
honor allowed for metadata AI while keeping on_view tolerant; add a
fail-soft stored-subtitle list projection; and bind catalogFilters to a
supplied owner with a required profile. Each fix has a fixture test,
using the server's published fixtures where they exist.

Stack-PR: F4

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Base automatically changed from apiv2-stack/04-delete-dead-v1-reads to main September 23, 2026 13:29
@Quick104
Quick104 force-pushed the apiv2-stack/05-fix-v2-model-decoding branch from 8f69772 to 16cb951 Compare September 23, 2026 13:30
@Quick104
Quick104 merged commit 0b6bd88 into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/05-fix-v2-model-decoding branch September 23, 2026 13: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.

1 participant