Repository navigation
Description
Split out of #189 (deep-window follow-up by @kskchaitanya1993). The #189 holdback fix itself is verified there (loopback -16832 = 0 across a 2.5 min run with the live window deepened to ~22s, comfortably past the ~18s holdback runway). This issue tracks what remains: the session still cycles through the #168 reroute dance roughly every 13s instead of settling into stable play.
Observed (5.18.5-family, Apple TV 4K 3rd gen, tvOS 26.5)
HEVC-in-MPEG-TS live channel, test-bed loops a fixed segment pool and injects a real [DISCONTINUITY] each lap. Over 2.5 min: 8 #168 reroutes, 0 host ladder re-tunes, playback never leaves the engine, it just loops:
#9 load 192.168.x/hevc-hdr/master.m3u8 -> readyToPlay -> playing (native, audio-only)
#9 master advertises video but AVPlayer built no video track after grace
#168 reroute -> #10 load 127.0.0.1/media.m3u8 (loopback)
live seg-0 ... seg-1 [DISCONTINUITY] ... seg-2 ... seg-3
#11 load 192.168.x/hevc-hdr/master.m3u8 <- origin master again, native bypass
#11 built no video track -> #168 reroute -> #12 loopback -> repeat
Root cause: two engine-side defects composing into a loop
Defect A: the #168 verdict is not remembered. The video-carriage watchdog (RemoteHLSIngestFallback.Watchdog) discovers "this master advertises video but AVPlayer will never build a video track for its MPEG-TS carriage" at runtime, at the cost of a full native mount, readyToPlay, and the 8-tick (~4s) grace. The verdict is then thrown away. Every subsequent load() of the same URL with nativeRemoteHLS re-mounts the doomed native bypass and re-pays the whole discovery cost. Nothing in the engine records that this master is a known reroute case.
Defect B: the rerouted ingest session has no in-engine recovery. rerouteRemoteHLSOntoLiveIngest loads the loopback session as .custom(HLSLiveIngestReader), so HLSVideoEngine gets sourceReopenableByURL: false (AetherEngine+Loading.swift, session construction). That flag routes every live pump exit (eof, readError, keyframeStarvation) straight past the URL-reopen machinery into onLiveSourceReset ("URL reopen not possible, requesting host retune", HLSVideoEngine+LiveReopen.swift). The ingest reader itself is also designed to go terminal rather than recover: 6 consecutive empty playlist refreshes throw HLSIngestError.ingestStalled (HLSLiveIngestReader.swift), a contract written for phase-1 direct-live where the host had chosen the path itself and owns a fallback ladder. For a #168-rerouted session that contract is wrong twice over: the reader was created by the engine from a URL plus headers and is trivially reconstructible in-engine, and the host never opted into the loopback path in the first place.
How the loop closes. The engine publishes liveSourceReset; a host that answers a live-source reset by re-tuning the same channel URL (a perfectly reasonable response) lands back on the native bypass, which is deterministically doomed for this master (Defect A), which reroutes again (#168), which builds a fresh ingest session that dies the same way (Defect B). Note the #N load <origin> mounts are NativeAVPlayerHost session logs executing that host retune; no engine path reloads the origin URL on its own. So every layer behaves as designed and the composition still loops, with roughly 5s of black/audio-only per lap burned on re-discovering a known verdict.
Why this matters beyond the test-bed
The looped fixed pool is what triggers the ingest death here, but real origins hit the same terminal funnel: ad-boundary and program-transition discontinuities, encoder restarts, and any CDN hiccup that outlives the reader's ~12s refresh-retry deadline. On a rerouted session, each of those today costs a full native-remount dance instead of an in-session recovery.
Proposed fix (two layers)
- Reroute verdict memory. Cache master URLs whose video-carriage watchdog fired (bounded, process-scoped, expiring so an origin that fixes its packaging is not permanently exiled).
load()withnativeRemoteHLSconsults the cache and routes a known reroute case directly onto the live-ingest loopback path, skipping the doomed mount and the ~4s grace entirely. This alone collapses the cycle cost and makes any host retune reland on the working path immediately. - Bounded in-engine revive for engine-created ingest sessions. When the custom reader is the engine's own
HLSLiveIngestReader, aneof/readError/terminal-stall pump exit should first attempt a bounded fresh-reader revive inside the session (rebuild the reader from URL plus headers, rejoin at the live edge, seam carriesEXT-X-DISCONTINUITY), mirroring the URL-reopen machinery and the AE#169 bounded-revive pattern. Only an exhausted budget delegates toliveSourceReset.
Evidence wanted to pin the exact terminal trigger
@kskchaitanya1993 offered the raw log around a few cycles in #189, and this is where it pays off: the decisive window is between the loopback mount (#10 load 127.0.0.1/...) and the next origin mount (#11 load 192.168.x/...). The lines that discriminate the candidates:
[HLSIngest] terminal: ...(whichHLSIngestError, e.g.ingestStalledwould implicate the pool wrap resettingMEDIA-SEQUENCEand starving the playlist tracker)[HLSVideoEngine] live custom-source pump exited (reason=...); URL reopen not possible, requesting host retune[HLSVideoEngine] live source replayed from start after reconnect; requesting host retune[AetherEngine] onLiveSourceReset -> publishing liveSourceReset to host
Also useful: confirmation of how the host app answers liveSourceReset (re-tune same URL?), which would complete the loop mechanism end to end. The fix targets the whole class either way; the exact trigger determines which revive path Layer 2 must cover first and what the regression test encodes.
Activity
kskchaitanya1993 commentedon Jul 22, 2026
Raw evidence from the deep-window run (5.18.5-family, ATV 4K 3rd gen, tvOS 26.5), and a clear answer to the host-retune question — which I think tightens the diagnosis.
One cycle (origin host redacted; ~13s period, repeated 8×):
On your "how does the host answer
liveSourceReset(re-tune same URL)?" — it doesn't, and I verified this two ways:liveSourceResethandler at all — grepping the whole tvOS app forliveSourceReset/onLiveSourceReset/onSourceReset/onReopen/reset/retune handlers returns nothing. We subscribe to the engine's phase/duration/format/timeControl publishers only; there is no reset/reopen sink.AETHER post-play error= 0,AETHER stall/reconnect= 0,reloadFromScratch= 0,ladder: rung= 0, host-ingest = 0. Our only same-URL reload (reloadFromScratch) never fired.So the
#154/#155origin remounts are the engine's ownNativeAVPlayerHostre-mounting the source with the engine's stored header (headers=1), with no host action in between. From this host's vantage the reload-to-origin is engine-internal — which I think strengthens the case for your Layer-2 (bounded in-engine revive): there's no host retune to suppress here, so only in-session recovery can break the loop.On the exact terminal trigger: the discriminating lines you listed —
[HLSVideoEngine] … pump exited (reason=…),… replayed from start after reconnect,[AetherEngine] onLiveSourceReset → publishing liveSourceReset,[HLSIngest] terminal: …— are not present in what I capture. My ring only gets the engine'sav_log-routed component lines ([NativeAVPlayerHost],[HLSVideoEngine],[AetherEngine],[HLSSegmentProducer]); those reset/pump-exit lines appear to log below that. The one exit reason I do see is the loopbackHLSSegmentProducerfinishingreason=stopRequested— i.e. the producer is torn down by the remount, so it reads as a consequence, not the trigger. If you want the exactpump exited/onLiveSourceResetreasons I can raise my capture level (or grab an on-devicesysdiagnoseos_log slice) and post the window around 2-3 cycles — just say which.Test-bed caveat, to be straight: the per-lap
[DISCONTINUITY]is a looped-pool artifact, but per your trace the underlying defects (verdict-not-remembered + no in-engine revive on any pump exit) would bite a real source on anyeof/readErrorblip too, so it isn't purely synthetic. VLC plays this same HEVC-in-TS channel fine, for what it's worth.This comment was drafted and posted automatically by Claude, working on behalf of @kskchaitanya1993.
fix(live): recover rerouted ingest sessions in-engine and remember the …
superuser404notfound commentedon Jul 23, 2026
Fixed in 5.20.0 (PR #200), along the exact two-defect line above, plus a third layer at the source once the likely trigger became clear from your segment log:
ingestStalledafter 6 stalls, which is what tore the session down. Three consecutive whole-window regressions now rejoin at the new edge under anEXT-X-DISCONTINUITYseam and playback just continues. Isolated stale-CDN-edge windows do not trip it.load()of the same URL routes directly onto the live-ingest loopback: no native remount, no ~4 s grace, no origin-side-16832window. A host retune after an ingest death relands on the working path immediately.eoffrom an upstream ENDLIST,readErrorfrom a CDN gap past the retry budget), the pump exit now rebuilds a fresh reader through the existing bounded live-reopen machinery (continuation indices, discontinuity seam) instead of requesting a host retune. Only an exhausted budget surfacesliveSourceReset, as the last resort it always should have been.On the "purely engine-side" puzzle from your trace: no engine path reloads the origin on its own, so the
#11 load <origin>mounts were the engine executing a retune issued host-side, most plausibly a handler answering the engine'sliveSourceResetrequest by re-tuning the same URL (a perfectly reasonable response, and not the bug). With 5.20.0 that request only fires after the in-engine budget is exhausted, and even then it relands on the loopback via layer 2.Could you rerun the deterministic HEVC-in-TS channel (deep window, same 2.5 min horizon) on 5.20.0? Expected signals:
#168reroute at the first open, then no further origin master mounts for the rest of the run.[HLSVideoEngine] live reopen succeeded on attempt Nline (layer 3), but no[HLSIngest] terminal:and no newloadmounts.[AetherEngine] #199: master is a remembered no-video-track carriage case; routing directly onto the live-ingest loopback path, and consequently no pre-reroute origin-16832grace at all.If anything in that run still cycles, the raw log around one cycle is exactly the right artifact, same offer as before. Verification basis on this side: new
Issue199RerouteRecoveryTestsplus tracker/halt suite extensions (all watched failing first), full suite green (965 tests), strict-concurrency and tvOS Simulator builds clean, CI green on PR #200.kskchaitanya1993 commentedon Aug 3, 2026
Apologies for the very long gap — you asked for this rerun on 2026-07-23 and I'm only bringing it back now.
The cycle is gone. Retested on 6.5.5 rather than 5.20.0, since we're well past it now; same deterministic HEVC-in-TS channel, same looped fixed pool with a real
[DISCONTINUITY]each lap, same ~2.5 min horizon, Apple TV 4K 3rd gen.I ran it twice, because our host changed in a way that otherwise makes our numbers useless to you.
Run A — our shipping configuration
Our host now probes the master itself and routes a known HEVC-in-TS channel straight onto the ingest path, so the engine's native bypass is never mounted:
Picture at t+7.0s, then stable for the rest of the run: one self-healed 5.2s stall at the join and nothing after it, forward buffer settling at ~60s, edge margin oscillating within about ±1s. This run says nothing about your three layers — it never reaches the path they live on. Reporting it only so the configuration difference is on the record.
Run B — native-first restored, which is what you actually asked about
We kept a debug lever that restores the pre-probe behaviour, so the engine's own discovery runs:
Totals over the window:
Signal 1 confirmed: exactly one
#168at the first open and no further origin master mounts for the rest of the run. Previously this was 8 reroutes over 2.5 min with an origin remount every ~13s.Signal 2 confirmed, via the silent branch: each pool lap passes with no
[HLSIngest] terminal:, no new mounts, and nolive reopen succeededline either — so layer 1 is absorbing the MEDIA-SEQUENCE reset at the tracker and layer 3 never has to engage. Your read that the looped pool resets MEDIA-SEQUENCE each lap looks right.Signal 3 not observed, and I don't think this run can observe it. No
#199: master is a remembered no-video-track carriage caseline appeared. The verdict memory is process-scoped, and our harness relaunches the app per tune, so there is never a secondload()of the same URL inside one process for the cache to be consulted on. That's a limitation of how we drive the device, not evidence against layer 2 — I'd need a harness that re-tunes within a session to exercise it, which we don't have today. Say the word if it's worth building; otherwise layers 1 and 3 are the ones this run speaks to.One correction to the record while I'm here: in my July comment I said the origin remounts could not be host-issued because we have no
liveSourceResethandler. That was accurate about our code and I'd still stand behind the grep, but it was answering the question with our old host. With the master probe in place we no longer take that path at all, so if you were relying on that data point to reason about who issued the remount, it only describes the configuration as it was then.This comment was drafted and posted automatically by Claude, working on behalf of @kskchaitanya1993.
superuser404notfound commentedon Aug 3, 2026
Thanks for coming back to this, and for running it twice. Splitting the shipping configuration from the restored native-first path is exactly the right way to report it: Run A on its own would have looked like a pass while never touching the code in question, and labelling it as such saved a wrong conclusion.
Closing on Run B. What that run establishes, as I read it:
[HLSIngest] terminal:, no new mounts and no reopen line, which is the tracker absorbing the axis reset instead of starving intoingestStalled. The cycle that used to feed on it is gone: 1 reroute at the first open and 0 origin remounts, against 8 reroutes with a remount every ~13 s before.load()of the same URL for it to be consulted on. No need to build a re-tune harness for it. The logic has unit coverage, and Live HLS carriage is learned only after a full native mount plus the 4 s watchdog grace; probe it alongside the mount #293 below makes it the secondary path anyway.The July grep needs no correction either. It described that host as it was, which is all it ever claimed.
The most useful part of this report is Run A. A host having to probe the master itself to route a known HEVC-in-TS channel onto the ingest is work the engine should be doing. It already owns a stronger version of that evidence (#268 classifies this carriage from the playlist plus the first segment's PMT, no AVPlayer involved) and simply gates it to finite VOD, so live keeps paying a mount plus the 4 s watchdog grace to rediscover it. That is also most of the gap to the t+9.0 s first video frame in Run B. Filed as #293: probe the carriage concurrently with the native mount and reroute the moment the PMT says HEVC-in-TS, so the first open in any process behaves like a remembered one and no host needs a probe of its own. It closes a second hole in passing, a live media playlist URL with no master has no variant evidence, so today the watchdog cannot judge it at all.
For the record on the remaining latency: Run A shows a 5.2 s self-healed stall at the join with no reroute anywhere near it, so the ingest join, not the reroute, is what is left to look at. Tracked separately from #293.
feat(live): the carriage verdict is read from the source, not waited out
feat(engine): publish the effective video route (#321) (#333)
fix(video): escalate live reopen exhaustion for URL sources too
Merge pull request #343 from tschuegy/fix/live-reopen-exhaustion-halt
fix(video): one method owns the reopen-exhaustion escalation, and it …
docs(readme): the retune answer a fixed-URL host gives
fix(engine): a cancelled software-path rebuild ends with its nested r…