Skip to content

A live reload with a DVR window should be able to rejoin the pre-reload playhead instead of the edge #442

Closed

Description

@cmcpherson274

What should the engine do?

Give a live session with a DVR window a reload/recovery mode that rejoins the PRE-RELOAD
PLAYHEAD instead of the live edge, so an engine-internal reload does not silently discard
a viewer's behind-live position.

Today every live rejoin path goes to the edge (AetherEngine+Loading.swift — "Live
rejoins at the live edge", both at 6.21.0 and cb3baaf). Measured consequence
(Jellyfin 10.11 raw-TS, dvrWindowSeconds: 1800): a session playing stably 540 s behind
the live edge hit a source stall; the engine's reload machinery recovered — at the edge.
The viewer's place, 9 minutes of deliberate rewind, was gone. The behavior reproduced in
both long sessions that hit a mid-rewind stall (2/2).

The shape we'd want (mirroring what our previous host-owned transport did deliberately):

  • A reload while behindLiveSeconds > threshold with an active DVR window rejoins at the
    tracked playhead, clamped to the REAL retained floor (see the companion
    seekableLiveRange honesty report — the clamp must not aim at window arithmetic).
  • Edge rejoin remains correct when the position was actually evicted, and for live-only
    (no window) sessions — today's behavior, unchanged.
  • Expressible either as a LoadOptions policy (liveReloadRejoin: .playhead | .edge) or
    as reload-scoped behavior whenever dvrWindowSeconds is set — we have no preference.

Without it, any rewind UI on this engine loses the viewer's place on every transient the
reload ladder absorbs — the recoveries working as designed is exactly what makes the
position loss invisible.

Motivating media or use case

Live TV DVR ("live rewind") in a tvOS Jellyfin client: viewer pauses or scrubs back on a
tuner channel, watches behind live, and the upstream hiccups — IPTV/tuner sources
stall routinely. Measured sessions: h264 1080p59.94 + AAC raw MPEG-TS via Jellyfin 10.11
/stream.ts, 29-minute runs, −540 s stable behind-live playback until the stall, then
the un-asked-for snap to edge. Full per-second logs available on request.

Area

Public API surface

Host app / integration context

Custom tvOS Jellyfin client (native AVPlayer loopback route, raw-TS live sessions with
dvrWindowSeconds), measured via the aetherctl harness on macOS 26.5.2 / M4 Max at
6.21.0 (87868c1); rejoin code re-checked at cb3baaf.

Would you be willing to open a PR?

Maybe, with guidance

Activity

  1. superuser404notfound commented on Aug 28, 2026

    @superuser404notfound
    Owner

    Not built, and the reason is worth stating precisely, because "the reload rejoins at the edge" turns out
    to be two different mechanisms with two different answers.

    The recovery that keeps the session is the live reopen ladder
    ([HLSVideoEngine] live reopen attempt N/M). It replaces the reader and the producer underneath a session
    that stays alive: the same HLSVideoEngine, the same segment cache, the same served playlist, the same
    time axis. A behind-live playhead should survive that untouched. If a stall recovered this way and still
    snapped to the edge, that is a defect rather than a missing feature, and I would want those log lines.

    The recovery that does not is the full reload, which calls
    stopInternal(resetDisplayCriteria: false, keepNativeHost: true, ...) and then loadNative again.
    keepNativeHost preserves the AVPlayer, not the DVR content: the HLSVideoEngine and its segment cache
    go with stopInternal, and the new session starts its own time axis at its own beginning. So on that path
    the pre-reload playhead is not discarded as a matter of policy, it stops existing. LiveReloadPolicy
    already says as much, if tersely ("the DVR window restarts at rejoin; a position would be stale"), and
    that is why a liveReloadRejoin: .playhead option would not work as written: there is nothing at that
    position to rejoin, and the number itself is on a dead axis.

    Making it real means retaining the cache and its axis across a session rebuild and re-serving the old
    window ahead of the new content with a seam between them. That is a genuine piece of work rather than a
    flag, and I would rather aim it with a measurement than build it on a guess about which recovery you hit.

    So the question that decides this one: in the two runs where 540 s of rewind was lost, does the log show
    live reopen attempt or reload: stopInternal start? If it is the reopen, there is a bug to fix and the
    position should already have survived. If it is the full reload, the request is real and I will scope the
    cache-retaining version, with your measurement as the case for it.

    Worth noting alongside: clampsLiveResumeIfBehindWindow was a second, independent way to lose a position
    on resume, and #444 now lets the host turn it off. It would not have moved a playhead 540 s behind an
    1800 s window, so it is not the cause here, but on a shorter window it is the first thing I would rule out.

  2. cmcpherson274 commented on Aug 28, 2026

    @cmcpherson274
    Author

    Answer to the deciding question, from the two runs' logs — and it is neither of the two mechanisms you named. Both position losses ran through a third path:

    [AetherEngine] #93 item death (failedToPlayToEndTime) at 214.00s; reloading item through stage-2 recovery (attempt 1, pause guard bypassed)
    [AetherEngine] #65 nudge did not revive the consumer; reloading item at the live edge (rejoin) (same URL, same host)
    

    Run 1 (the −540 s loss): those two lines land at t=776 of the session — the exact tick the playhead snapped 1572 → 2134.8. Run 2: the same pair at t=786. grep -c over both full logs: live reopen attempt = 0, reload: stopInternal start = 0, in every leg of the campaign.

    Context for the #93: the upstream source had frozen ~30 s earlier (edge stopped advancing; the local playlist server had been answering 503 /media.m3u8 reason=blocking reload msn=180 unsatisfiable since the freeze), so the item starved to failedToPlayToEndTime, stage-2 recovery ran, the nudge failed, and the #65 reload chose the edge — and then re-fired every ~39 s against the still-dead source (#65 repeats at t=815, 855, 894…).

    Two observations that may re-frame the scoping:

    1. The #65 line says (same URL, same host) — if that reload keeps the HLSVideoEngine and its cache the way the reopen ladder does, then at the moment it chose the edge the −540 s position still existed in an 1800 s window, which lands this in your "defect rather than missing feature" branch, at a third site (nudge/stage-2) rather than the two you named.
    2. If it instead tears down like the full reload, then the request stands as scoped in your comment, with these logs as the measurement: the loss is real, reproducible (2/2), and arrives through the consumer-death path on a frozen source — which is exactly the moment a viewer parked 9 minutes behind would most want their place kept (the freeze doesn't affect what they're watching; the cache has minutes of runway ahead of their playhead).

    Full logs available — happy to attach both runs.

  3. superuser404notfound commented on Aug 28, 2026

    @superuser404notfound
    Owner

    That answer is the one that decides it, and your reading (1) is right: the third path keeps the session, and the position was still real content when it was thrown away.

    reloadStalledConsumerItem is the whole of that path. It calls host.load(url:startPosition:skipInitialSeek:inPlaceSwap: true) and nothing else: no stopInternal, so HLSVideoEngine, its VideoSegmentProvider, the segment cache and the served playlist all stay exactly as they were. That is why the #65 line says (same URL, same host). At the moment it chose the edge, your minus 540 s was resident content in a cache that had not moved.

    What discarded it was not a teardown but a rule applied too widely. LiveReloadPolicy said "live reload, therefore no start position, therefore skip the initial seek", and it said that for every live reload. The rule was written against a remote Jellyfin stream.ts: the server re-served its transcode backlog, and a pre-readiness seek to zero pointed 60 s behind a live edge AVPlayer was targeting, which parked the item in waitingToPlay forever. On that path zero was the only target available and the position really was on a dead axis. On the in-place path neither is true, and since #441 the session can prove it, because seekableLiveRange is now the intersection of the advertised window and what the cache actually holds.

    So the recovery now asks before it discards. Merged on main in 48d7fbb1:

    • it rejoins at the pre-reload playhead clamped into the resident range, and keeps the edge rejoin wherever nothing can vouch for the position: remote-HLS live, the software live path, and a viewer who was at the edge anyway;
    • the distance that decides is deliberately not the live behindLiveSeconds. A stall inflates that by its own duration, so at the moment a recovery runs it cannot tell a viewer parked in the window from an edge viewer whose picture just froze. The engine now records the distance from the last tick where the clock actually moved;
    • the threshold is the served TARGETDURATION rather than a constant I picked. The edge advances one segment at a time, so a healthy playhead's distance from it oscillates inside exactly that span, and anything past it is a position;
    • the seek is stashed and replayed at readiness rather than handed to load(). The pre-readiness seek is the wedge the old rule existed to avoid, and a live seek converts its target into a distance behind the edge, so the replay lands on the same content whatever axis the fresh item came up on.

    Measured on the harness, same seed and parameters, a viewer 102 s inside an 1800 s window when the source froze:

    before   forward step 100.99s   reloading item at the live edge (rejoin)
    after    forward step   1.10s   reloading item at 61.31s, the place it held
    

    The second-order effect is the one worth having. In the before run the session died again afterwards; a rejoin at the edge of a source that has stopped delivering starves straight back into the ladder it came from. In the after run there was no item death at all, because the playhead stayed where there was still something to play.

    One caveat that matters for your numbers specifically: this restores the place as far as the cache reaches, not as far as the window advertises. If retention was holding less than the full 1800 s, the rejoin lands on the resident floor rather than on minus 540 s, and seekableLiveRange is what says which of those happened.

    Separately, and this is the part your logs reframed for me: I could not get an item death to fire at all while the playhead was parked deep in the window, until I looked at why yours did. A frozen source stalls a behind-live viewer even when every segment ahead of them is already on disk, because the blocking reload holds for 3 x TARGETDURATION before it can answer 503, and AVPlayer issues no segment requests while that is outstanding. Measured: 18.0 s hold, forward buffer 4 s deep, stall guaranteed. That is the step before the one you reported, and it is what turns a source freeze into item death for someone who had nine minutes of runway. Opened as #446 with the reproduction.

    The full logs would help there rather than here, if the offer still stands: what I would want from them is whether your playlist polls show the same multi-second holds before each 503, and whether AVPlayer ever emitted -15410 'Invalid server blocking reload behavior for low latency' and stopped sending _HLS_msn. On my run that error was what restored playback, which is an awkward thing for the 503 to be protecting against.

  4. superuser404notfound commented on Aug 28, 2026

    @superuser404notfound
    Owner

    Released in 6.54.0, along with #446, which came out of trying to rebuild this failure.

    That second one is worth flagging here because it decides how much of the nine minutes is actually usable. I could not get an item death to fire at all while a playhead was parked deep in the window, until I looked at why yours did: with a frozen source, the blocking reload holds for 3 x TARGETDURATION before the 503 is allowed, AVPlayer issues no segment requests while one is outstanding, and the client starves with its whole runway already on disk. Timed off one run, eighteen seconds of hold against a four second forward buffer. That session now withdraws CAN-BLOCK-RELOAD as soon as the source misses its own cadence, so the fetches keep coming from the cache instead of stopping.

    The two together are what the retest is for: the recovery should report reloading item at <position>s, the place it held instead of at the live edge (rejoin), and the outage before it should no longer stall a viewer who is behind live. Worth knowing in advance that the place is restored as far as the cache reaches rather than as far as the window advertises, so seekableLiveRange at the moment of the recovery is the number that says which of those you got.

    One honest limit, in case the retest runs long: once the playlist stops changing altogether, AVPlayer parks anyway and the no-cut watchdog hands the session to the host. Neither change lets a viewer ride out an unbounded outage, they stop the outage from costing a position and a stall it never needed to cost.

  5. cmcpherson274 commented on Aug 28, 2026

    @cmcpherson274
    Author

    Retest done on 6.54.0 — same stack, same deep-seek recipe as the #443 campaign (the fuse lit again, 4/4: production froze at seek+152 s, origin flow stopped ~seek+200 s, dispatcharr teardown behind it — the server half is unchanged and stays our chase).

    The position-discard half: FIXED, in the strongest form. On 6.53.0 the same recipe produced five #93 item deaths and four reloading item at the live edge (rejoin)s, each discarding the −577 s position, until revive budget exhausted, giving up at t≈897. On 6.54.0: zero #93, zero rejoins, zero reloads of any kind — the playhead held its place (rendered 191.09 s at the freeze, still 191.09 s at session end, 14 minutes later, state=playing phase=rebuffering). The the place it held line never fired because nothing ever needed reloading — the recovery that used to destroy the position simply never triggers on this shape now.

    The stall half: the viewer still parks with the runway on disk. After the freeze, playback continued ~37 s (cur 154 → 191) and then stopped; rx= froze at the same instant the origin did, and no segment fetches resumed for the rest of the run — with range=1.45...735.32 advertising ~544 s of cached content ahead of the playhead. Ticks, 60 s samples:

    t=720  cur=178.4  edge=735.3 (frozen)   rx=1246.2MB   playing
    t=780  cur=191.09 edge=735.3            rx=1318.8MB   rebuffering
    t=840  cur=191.09 edge=735.3            rx=1318.8MB   rebuffering   ← and so on to t=1740
    

    Your honest-limit note said AVPlayer parks once the playlist stops changing altogether, and that is exactly what this looks like — but it parks ~37 s in, with its forward buffer spent, not after consuming the disk runway the #446 change was aimed at. If the intent was "fetches keep coming from the cache instead of stopping," on this shape they stop with the playlist. (No the no-cut watchdog handoff line appeared in the CLI run either — the session just sat in rebuffering to the end of the leg.)

    Net from our side: the part a viewer loses forever (their place) is fixed and verified; the part they could in principle still watch (nine minutes of already-downloaded runway during an outage) remains unreachable on this shape. Happy to re-run against anything — this recipe is scripted end to end.

  6. superuser404notfound commented on Aug 28, 2026

    @superuser404notfound
    Owner

    Thank you for the retest, and for reading it the way you did: "the recovery that used to destroy the
    position simply never triggers on this shape now" is the outcome I would have asked for over the one I
    built. Zero reloads beats a reload that keeps its place.

    Two notes on what you saw around it.

    The fuse is expected on 6.54.0. The producer park is #443 round 4, and its fix (c3ee9d52) landed
    after the 6.54.0 tag, so that tag still freezes production at 180 x EXTINF for any window deeper than
    180 segments. Your range=1.45...735.32 at a ~4.08 s cadence is 180 segments exactly. Nothing else to
    chase there; it rides the next tag.

    The stall half is real and now has a cause, which is neither the blocking reload nor anything about
    the runway. I reproduced your shape on the harness and it is AVPlayer's unchanged-playlist watchdog: once
    the source stops cutting, the playlist stops changing in the only dimension AVPlayer reads, it logs
    -12888 on every reload, and after a handful of those it stops polling and stops requesting segments,
    including ones listed in that very playlist and resident on disk. Withdrawing CAN-BLOCK-RELOAD does not
    help because low latency was never the reason: an arm that never advertised it at all stalled the same
    way, having played 78.6 s of a 150.9 s runway.

    Details, the measurement and the fix are on #446, since that is the issue that owns this half. One part
    of it belongs here though, because it is a second way to lose a position that the fix in this issue
    cannot cover: when the playlist finally moves again after such a stall, AVPlayer rejoins at
    edge-minus-HOLD-BACK on its own. Measured on the harness, forward step 117.76 s, with no recovery line
    of ours anywhere near it. So a source outage can still cost a viewer their place, just not through the
    path this issue named.

    Closing this one on your retest. The rest continues on #446.

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