Skip to content

feat(playback): share v2 playback capabilities and installation id - #376

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/28-playback-capabilities-v2
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/28-playback-capabilities-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Video and audiobook playback now read their capability from GET /api/v2/playback/capabilities, through one shared gate that also owns the server's installation_id and refreshes it when the server reports 409 installation_changed.

Problem

PlaybackV3CapabilityGate read GET /api/v1/playback/capability (row 78). That document has no installation_id. Every v2 playback mutation (start, replan, route-events, progress, stop) must send that id in its body. The server checks it against its persisted ServerInstanceID and refuses a mismatch with 409 installation_changed ("refresh capabilities"). Before the session cutover (W2-B) can land, one place has to own the id, hand it to both players, and refresh it on that 409.

Solution

  • One provider. PlaybackV3CapabilityGate reads the v2 document through SiloAPI.shared.apiV2Client.playbackCapabilities(auth:), under an owner captured from TokenStore. playbackRequest fences the request and sends X-Profile-Id. Video (PlaybackSessionBridge.stageProtocolV3Start) and audiobook (AudioPlayerViewModel.startSession) both use it.
  • Contract. APIv2PlaybackCapabilities.requireAvailable() requires state == "available", allowed, protocol 3, playback_plan_v3, neutral_playback_v3_contract_v1, header_authenticated_media_v1, sequenced_progress_v1, and a non-empty installation_id. NeutralProtocolV3Capability.installationID is a non-optional String (F14). The previous check also used v1 enabled, which v2 does not send.
  • Caching. Unchanged in shape: only an available capability is cached, per server id. A refusal is re-probed on the next Play. A concurrent probe is still shared.
  • Refusals. A v1-only server (legacy 404, or the recorded serverUpdateRequired verdict) becomes a non-retryable server_upgrade_required failure with the shared D7 copy ("This server needs to be updated before this version of Silo can use it."). Missing required features give the same failure and copy, replacing the older TestFlight-specific text. 409 capability_not_configured and state: not_configured both give playback_not_configured.
  • installation_changed. withInstallationRefresh runs a start with the current capability. On 409 installation_changed it drops the cached capability for that installation, probes again, and runs the start once more. A second refusal is surfaced, so it never loops. The probe runs in its own task and does not see the caller's cancellation, so the helper checks for cancellation before each start: a player dismissed, or an autoplay start that timed out, during the refresh throws CancellationError instead of starting a session nobody owns. Both start paths now mint playback_attempt_id and build the request inside the closure, so a refreshed start always gets a new attempt id (I18). The existing same-request retry after a transport error is unchanged and still reuses the same attempt id.
  • Deleted: SiloAPI.playbackV3Capability (the v1 path), PlaybackV3CapabilityResponse, PlaybackSessionBridge.supportsNeutralProtocolV3, isMissingProtocolV3Capability, the v1 Tests/Fixtures/PlaybackV3/capability_response.json fixture and its assertions. The fixture SOURCE note records why that file is not vendored.
  • The audiobook start now checks for a selected profile before probing, because the v2 capability read requires one.

This PR writes nothing to the server. getPlaybackCapabilities is a read, so no failure-outcome table applies. The start mutations still use v1 here and move in W2-B.

Validation

  • iOS, tvOS and macOS builds passed on this branch.
  • Focused tests passed on iOS and tvOS: PlaybackCapabilityGateTests, PlaybackProtocolV3Tests, APIv2ContractTests, PlaybackProtocolV3ConformanceFixtureTests and UpdateRequirementTests.
  • scripts/ci/check-no-api-v1.sh passed. The ownership-fence line count in iosApp/iosApp stays at 64.
  • New PlaybackCapabilityGateTests (on StubURLProtocol through APIv2TestStub and the vendored v2 fixtures) cover:
    • the contract: each required feature, not_configured, and a missing installation_id
    • positive-only caching: a refusal is re-probed, an available capability is served from cache, and the request is a GET to /api/v2/playback/capabilities with X-Profile-Id
    • 409 capability_not_configured and the legacy 404 mapping to terminal failures
    • 409 installation_changed refetching and rerunning the start with the new installation, after which the cache holds the new one
    • other start failures neither refetching nor retrying, and a second installation_changed surfacing instead of looping
    • a caller cancelled while the refresh probe is in flight getting CancellationError, with the start run only once. This test fails when the cancellation check is removed.
  • The final stack passed the full suites (iOS 1981 tests and tvOS 1792 tests, 0 failures), the macOS build and the v1 path guard, and every branch in the stack builds on its own.
  • Not run: manual playback on a device or simulator. Until W2-B moves the starts to v2, a v1 start cannot return installation_changed, so only the tests above exercise the refresh path on this branch.

