Skip to content

fix(software): publish retained VOD ranges and honor bounded seek outcomes - #759

Merged
superuser404notfound merged 5 commits into
superuser404notfound:mainfrom
orut34iop:codex/fix-software-vod-resident-ranges
Oct 15, 2026
Merged

superuser404notfound merged 5 commits into
superuser404notfound:mainfrom
orut34iop:codex/fix-software-vod-resident-ranges

Conversation

@orut34iop

@orut34iop orut34iop commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem and resulting behavior

Software VOD can retain enough compressed packets to replay an earlier position while publishing no residentRanges. Inferring a cache band from [currentTime, bufferedPosition] makes the band move or disappear during scrubbing. Publishing the actual retained ranges exposed related correctness problems: rounded VC-1 durations fragmented continuous coverage, a remote read error hid valid committed packets, and unsuccessful cold positioning could still be finalized as a successful resume/seek.

This PR makes software VOD residency and positioning agree with the packet evidence and the demux result. A cached seek preserves verified coverage; a cold seek discards the old store and either lands or reports failure. Slow but progressing remote positioning receives a bounded opportunity to finish.

Changes

Publish retained packet coverage

  • Convert exact packet timestamps to presentation spans, intersect video with selected audio even when muted, and preserve genuine holes. Video-only sources need no audio coverage.
  • Reuse bounded successor-PTS coverage for H.264, HEVC and VC-1. Rounded 33 ms durations on a 33/34 ms timestamp cadence no longer manufacture tiny holes. Reordering, real discontinuities and the unknown final-frame end remain conservative.
  • Track per-chunk discarded timestamp floors and require retained keyframes. FIFO eviction and bounded metadata can shorten published history, never enlarge it.
  • Sample on the existing periodic timer, including while paused, through BlockingWork.detached. Copy metadata under the lock and calculate spans outside it; no UI-time disk scans.
  • Coalesce sampling and reject stale host/load/origin/seek results. Map source timestamps to the same display axis as currentTime and seek(to:).

Preserve committed data after a source read error

  • Distinguish source-read failure from FIFO storage and packet-envelope failure.
  • A source-read error leaves committed, verified packets usable for residency and cached seeks. Consumption drains those exact bytes and then throws the original error; it never converts the failure to EOF or flushes unresolved successor timestamps.
  • Storage/envelope failure still invalidates usability. A cache miss starts a new source lifetime; eviction/reset/close rules remain effective.
  • Edge-triggered numeric state diagnostics contain no source identity or packet content.

Honor resume/seek outcomes

  • Failed software resume throws before readiness or a requested clock anchor is published.
  • Failed software seek does not restart decoding or finalize the requested target as landed. It parks the host, clears residency, and publishes .softwarePipelineFailed; the engine closes the seek as .stalled without overwriting the error with a playable state.
  • Stop, cancellation and superseding seeks reject stale completions. Tests use the upstream SeekEvent.id contract, without downstream request-ID extensions.

Allow bounded remote positioning to finish

  • During a finite read deadline, a cold detour miss immediately uses the existing persistent streaming reconnect instead of first waiting for a speculative 4 MiB detour block. Already resident blocks still hit, and ordinary unbounded parsing keeps the existing detour behavior.
  • Increase the software host's foreground positioning budget from 8 to 30 seconds. Index-poor containers can require several random keyframe probes; a successful response from cloud-backed storage can itself take multiple seconds.
  • Positioning remains off-main with a finite I/O deadline. The budget begins after demux access is acquired, so an earlier in-flight read can add to total call time. This is not a 30-second end-to-end guarantee, nor a promise that all remote sources will seek successfully. A failing source may take longer to report failure.

Relationship to upstream

Regression coverage

Synthetic tests cover cached seek begin/prepare/settle, missing audio and audio islands, rounded VC-1 timestamps, reordering and real gaps, FIFO eviction with byte-identical reads, invalid timestamp watermarks, source errors versus storage failure, draining/replaying a failed source and resetting on a miss, display-origin mapping, paused publication, background execution, coalescing and stale publication rejection.

Positioning tests cover successful/failed resume, stop and caller cancellation, failed seek with/without an attached error sink, event identity, and superseding seeks. Loopback-origin tests verify exact bytes, bounded cold-detour bypass, retained hits without a new request and restoration of ordinary detours. The documented host budget has a source-backed documentation check.

Tests use synthetic packet envelopes, an existing generated test fixture and a local patterned HTTP origin. No private media, server or account is required. New prerequisite waits use the shared waitFor; blocking packet consumption runs on an owned thread with cancellation closing the source.

Validation

2026-10-15 conflict resolution: GitHub reported the previous head as conflicting and had created no CI run for it; the earlier green run belonged to 4a5eae0e. After merging official main, the full test/example build and 142 focused checks passed locally (119 Swift Testing tests in 17 suites under the strict one-thread cooperative pool, plus 23 XCTest documentation/API checks). The test bundle used a verified Apple Development signature. Documentation links and diff checks passed. CI passed on 10600a5c: run 38681845346 completed successfully in all four jobs: macOS tests, tvOS/visionOS builds, iOS/release-tool build, and documentation links. Both the regular and strict one-thread Swift Testing runs passed 4,465 tests in 615 suites; packet-cache/runtime regressions and transport-probe builds also passed.

