Skip to content

AVPlayer path can end a VOD ~53 s early when the selected audio track outruns the video track (boundary race; boundary-exact resume EOFs instantly) #287

Closed

Description

@edde746

What happened?

On an MKV whose selected audio track outruns the video track by ~53 s, end-of-playback is a coin flip. Most sessions play the audio-only tail out to the container duration and finish organically. Occasionally a session fires didReachEnd (AVPlayer didPlayToEndTime) the moment the video track is exhausted — ~53 s early against the engine's own published duration — and any session that the host then rebuilds and resumes at exactly that boundary position EOFs instantly again, so a host retry loop can never escape.

The stream layout (ffprobe, packet-accurate):

stream codec last packet ends
v:0 hevc 1431.971 s
a:0 (selected) aac eng 1484.935 s
a:1 ac3 jpn 1432.032 s
container/duration 1484.936 s

So the engine publishes duration = 1484.9 (demuxer/container), the plan is built to 1484.9, but the VOD cutter advances on video keyframes only, and the advertised EXTINF sum ends near the last video sample (~1432). In the bad arm, playback stops at exactly 1432.000 s with a clean end-of-media; the host's position telemetry (10 s cadence) froze at 1432000 ms and never advanced. In the good arm the same build on the same file plays the tail through 1484.5+ s and ends organically.

Observed distribution so far: 1 bad arm out of ~6 boundary crossings on device — but every session resumed at the boundary position (1432000 ms) after the bad arm reproduced it instantly, which is what turns one race loss into a hard park for hosts with mid-file-EOF protection (ours reloads and retries, then gives up and shows a stream error to the user).

#169's tail-park synthesizer doesn't reach this: it requires the playhead within 0.5 s of duration and loadedEnd >= duration - 0.5, and here the playhead parks 52.9 s short.

Steps to reproduce

  1. MKV with a selected audio stream that runs meaningfully longer than the video stream (here: video ends 1431.97 s, selected AAC ends 1484.94 s; dual-audio BDRip, other audio + subs also end ~1432).
  2. Native AVPlayer HLS-fMP4 path, direct play (remux), play across the video-exhaustion boundary (~1432 s).
  3. Usually: tail plays as audio-only with the last frame held, organic end at 1484.9. Sometimes: clean end-of-media at exactly 1432.000.
  4. Deterministic-ish amplifier: after a bad arm, load + resume at exactly the boundary position (1432000 ms) EOF'd instantly on consecutive rebuilt sessions. Fresh opens at 1431000 or 1440000 ms played the tail fine (5/5), so it seems to need the boundary-exact resume or a race while crossing it at speed.

AetherEngine version or commit SHA

6.5.4 (96ffcab + adaptive pump 7085f416b era pin), exactVersion

Host app

Custom

Platform

iOS

OS version

iOS 26.5.2

Device / chip

iPhone Air (iPhone18,4)

Playback path

Native AVPlayer HLS-fMP4 (VideoToolbox HW decode), direct-play remux, release build

Source media (for playback bugs)

MKV, HEVC Main10 1080p 23.976, selected audio HE-AAC 2.0 (eng), second audio AC3 2.0 (jpn), SRT + 2x ASS text subs with font attachments, ~2.8 Mbps. Container duration 1484.936 s; video ends 1431.971 s; only the selected AAC track spans the full duration.

Error codes / log lines