Risks and follow-ups

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 28 of 50 in the Apple API v2 stack. Base: apiv2-stack/27-progress-reread-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

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

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: e2d932d9-0520-471e-927e-3385ed789e95

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@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:44:40.607143Z 83820f0 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: ba819592 (apiv2-stack/28-playback-capabilities-v2).

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, all fixed on this branch:

  • minor: The installation refresh re-runs the start after the caller has cancelled

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

@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: 6375069b7f

ℹ️ 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 +210 to +212
let required = [PlaybackProtocolV3.planFeature, PlaybackProtocolV3.neutralContractFeature,
PlaybackProtocolV3.headerAuthenticatedMediaFeature, PlaybackSequencedContract.feature]
guard protocolVersions.contains(PlaybackProtocolV3.version), required.allSatisfy(features.contains) else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Accept the v2 capability document the server actually returns

Remove this token from the v2 capability gate or coordinate a server-contract change first. The vendored Tests/Fixtures/APIv2/playback_capability_available.json, sourced from server commit 84ed9e596, does not include header_authenticated_media_v1; the new test manually appends it before exercising this guard. Consequently, an unmodified capability response from that server reaches this check and every video or audiobook start fails with server_upgrade_required, even though the document reports playback as available.

AGENTS.md reference: AGENTS.md:L12-L21

Useful? React with 👍 / 👎.

@Quick104
Quick104 force-pushed the apiv2-stack/27-progress-reread-v2 branch from 64e5328 to 0ae7311 Compare September 23, 2026 13:40
Base automatically changed from apiv2-stack/27-progress-reread-v2 to main September 23, 2026 13:40
Quick104 and others added 2 commits September 23, 2026 09:40
Video and audiobook playback read their capability from
GET /api/v1/playback/capability, which has no installation_id. Every v2
playback mutation must echo that id, and the server refuses a stale one
with 409 installation_changed, so the v2 session cutover needs one place
that owns the id and can refresh it.

PlaybackV3CapabilityGate now reads GET /api/v2/playback/capabilities
through the shared APIv2Client, under the captured owner. It requires
state available, allowed, protocol 3, the neutral plan, header-authenticated
media, sequenced progress and a non-empty installation_id, and hands out a
non-optional installationID. It still caches only an available capability,
per server, and re-probes after a refusal. A v1-only server and a server
without a playback installation identity (409 capability_not_configured)
become non-retryable terminal failures; the v1-only case shows the shared
server-update message.

withInstallationRefresh runs a start with the current capability and, on
409 installation_changed, drops the cached capability, probes again and
runs the start once more. Both start paths now mint the attempt id and
request inside that closure, so a refreshed start always carries a new
playback_attempt_id. The starts still go to v1 until the session cutover,
so the refresh path is exercised by tests only for now.

Deletes SiloAPI.playbackV3Capability, PlaybackV3CapabilityResponse,
supportsNeutralProtocolV3, isMissingProtocolV3Capability and the v1
capability_response.json fixture.

Stack-PR: W2-A
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
withInstallationRefresh awaits the capability probe, which runs in an
unstructured task and does not observe the caller's cancellation. After a
409 installation_changed, a player dismissed or an autoplay start that
timed out during the re-probe still ran the start again. Once W2-B moves
the starts to v2, that allocates a server session for a player that is
already gone.

The helper now checks for cancellation after each capability probe and
before each start, and throws CancellationError instead. A new gate test
cancels the caller while the re-probe is suspended and asserts the start
ran once.

Stack-PR: W2-A
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/28-playback-capabilities-v2 branch from 6375069 to 83820f0 Compare September 23, 2026 13:40
@Quick104
Quick104 merged commit 538076d into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/28-playback-capabilities-v2 branch September 23, 2026 13:40
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