Skip to content

fix(demux): align origin-slot completion with playback priority - #746

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
yucelokan:fix/playback-origin-callback-priority
Oct 13, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
yucelokan:fix/playback-origin-callback-priority

Conversation

@yucelokan

@yucelokan yucelokan commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Run byte delivery and origin-slot completion at the same priority as foreground demux work. This addresses a user-initiated reader waiting for a request slot released by a lower-priority URLSession callback.

What changed

  • Give AVIO, held HTTP and prewarm sessions independent serial user-initiated delegate queues; use the same priority for held transport work.
  • Release finite-request tickets in their completion callbacks, before the synchronous reader processes the result, with an idempotent lease for cancellation and early-return races.
  • Preserve per-origin limits, FIFO ordering, pacing and timeout policy; document scheduling and add real callback-priority / ticket-lifetime regressions.
  • Correct the existing cached-segment regression exposed by CI: cache residency does not guarantee a response before a wall-clock threshold. A gated case now proves that the slow notification preserves the cached bytes without restarting production; cancellation releases the gate.

Test plan

  • Device / OS: Apple Silicon Mac, macOS 27.0.1; Xcode 27.0 / Swift 6.4.
  • Source media: bounded loopback HTTP byte fixture (64 bytes); this checks scheduling and request ownership rather than a video codec.
  • Result: Prior PR revision: full swift test --jobs 4 --disable-automatic-resolution passed (764 XCTest cases, one skipped; 4,302 Swift Testing cases reported, with fixture-dependent skips). After the CI test correction, the full Swift Testing suite also passed with LIBDISPATCH_COOPERATIVE_POOL_STRICT=1, including both normal and deliberately delayed cache-hit cases. swift build, doc links and git diff --check passed.
  • Initial upstream CI: all platform builds passed; the existing cacheHitDoesNotSignal assertion failed under parallel load. Its slow-serve timer is armed before the cache lookup, so the assertion incorrectly required the serving thread to finish inside 20 ms. The correction changes only that regression and its documentation; no HLS runtime behavior or timeout is changed.
  • Physical-device integration: the combined downstream fork was used on a real iPhone (iOS 26.6.1) and Apple TV (tvOS 27.0) on 12 October 2026, with live MPEG-TS / H.264 High / AAC-LC stereo / SDR. Five source reconnects completed across the two sessions, without player restarts. This is playback integration evidence, not a claim that every possible QoS inversion is eliminated; the isolated callback-priority regression supplies the direct scheduling check.

Current-main integration, 12 October 2026

Rebased this standalone PR onto upstream main 004eea20 (FFmpegBuild 3.7.1). Its complete macOS package/CLI/example build, documentation links and whitespace checks passed locally; the full-suite figures above describe the previous PR revision. Current-head CI supplies the full tests and platform matrix.

Additional integrated-fork device sessions used Apple TV / tvOS 27.0 and iPad / iOS 26.6.1 concurrently: private MPEG-TS channels, H.264 High Level 4.0 / 1920×1080 / 25 fps / SDR + AAC-LC stereo 48 kHz. Four repeated-source intervals were removed without sampled backward clocks, restarts or software fallback. Video-only gaps exposed an outgoing-PES interleaving edge case; that correction and its diagnostics are kept in #747. These are integrated device results, not isolated trigger coverage for every PR.

Current-head CI: e3f98abe passed all four checks: macOS full/strict-pool tests, iOS Simulator plus release CLI, tvOS/visionOS Simulator, and documentation links.

Checklist

  • CHANGELOG.md updated
  • Commit messages follow Conventional Commits (fix(...))
  • The fix lives in the engine, not in a host-side workaround
  • Public API changes are intentional and documented

Four-device integration follow-up (12 October 2026)

The integrated downstream build containing this PR was exercised on an iPhone/iOS 26.6.1, iPad/iPadOS 26.6.1, Apple TV/tvOS 27.0 and a Mac running the iPad-compatible app/macOS 27.0.1. The sanitized device, media and scenario report covers 8,246 current-build diagnostic records, 27 verified replay removals, live seeking and VOD/PiP use.

The remaining decoded-video boundary defects and recovery correction are in #747; this PR's code and standalone validation remain unchanged. These integration logs are not an isolated physical-device proof of this PR's specific failure path. No private source URLs, credentials or media are included.

@yucelokan
yucelokan force-pushed the fix/playback-origin-callback-priority branch from 5f29bb2 to 72e2fc8 Compare October 11, 2026 23:24
@yucelokan
yucelokan force-pushed the fix/playback-origin-callback-priority branch from 72e2fc8 to e3f98ab Compare October 12, 2026 12:20
@superuser404notfound
superuser404notfound merged commit ea3e4fc into superuser404notfound:main Oct 13, 2026
4 checks passed
superuser404notfound pushed a commit that referenced this pull request Oct 13, 2026
)

#746 moved the 429 accounting into syncRequest's completion callback so
the slot is not handed on before the refusal is on the books, but the
detour still charged the same answer again afterwards. Each charge halves
the origin's concurrency and doubles its quiet period, so one 429 on a
detour block quartered the budget. The detour now only reads the
Retry-After it hands its caller.

The new callbacks also passed an absent Retry-After as 0, which the budget
reads as a zero quiet period instead of the exponential ladder; the old
detour path mapped it to nil. One helper charges the response for all
three finite request paths and keeps that mapping.

The CHANGELOG entry moves under Unreleased: the branch predated the
7.35.0 cut.

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

superuser404notfound commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Merged in ea3e4fc, thank you. Returning the slot from the completion callback is the right shape, and charging the refusal before that return is what keeps the next waiter from walking straight into the same 429.

Two follow-ups landed in b141b14:

  • detourFetchBlock still called noteOriginRefusal after syncRequest returned, so a rate-limited detour block was now charged twice. Each charge halves the origin's limit and doubles its quiet period, so one 429 quartered the budget. A regression test in DetourOriginTicketTests drives a detour against a 429 origin and reads the count off the books (it showed 2 before the fix).
  • The new callbacks passed parseRetryAfter's 0 for a missing header straight to the budget, which arms a zero quiet period instead of the exponential ladder. The old detour path mapped it to nil. One helper now charges the response for all three finite request paths and keeps that mapping.

On the delegate queues: an earlier measurement here (AE#272) found no difference between the implicit queue and .userInitiated under full CPU load. The case this PR describes, a task resumed from a utility-priority thread such as the AE#519 read-ahead producer, is a different setup, and an explicit queue costs nothing, so it stays. The CHANGELOG line also moved under Unreleased, as with #745.

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