Skip to content

Loopback path: subtitle cues permanently starve after a backward seek into cache-resident content — the packet store pruned behind the playhead can never re-harvest without a producer restart, and track switches drain the same empty store #125

Closed

Description

@rrgomes

Found while retesting #123 on 5.0.4 (the sourceTime fix itself works — cues stayed glued to the picture through the queued chase; separate confirmation on that issue). This is a distinct defect in the #112-rework overlay feed.

Symptom. During a mixed-direction queued seek storm on a heavy 4K Dolby Vision remux (loopback-HLS native path, ~7080 s asset, embedded PGS + SubRip tracks), subtitle cues stopped rendering entirely partway through and never returned. Cycling the subtitle track (PGS → SubRip → off → PGS) did not recover; each re-arm logged:

15:32:30.807 [AetherEngine] overlay fed by packet-store drainer for stream=5 (backfilled 0 cues)
15:32:42.311 [AetherEngine] overlay fed by packet-store drainer for stream=6 (backfilled 0 cues)
15:32:47.608 [AetherEngine] overlay fed by packet-store drainer for stream=5 (backfilled 0 cues)

The session then sat paused for 13+ minutes in that state; the periodic memprobe showed subTracks=2 subActive=true subCues=0 throughout — a track armed, the store empty, no path back.

Mechanism (from a code read of 5.0.4). The #112 rework feeds the overlay exclusively from SubtitlePacketStore, harvested by the producer's demux pump; there is no side demuxer anymore, and selectSubtitleTrack backfills synchronously from that store. Three properties combine:

  1. Every drainer tick prunes the store behind the playhead: store.prune(before: playhead - 300) (retentionSeconds = 300).
  2. A backward declareTarget into segment-cache-resident content deliberately skips the producer restart — declareTarget backward jump 200 -> 52: resident in cache, no restart — so the region is served entirely from the segment cache and the producer never demuxes it again. Cache hits are the only way the store's writer is bypassed, and the pump is the store's only writer.
  3. The producer meanwhile stays where the forward excursion left it — in our trace backpressure-parked ~600 s ahead of the playhead (#65 backpressure PARK (advance) head=204 target=194 … consumer paused) — so nothing ever re-harvests the watched region.

Sequence in our trace: forward chase to ~795 s (prune cutoff advances to ~495 s, dropping every packet below it) → scrub back to ~213 s lands cache-resident, no restart → drain window around the playhead is empty and can never repopulate → every track re-arm drains the same empty store. The store's eviction comment states the underlying assumption — oldest entries "are already consumed by the drainer, ahead entries cannot be re-fetched" — i.e. a forward-only playhead, which backward seeks into cached content violate.

A second observation from the same trace (may be the same fix, mentioning for completeness): cue application events ceased early in the storm — the last applySubtitleEvent fired at 15:26:46 with the playhead ~97 s, even though the producer went on to demux ~130–800 s continuously over the following minutes (its ledger lines are present throughout), and playback decoded through those regions at rate 1. So delivery had already gone quiet well before the far-backward jump made it unrecoverable; possibly the chase's rapid window jumps ran the drain cursor past regions whose packets arrived slightly later, with the prune then closing behind. Happy to dig further if the primary fix doesn't explain it.

Fix directions, in case they help (you own the design): when a drain plan's window has no stored packets and the producer is not converging on the playhead (cache-resident serve or parked), a bounded one-shot windowed read of the subtitle streams around the playhead would repopulate the store without resurrecting a persistent second demuxer; alternatively, retention by bytes instead of time (the 32 MB/stream cap already exists; a session's full SubRip is ~100 KB, PGS a few tens of MB) would make backward jumps mostly free, with the windowed re-read as the fallback for the cap-evicted case.

Environment: Apple TV 4K 1st gen (2017), tvOS 26.x, AetherEngine 5.0.4, loopback-HLS native path, 4K HEVC DV P7→8.1 remux with FLAC audio, embedded PGS (default) + SubRip tracks. Full session log available as always.