None in the bad arm - it presents as a clean organic completion at 1432.000 s (didPlayToEndTime), not an error. (No -12889: the #169 window is never entered because the park is 52.9 s from duration.)

Anything else

Two engine-side observations rather than prescriptions:

  • The advertised presentation is internally inconsistent in this shape: published duration (container, 1484.9) vs playlist EXTINF sum (video-anchored, ~1432). Whichever of the two is chosen as truth, agreeing with itself would remove the ambiguity the host currently has to heuristically classify (early organic end vs mid-file stream death).
  • The tail itself does play - audio-only fMP4 segments render fine with the last video frame held, including sessions opened inside the tail. It is only the boundary crossing / boundary-exact resume that sometimes ends the item early.

Happy to run instrumented builds or captures on this rig - same setup as the #286 measurements.

Activity

  1. edde746 commented on Aug 3, 2026

    @edde746
    Author

    Host-side follow-up: we evaluated working around this in the app and decided against shipping any of it, so the engine fix remains the only path that preserves the content.

    • A "recurrence = exhausted content" heuristic (accept the EOF once a rebuilt session stops at the same boundary again) was built and reverted: the tail is demonstrably servable - the same build plays it on most crossings and on any session opened inside the tail (1431 s, 1440 s opens both play to 1484.9) - so the recurring boundary EOF is a serve failure, not content truth, and completing there silently drops the 52.9 s tail.
    • A nudged resume past the boundary was rejected as unverifiable: the bad arm is a race (~1 in 6 boundary crossings on this rig) that we could not summon on demand.

    So on the bad arm we keep hitting a hard stop ~53 s early. The inconsistency to resolve stays as reported: published duration says 1484.9, the video-anchored playlist ends at ~1432, and the audio-only tail only plays if AVPlayer happens to sail past the boundary before the race lands.

  2. superuser404notfound commented on Aug 3, 2026

    @superuser404notfound
    Owner

    Root cause found and fixed on fix/premature-end-of-item-287 (#291). One correction first, because it moves the defect to a different layer.

    The playlist is not video-anchored

    Measured on a synthesized MKV with the same shape (60 s HEVC video, 113 s AAC audio, direct-played through the loopback path), the served VOD playlist is:

    #EXT-X-TARGETDURATION:57
    #EXT-X-PLAYLIST-TYPE:VOD
    #EXTINF:4.004,     (x14)
    ...
    #EXTINF:56.967,
    seg14.mp4
    #EXT-X-ENDLIST
    

    14 x 4.004 + 56.967 = 113.023, which is the container duration to the millisecond. The keyframe planner ends its final segment at sourceDurationSeconds, so the tail lives inside one long final slot whose EXTINF reaches the presentation end rather than the last video sample. duration and the playlist already agree, so there was no inconsistency there to resolve.

    Where it actually is

    aetherctl play on that fixture reproduced the bad arm deterministically here, in every run rather than 1 in 6: didPlayToEndTime at 60.03 s of a 113.02 s item, with the final segment already fetched whole. Rebuilding the fixture with an 8 s tail and with a 2 s tail ended at 60.03 s as well, so the trigger is the video renderer running dry, and nothing about the length of the tail.

    The tail is servable exactly as reported. A single seek back to the same position followed by play() resumes and plays it out to an organic end at 112.97 s with no audio dropped. play() without the seek was measured too: the rate returns to 1.0 and the clock stays frozen at the boundary indefinitely, which is what makes the re-seek load-bearing rather than cosmetic.

    The fix

    The engine no longer forwards an end-of-item event that lands more than a second inside the range AVPlayer itself still reports as seekable. It re-seeks in place and resumes instead, before .ended latches.

    The witness is the seekable range, not the loaded one. At the instant of the premature end AVPlayer has already trimmed loadedTimeRanges back to the exhaustion point, [22.34, 60.01] against a playhead of 60.03, while seekableTimeRanges still reports [0, 113.02]. That is also why the recurrence heuristic was hard to make honest from outside: everything AVPlayer exposes about buffering at that moment agrees with the early end.

    Since this suppresses a terminal event, it is bounded: at most 3 recoveries per item, each must have moved the playhead, live is excluded, and a real serve failure never reaches the path because a segment that never arrives fails the item with failedToPlayToEndTime / -12889 instead. A source that genuinely cannot continue costs one re-seek and then completes exactly as it does today.

    Results

    fixture before after
    53 s tail (dur 113.02) ends 60.03 112.97, organic
    8 s tail (dur 68.02) ends 60.03 67.98, organic
    2 s tail (dur 62.02) ends 60.03 61.98, organic
    equal-length A/V (dur 60.02) 59.97 59.97, path never armed
    resume at the boundary (60.03) 112.97

    One recovery attempt each. 1462 tests in 217 suites green, strict Swift concurrency clean, tvOS and iOS builds green, PR CI green on all three jobs.

    This will ship in the next release, and a retest on the real rig against the 1484.9 s title would be welcome once it is tagged.

    Thanks for the packet-accurate stream table, and for writing up the two host-side workarounds that were built and reverted. The observation that any session opened inside the tail plays through is what made the in-place re-seek the first thing worth measuring.

  3. superuser404notfound commented on Aug 3, 2026

    @superuser404notfound
    Owner

    Released as 6.5.6 (f74dd24). Both consumers are pinned to it.

    A retest on the 1484.9 s title would be welcome, on the crossing as well as on the rebuilt-session-at-1432000 arm. The line to look for is:

    [NativeAVPlayerHost] #<n> AE#287 premature end: playhead=... seekableEnd=... re-seeking in place (attempt 1)
    

    Its absence on a straight crossing means the good arm won the race as before; its presence means the bad arm landed and was recovered. Either way the item should now reach 1484.9.

  4. edde746 commented on Aug 3, 2026

    @edde746
    Author

    Retested on the real rig against the 1484.9 s title, pinned to 6.5.6 (f74dd24), same iPhone Air / iOS 26.5.2 release-build setup as the original report.

    arm runs result
    boundary crossing (open at 1431.0 s, play across 1431.97) 4 4/4 reach ~1484.86, organic end, autoplay next
    boundary-exact resume (open at 1432.000 s - the arm that re-EOF'd instantly on every rebuilt session pre-fix) 2 2/2 play the full tail to ~1484.7, organic end

    One caveat on the log line you asked about: [NativeAVPlayerHost] ... AE#287 premature end goes to os_log, which this rig's harness capture path (devicectl console = stdout/stderr only) cannot see, so I cannot say per-run whether the bad arm landed and was recovered or the good arm simply won. What I can say: pre-fix the identical crossing recipe parked ~1 in 6, and on 6.5.6 all six runs reached the true end. The boundary-exact resume arm was deterministic-bad pre-fix on rebuilt sessions and is deterministic-good now.

    Our native subtitle/driver suites are green against 6.5.6 and both app pins (iOS, tvOS) are bumped. Thanks for the fast turnaround - and for the correction on the playlist shape; the seekable-vs-loaded range split at the exhaustion instant explains exactly why no host-side signal could distinguish this honestly.

  5. superuser404notfound commented on Aug 4, 2026

    @superuser404notfound
    Owner

    Thanks for the retest matrix, and for running both arms rather than just the crossing. 4/4 on the crossing and 2/2 on the boundary-exact resume, on the arm that was deterministic-bad on every rebuilt session before the fix, is the confirmation this needed. Closing as fixed in 6.5.6.

    On the observability caveat: the log line is reachable from a stdout-only capture path, it just was not written down anywhere outside the aetherctl sources. EngineLog.handler is public and mirrors every info-level line verbatim, so

    EngineLog.handler = { print($0) }

    puts AE#287 premature end: ... (and everything else the engine emits) into stdout where devicectl device process launch --console picks it up. It fires from whichever thread emitted the line, so it wants to be thread-safe and non-blocking. Per-segment trace lines are emitted at a verbose level that reaches os_log's debug level only and never the handler, so the mirrored stream stays readable rather than drowning in segment chatter.

    That gap was mine: the handler existed since well before this issue and nothing in the README mentioned it, which is what turned an available signal into an unobservable one on your rig. Fixed in 29d204e, the README now has a Diagnostics section covering both the os_log subsystem and the stdio door. Next time an engine-side witness gets quoted, it should be capturable without asking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions