Repository navigation
Description
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
- 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).
- Native AVPlayer HLS-fMP4 path, direct play (remux), play across the video-exhaustion boundary (~1432 s).
- 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.
- 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
edde746 commentedon Aug 3, 2026
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.
So on the bad arm we keep hitting a hard stop ~53 s early. The inconsistency to resolve stays as reported: published
durationsays 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.superuser404notfound commentedon Aug 3, 2026
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:
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.durationand the playlist already agree, so there was no inconsistency there to resolve.Where it actually is
aetherctl playon that fixture reproduced the bad arm deterministically here, in every run rather than 1 in 6:didPlayToEndTimeat 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
.endedlatches.The witness is the seekable range, not the loaded one. At the instant of the premature end AVPlayer has already trimmed
loadedTimeRangesback to the exhaustion point,[22.34, 60.01]against a playhead of 60.03, whileseekableTimeRangesstill 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
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.
superuser404notfound commentedon Aug 3, 2026
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:
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.
edde746 commentedon Aug 3, 2026
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.One caveat on the log line you asked about:
[NativeAVPlayerHost] ... AE#287 premature endgoes 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.
superuser404notfound commentedon Aug 4, 2026
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
aetherctlsources.EngineLog.handleris public and mirrors every info-level line verbatim, soputs
AE#287 premature end: ...(and everything else the engine emits) into stdout wheredevicectl device process launch --consolepicks 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.
fix(native): recovery paths must not read AVPlayer on the main actor (s…
fix(transport): the speed a host set survives the transport's own resume
fix(native): end a timed-out #287 recovery on the playhead it measure…
Merge fix/962-final-video-sample: audio-tailed titles keep their last…
fix(hls): keep the last video sample in its own segment on an audio-t…
fix(native): judge an end by where the clock just was, not where AVPl…
fix(native): bound the superuser404notfound#287 in-place re-seek (AE#…