Activity

  1. superuser404notfound commented on Jul 14, 2026

    @superuser404notfound
    Owner

    Great catch, and the triangulation made this a fast fix. Confirmed against a 5.0.4 code read: the overlay is fed only from SubtitlePacketStore, whose single writer is the producer demux pump, and the drainer pruned that store every tick at playhead - retentionSeconds. A backward jump into segment-cache-resident content is served without a producer restart and the pump stays parked forward, so once a forward excursion pushed the prune cutoff past the returned region, its packets were gone and never re-harvested. The drain window landed permanently empty and every re-arm drained an armed-but-empty store, exactly the "backfilled 0 cues" you logged.

    Fix is your direction B. The trailing time-prune is gone; retention is byte-bounded via the existing perStreamByteCap (evict-oldest per stream). Text tracks keep the whole session so backward seeks into them are free; a bitmap track keeps a wide trailing window. This matches how the segment cache retains history for backward seeks instead of clamping to a window ahead of the playhead. A backward seek past a bitmap stream's evicted edge is the windowed-re-read fallback you noted, deferred until it proves to matter, since it reopens the side-demuxer class the #112 rework removed.

    The second observation (delivery going quiet before the far-backward jump) is not addressed directly, but it reads as transient rather than permanent: any seek past the jump threshold rebuilds the drain cursor and re-scans the now-retained store, so only the prune made it stick. Worth watching on the retest.

    Landing in the next release; I will ping here when it is tagged so you can retest with cues paced off sourceTime. After a long mixed-direction storm, a backward seek into an earlier region should re-render cues instead of starving, and cycling the track should recover. Thanks for the full trace and the fix directions.

  2. superuser404notfound commented on Jul 14, 2026

    @superuser404notfound
    Owner

    Shipped in 5.0.5: https://github.com/superuser404notfound/AetherEngine/releases/tag/5.0.5

    Retest whenever you get the chance, with cues paced off sourceTime: after a long mixed-direction storm, a backward seek into an earlier region should re-render cues instead of starving, and cycling the track should recover. The second observation (delivery going quiet before the far-backward jump) should not survive either, since any seek past the jump threshold now rebuilds the drain cursor over a retained store, but if a cue still drops early that is the thread to pull. Full session log welcome if anything turns up.

  3. rrgomes commented on Jul 15, 2026

    @rrgomes
    ContributorAuthor

    Retested on 5.0.5 with the same asset class (4K HEVC Dolby Vision Profile 7, ~2 h, PGS subtitle track active, loopback path on a 2021 Apple TV): the fix holds.

    Procedure: ~4 minutes of linear play to build cache, then a mixed-direction seek storm (±10 s bursts and scrubs both ways), then repeated backward seeks into cache-resident regions — the exact 5.0.4 starvation trigger (declareTarget backward jump … resident in cache, no restart).

    On 5.0.4 any one of those backward jumps emptied the drain window permanently (subActive=true subCues=0), and track re-arms drained the same empty store (backfilled 0 cues ×3). On 5.0.5:

    • cues re-rendered within seconds after every cache-resident backward jump, across a dozen-plus such jumps in one session;
    • subCues stayed populated throughout (5 → 62 over the session, never collapsing to 0);
    • cycling the subtitle track off/on backfilled non-zero every time (backfilled 11 cues, backfilled 13 cues on re-arm).

    No starvation reproduced. From our side #125 is fixed — thanks for the fast turnaround. LoadOptions.autoplay from #124 is next on our adoption list.

  4. superuser404notfound commented on Jul 15, 2026

    @superuser404notfound
    Owner

    Thanks for the thorough retest. Running the exact 5.0.4 trigger procedure (cache build, mixed-direction storm, repeated cache-resident backward jumps) makes this a solid confirmation, and subCues never collapsing to 0 across the session also covers the secondary observation (delivery going quiet before the far-backward jump), so both threads are resolved. Closing as fixed in 5.0.5.

    If anything comes up while adopting LoadOptions.autoplay, #124 is the right thread, or open a new issue. Thanks again for the trace-level reports, they made both fixes fast.

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