On the 2026-10-14 upstream PR revision (before the main merge):

  • SwiftPM native build, including all test targets and compiled examples: passed.
  • 140 focused checks passed: 118 Swift Testing tests in 17 suites plus 22 XCTest API/documentation checks. The Swift Testing selection ran with LIBDISPATCH_COOPERATIVE_POOL_STRICT=1 and includes the blocking-executor source guard.
  • The test bundle was signed with a valid Apple Development identity and its signature verified before execution.
  • python3 Scripts/check-doc-links.py: passed. git diff --check: passed. Package.swift and Package.resolved are unchanged.

During porting, compilation identified a downstream-only clock helper; the failure path now uses the existing upstream display-origin conversion. The first test run also exposed an unintended #775 dependency in the VC-1 fixture. That fixture now supplies explicit audio durations while preserving the rounded video timing, seven-picture reorder and real discontinuity. All failures were resolved before the successful run above; no production audio-duration behavior was changed.

Reproduce the focused selection with:

LIBDISPATCH_COOPERATIVE_POOL_STRICT=1 swift test --filter 'SoftwareResidentRange|ResidentRangesTests|ResidentSpanTests|Issue613PacketCoverageTests|Issue592CoverageFrontierTests|SoftwarePacketReadAheadParkTests|Issue276RetainedCoverageTests|Issue303SoftwareReadAheadTests|Issue605SoftwareVODStillTests|PublicAPIDocumentationTests|DocumentedConstantsTests|Issue519ReadAheadQoSTests|Issue318CoverageCrossingTests|SoftwareRepositionResultTests|Issue254OffMainRepositionTests|AVIOReaderAbortableWaitTests|DetourOriginTicketTests|BlockingWorkTests'

No full-suite or full-platform CI pass is claimed for this new head.

Downstream integration was separately built, development-signed and installed on Apple TV 4K (3rd generation), tvOS 27.2 beta. Eight distinct backward seeks outside the application packet cache succeeded. Two actual positioning operations took approximately 12 and 10 seconds, exceeding the previous 8-second cap. One total seek took approximately 15.5 seconds including an earlier read wait. Exiting a pending seek released resources in approximately 65 ms, reopening resumed video, and verified coverage remained visible while paused.

These are discrete device-control and diagnostic observations, not continuous audio or physical touch-remote acceptance, and not an installation of this exact upstream branch. Final physical retesting remains pending. Server/cloud cache coldness was not controlled.

The PR includes no media titles, filenames, URLs, screenshots, playback positions, account details, device identifiers or raw session logs.

Review boundaries

The existing public residency type is unchanged. Native AVPlayer late-landing recovery, software live DVR, decoder/audio routing, packet-cache capacity, dependencies and host-app UI are unchanged. Failed software positioning is intentionally surfaced instead of pretending the target was reached. Source failure is not treated as proof of storage corruption or as normal EOF.

Documentation updates explain the residency/error contract and finite positioning budget. The complete CI result above belongs to 10600a5c, including the follow-up and main merge. It does not replace physical device acceptance.

@orut34iop orut34iop changed the title fix(cache): publish retained software VOD resident ranges fix(software): publish retained VOD ranges and honor bounded seek outcomes Oct 14, 2026
@superuser404notfound
superuser404notfound merged commit 20ac6ce into superuser404notfound:main Oct 15, 2026
4 checks passed
superuser404notfound pushed a commit that referenced this pull request Oct 15, 2026
…aimed (#759)

tvOS keeps software VOD packets in purgeable memory, and the store only
learned of a reclaimed history chunk when a restore walked into it. The
ranges #759 publishes therefore kept claiming that history until a seek
proved it gone. The sampler now evicts emptied chunks (a purgeable-state
query per history chunk, under a try-lock so it never waits on the store)
before it copies the floors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged as 20ac6ce, thank you @orut34iop. This is careful work: the per-chunk discard floors, the source-read versus storage split and the stale-result guards all hold up, and the regression coverage made the review straightforward.

The branch no longer merged cleanly, and the push to it was refused, so I merged it from my side. Besides the CHANGELOG and one comment in SoftwarePlaybackHost.load, main had meanwhile moved the packet store behind a SoftwarePacketStore protocol and added an in-memory store, which is what tvOS uses now. retainsConsumedPackets became a protocol requirement in the merge. The in-memory store reports true when its history cap is nonzero. Full suite green after the merge (4881 Swift Testing, 769 XCTest).

One follow-up, c7ac32a: the in-memory store keeps history in purgeable VM. The kernel can empty a history chunk at any time, and until now the store only noticed when a restore walked into it, so the published ranges kept claiming that history until a seek proved it gone. The sampler now evicts emptied chunks before it copies the floors. It runs a purgeable-state query per history chunk under a try-lock, so it never waits on the store. The new test fails without the change.

Two decisions after review:

  • A failed software reposition stays terminal. Continuing at an undefined read position would run the clock at the target with pictures from somewhere else, which is worse than an honest error.
  • The bounded detour bypass stays as it is. I wanted to know whether it also changes the native cue prewarm, which runs under a read deadline on the playback reader too. I ran an A/B on a 2 h Matroska file with Cues at the end, behind a logging origin with 150 ms latency and 3 MB/s, alternating arms over three runs each. Both arms issued the identical request sequence: 4 requests and a 224 to 232 ms prewarm on the native path, 6 to 7 requests on a software session with a cold backward seek. With an index the guard never fires, so it only affects the index-poor containers it was written for.

Not released yet; it goes into the next AetherEngine release.

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.

2 participants