Skip to content

fix(playback): take the media runtime from the v3 plan - #105

Merged
Quick104 merged 1 commit into
mainfrom
fix/playback-source-duration
Jul 26, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/playback-source-duration

Conversation

@Quick104

@Quick104 Quick104 commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The v3 plan's source descriptor was already decoded here, but its runtime was ignored: ApplePlaybackV3PlanAdapter.playbackSession took durationSeconds from the catalog FileVersion the client had selected.

That is the wrong file whenever the server resolves a different effective version — the plan carries both requested_media_file_id and effective_media_file_id precisely because they can differ — and it is unavailable whenever the catalog value is missing or wrong. The same underlying gap showed up on Android as a 90-minute movie playing back as about a minute.

What this does

Prefers plan.source.durationSeconds, falling back to the catalog version only for servers that predate the field.

durationSeconds is declared Double?. This matters more than it looks: every non-Optional property on PlaybackV3SourceDescriptor is a required key under synthesized Codable, so a non-Optional duration would throw keyNotFound against an older server and fail the entire plan — turning a missing runtime into dead playback.

Scope

Client half of Silo-Server/silo-server#482, which adds source.duration_seconds to the v3 plan and fixes the scanner rule that let a wrong duration persist. The Android half is Silo-Server/silo-android#104.

Merge the server PR first. Without it the field is simply absent and behavior is unchanged from today, so this is safe to merge in either order but provides no benefit until the server ships.

Independent of the feat/playback-v3-only work — this branch is cut from main and touches neither the legacy fallback path nor the session bridge.

Verification

$ xcodebuild build -scheme Silo -destination "platform=iOS Simulator,..." -configuration Debug
** BUILD SUCCEEDED **

$ xcodebuild test -scheme Silo -only-testing:SiloTests/PlaybackProtocolV3Tests
Test Case '-[SiloTests.PlaybackProtocolV3Tests testMissingPlanRuntimeFallsBackToTheCatalogVersionDuration]' passed (0.000 seconds).
Test Case '-[SiloTests.PlaybackProtocolV3Tests testPlanDecodesWhenTheSourceRuntimeIsAbsent]' passed (0.001 seconds).
Test Case '-[SiloTests.PlaybackProtocolV3Tests testPlanRuntimeOverridesTheCatalogVersionDuration]' passed (0.000 seconds).
	 Executed 12 tests, with 0 failures (0 unexpected) in 0.052 seconds
** TEST SUCCEEDED **

Three tests added, per the repo guidance to cover critical shared-logic behavior:

  • the plan's runtime overrides the catalog version's (fixture uses 5400 vs the catalog's 120, so the source is unambiguous)
  • a missing plan runtime falls back to the catalog value
  • a descriptor with no duration_seconds key still decodes, guarding the Optional requirement above

Notes

Not addressed here, and worth separate issues:

  • PlaybackSessionBridge reports duration: 0 with forceOverwrite: true on stop, and the server clobbers a good stored duration with it.
  • AVFoundation still wins the duration race in PlayerViewModel: the KVO observer on AVPlayerItem.duration re-fires on every playlist refresh and the monotonic-max guard only rejects smaller values, so a growing HLS window can still extend a known runtime. The server value seeds it rather than overriding it.
  • Six of the eight PlaybackV3Timeline fields are decoded and never read; the seek path uses a hardcoded 30-second window instead of seekWindowStartSeconds/seekWindowEndSeconds/canSeekAnywhere.

AI Disclosure

  • Tool(s): Claude Code
  • Model(s): claude-opus-5[1m]
  • Involvement: fully AI-generated
  • Adversarial review: The design was reviewed by three independent agents before implementation. Two findings shaped this client's half. First, the new property must be Optional — review traced Swift's synthesized Codable treating every non-Optional property on the descriptor as a required key, so declaring the duration non-Optional would fail the whole plan against any older server; the third test exists to lock that in. Second, a proposed rule to represent duration as genuinely "unknown" in the UI was withdrawn after review found TVPlayerScrubber divides by duration with no guard (0/0 → NaN, currently masked only by a duration > 0 check) and NowPlayingController drops the system scrubber when duration is zero. This client keeps treating 0 as unknown internally and only gains a trustworthy first source.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Playback sessions now use the source runtime provided by the playback plan when available.
    • Plans without a source runtime continue using the catalog duration as a fallback.
    • Playback plans can now omit the source duration while remaining compatible with decoding.
  • Tests

    • Added coverage for source-runtime precedence, catalog fallback behavior, and plans missing duration data.

The plan's source descriptor was decoded but its runtime was ignored: the
session took durationSeconds from the catalog FileVersion the client had
picked. That is the wrong file whenever the server resolves a different
effective version, and it is unavailable whenever the catalog value is
missing.

Prefer plan.source.durationSeconds and fall back to the catalog only for
servers that predate the field. The property is Optional because every
non-Optional property on the descriptor is a required key — a non-Optional
duration would fail the entire plan against an older server.

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

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 281f7df1-2d3e-4249-9fc3-b8c134c873aa

📥 Commits

Reviewing files that changed from the base of the PR and between 4eaf2c5 and 09e85e0.

📒 Files selected for processing (3)
  • iosApp/Tests/PlaybackProtocolV3Tests.swift
  • iosApp/iosApp/Screens/Player/ProtocolV3/ApplePlaybackV3PlanAdapter.swift
  • iosApp/iosApp/Screens/Player/ProtocolV3/PlaybackProtocolV3Models.swift

📝 Walkthrough

Walkthrough

The V3 source descriptor now carries an optional source runtime. playbackSession prefers that runtime and falls back to the catalog duration when it is absent. Tests cover precedence, fallback, and decoding responses that omit duration_seconds.

Changes

Playback duration handling

Layer / File(s) Summary
Optional source runtime and adapter fallback
iosApp/iosApp/Screens/Player/ProtocolV3/PlaybackProtocolV3Models.swift, iosApp/iosApp/Screens/Player/ProtocolV3/ApplePlaybackV3PlanAdapter.swift
PlaybackV3SourceDescriptor adds optional durationSeconds, and playbackSession uses it before selectedVersion.duration.
Duration selection coverage
iosApp/Tests/PlaybackProtocolV3Tests.swift
Tests verify source-runtime precedence, catalog fallback, absent-field decoding, and helper support for optional runtimes.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: preferring the V3 plan’s runtime over the catalog value.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/playback-source-duration

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

@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: 09e85e0a02

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

// file the server actually chose. Fall back to the catalog version
// only for servers that predate the field; substituting it when
// the server reports an unknown runtime would reintroduce a guess.
durationSeconds: plan.source.durationSeconds ?? selectedVersion.duration,

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 an explicitly unknown plan duration

When a current server returns "duration_seconds": null because the effective source runtime is unknown, synthesized Codable produces the same nil as an absent legacy key, so this fallback substitutes selectedVersion.duration. If the server selected a different effectiveMediaFileId, that duration belongs to the requested file and produces incorrect scrubber/progress reporting—the case this change is intended to fix. Distinguish an absent legacy key from an explicitly unknown value and preserve the latter through the downstream catalog fallback.

AGENTS.md reference: AGENTS.md:L19-L22

Useful? React with 👍 / 👎.

@Quick104
Quick104 merged commit 8db35a8 into main Jul 26, 2026
1 check passed
@Quick104
Quick104 deleted the fix/playback-source-duration branch July 26, 2026 04:12
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