Skip to content

A session-preserving reload that can change one LoadOption (reload(withOptions:) or per-setting setters) #460

Closed

Description

@cmcpherson274

Closed-source tvOS Jellyfin client, pinned 6.60.0 (771d8592). AetherEngine is the shipped engine for VOD, live TV and the guide's picture-in-guide. TVVLCKit — the last engine we could hand a struggling session to mid-flight — is being removed this cycle. What remains beside AetherEngine is an AVPlayer rung (our HLS/fallback leg, multiview tiles) and Jellyfin's server-side transcode; both are demote destinations reached by tearing the session down and starting the item over, and for two of the three cases below AVPlayer rides the same VideoToolbox decoder and the same audio-compat set, so it is not an alternative decoder either. Every one of those answers costs the viewer a visible restart. These are three places where an IN-PLACE answer would have to come from your API.

What exists. reloadAtCurrentPosition() (AetherEngine.swift:4047) is the one session-
preserving rebuild a host can request that is not tied to a specific selection — your docs name
four (docs/api.md:104: an audio-track switch, a subtitle-track switch, a disc-title switch, and
reloadAtCurrentPosition()), and none of them can change a LoadOption. On the URL branch it
replays the session's own options verbatim and mutates exactly two internal fields:

var options = loadedOptions
options.isLiveRejoin = options.isLive
options.subtitleSessionCarryover = carryover

(AetherEngine.swift:4092-4094; the custom-source branch takes its own path, so a
reload-with-options would want both). loadedOptions is private(set) (:1554), and the only
public write of a whole LoadOptions is a fresh load(source:options:) (:2973). The one shipped
per-setting exception is #364's setTeletextPage(_:) (AetherEngine+TeletextPage.swift:26 →
setLoadedTeletextPage, AetherEngine.swift:1562 — documented at :1558 as "the one narrow write
into loadedOptions outside a load", so the change survives the internal reopens that replay
these options; CHANGELOG.md:2199-2200 says the same). That is exactly the contract this ask
generalises.

What the alternative costs, honestly. A host correcting a session today does a fresh load()
with the option changed. That is not cheap-but-equivalent, but not for the reason one would
first guess: reloadAtCurrentPosition() is itself a from-scratch load()
(SubtitleSessionCarryover.swift:4-5 says so), so both pay the same teardown, both keep the native
host where the load can, both re-fetch and re-parse the subtitle track on the way back, and the
audio pick rides load(audioSourceStreamIndex:) on either path (:2977 — no post-load restart).
What a host-issued load() cannot reproduce is the two engine-internal fields the reload sets:
subtitleSessionCarryover and isLiveRejoin (PlayerState.swift:497/:490 — "Not settable from
the public initializer"). Without them the id-exact external-subtitle registry, mid-session
addExternalSubtitleTrack registrations and the host's explicit subtitle authority (including
subtitles explicitly OFF) are wiped and re-derived by auto-selection, and a live reload loses
the skip-the-initial-seek rejoin contract. We take the fresh load today (our recovery primitive
tries reloadAtCurrentPosition() first and falls through to a fresh install when it no-ops or
throws — App/AetherPlayerEngine.swift:1247), so nothing is blocked; every option-changing
correction simply pays those two losses plus the visible black gap.

Why the shape is already yours. The engine changes its own mind about options mid-startup
without restarting the wait: the AE#268 HEVC-in-TS reroute copies the options, flips one, calls
continueStartupAcrossReroute() (:1466) and re-enters load(); :3951 is the same move for
AE#246 ("#361, same wait, different route"). And three public APIs already are per-setting
mutators riding a session-preserving rebuild — selectAudioTrack(index:) (:5354),
selectTitle(id:) (:5396), setTeletextPage(_:) — so the per-setting spelling is not
hypothetical.

The ask. A public reload(withOptions:) — or reloadAtCurrentPosition(applying: (inout LoadOptions) -> Void), or per-setting setters in the setTeletextPage(_:) style if you
would rather keep the struct otherwise closed to generic writes — carrying the same
session-preserving contract, with the changed option installed into loadedOptions so the
internal reopens that follow replay it. Not every field: isLive, audioOnly and the
custom-source shape are load identity; the fields a correction wants are the routing and
decoding levers. This is the mechanism the next two asks compose with.

Filed as groundwork for the removal of our second engine (three related asks, filed separately so each can move on its own).

Activity

  1. superuser404notfound commented on Sep 2, 2026

    @superuser404notfound
    Owner

    Shipped in 6.63.0. Thank you for the write-up: pricing the alternative honestly, rather than asserting it was blocked, is what made this straightforward to design, and the observation that the cost is the two engine-internal fields and not the teardown is exactly right.

    public func reloadAtCurrentPosition(applying change: (inout LoadOptions) -> Void) async throws

    Of the three spellings offered I took the closure, and against reload(withOptions:) for a specific reason rather than taste: the engine rewrites its own routing fields mid-session (nativeRemoteHLS on the #154 / #168 reroute, audioOnly when the probe finds no video). A host handing back its own load-time struct would be refused for a field it never touched. Seeding the closure from the session avoids that, and it doubles as the read API for what the session is actually running on, which loadedOptions never had.

    The line I drew, and why it is not every field. isLive, audioOnly, nativeRemoteHLS and sequentialOrigin are refused by name through AetherEngineError.loadIdentityNotCorrectable(fields:). That is the set named in the request plus nativeRemoteHLS, which belongs there for the reroute reason above. Everything else is correctable. Two properties that matter for a ladder:

    • Both refusals (that one and sessionNotReloadable) are raised before any teardown, so a refused correction leaves the session playing untouched.
    • Both are all-or-nothing. A correction refused for one field installs none of the others that rode along in the same closure.

    On the no-op. reloadAtCurrentPosition() keeps its silent return, since three consumers pin that contract, but the new overload throws sessionNotReloadable instead, with .noActiveSession and .customSourceNotSeekable distinguished. sessionReloadRefusal is also public and answers the same question about either reload without attempting one, so the fall-through in a recovery primitive no longer has to be reached by timing a rebuild out.

    One correction to the read. The custom-source branch does not need subtitleSessionCarryover or isLiveRejoin added: it reaches both by other means. reloadWithAudioOverride passes liveRejoin: loadedOptions.isLive into loadNative, and it carries its own subtitle state across stopInternal (the active track through the external registry, the sidecar or embedded stream, the reapply ordinal, and the visible bitmap cues so a PGS line stays up through the rebuild). Different mechanism, same guarantee.

    What that branch does differ on is coverage, and it is documented rather than left to be discovered: it replays loadedOptions field by field instead of passing a struct through load, so the routing, probe-budget, live-join, deinterlace and subtitle-preparation fields apply there, while the four load itself consumes (preferredAudioLanguages, externalSubtitles, maxConcurrentSourceRequests, autoplay) are installed and take effect at the next load. On a URL source every field applies.

    Verified against real media, with a header-logging origin on the far end so the correction is read from outside the engine rather than from its own log:

    REQ t=120.59 auth=stale   range=bytes=0-33554431
    REQ t=128.84 auth=stale   range=bytes=17579980-50348495
    HOSTCALL reloadAtCurrentPosition(applying: httpHeaders[X-Auth]) at +10000 ms (t=9.90s)
    REQ t=130.79 auth=fresh   range=bytes=0-33554431
    REQ t=130.87 auth=fresh   range=bytes=17334168-50348495
      #460 correction applied, session resumed at 10.90s from 9.90s (state=playing)
    

    Buffer went 56 s to 60 s across the rebuild, no rebuffer. The refusal arm (is-live=true) printed the refusal and the session played on without a tick. Both are drivable from aetherctl play --reload-applying <key>=<value> --reload-applying-at <ms> if it helps to see the shape before wiring it.

    Docs in docs/api.md under "Correcting a LoadOption without restarting the item". Leaving this open until it has been tried on your stack. #461 and #462 are next.

  2. cmcpherson274 commented on Sep 2, 2026

    @cmcpherson274
    Author

    Tried on our stack at 6.65.0 (50a2d3ee, pinned this morning), and it does what the ask wanted — plus one thing we learned about our own spool by reading the branch it would take.

    What we wired. One wrapper primitive over reloadAtCurrentPosition(applying:) with the guards in this order: no session / our live-rewind spool arm / a load already in flight / sessionReloadRefusal. The catch is typed: loadIdentityNotCorrectable and sessionNotReloadable keep the session (they are raised before any teardown, exactly as documented), so the session is still playing in every false case except a real load throw, and the caller decides whether a fresh install is worth it. Two shipped consumers today: the #461 decode-path escape (reported there), and the audio-route-death recovery — when the AVR goes away mid-play the session-preserving reload would replay the bridge mode chosen for the AVR onto whatever route survives (read off the reload's own option replay; we have no route-death leg on this bench), so it now corrects audioBridgeMode against the route the app is on before reloading. sessionReloadRefusal also replaced our post-await "did the reload do anything" sniff in the recovery ladder as the up-front answer (we kept the sniff for the non-throwing reload-failed exit).

    Measured (simulator, app log, 2026-09-02). The three sim legs are fired by our JF_AETHER_RELOAD_APPLY DEBUG rig through the real primitive:

    refusal leg  (a VOD session, correction {$0.isLive = true} at +20 s)
    09-02 08:58:48.125  [AetherEngine] #460: correction refused, load identity is not correctable: isLive
    09-02 08:58:48.125  [Aether] option correction refused (load identity is not correctable: isLive) — session kept (JF_AETHER_RELOAD_APPLY is-live=true)
      → no install, no reload after it; the clock kept ticking (the "before any teardown" contract, from outside the engine)
    
    correction leg  (TrueHD source, {$0.audioBridgeMode = .lossless} at +20 s)
    09-02 08:59:33.531  [AetherEngine] #460: reload applying audioBridgeMode
    09-02 08:59:35.147  [AetherEngine] AE#462: audio delivery = decoded          (re-derived after the rebuild — expected)
    09-02 08:59:35.147  [Aether] option correction done (JF_AETHER_RELOAD_APPLY audio-bridge=lossless) — subtitle session + audio pick carried by the engine   (1.6 s)
    
    composition with #461  ({$0.preferredDecodePath = .software} on a session already on software)
    09-02 09:00:18.850  [AetherEngine] #460: reload applying preferredDecodePath
    09-02 09:00:18.926  [AetherEngine] #461: host asked for the software path; the routing had already chosen it
    

    And on hardware (Apple TV 4K 3rd gen) the same composition on a NATIVE session is the #461 report's headline — a native session became a software session at its own playhead in 117 ms.

    The thing worth knowing about the custom-source branch — read, not measured. Our live arm feeds the engine through a custom IOReader over the app's own tuner pull (a rewind spool). That reader answers seek(0, SEEK_SET) successfully (it re-bases to its join offset), so customSourceIsSeekable is true and sessionReloadRefusal returns nil for it: the engine would accept the correction and rebuild on the retained reader, which on our arm would rewind the spool to its join offset with stale join arithmetic. We have not measured that — our spool guard fires first — it is read off CustomIOReaderBridge.open() and AetherEngine.swift:4156-4158 at 50a2d3ee. Not a bug in #460 (the contract says exactly what it does); it is why the spool guard lives inside the primitive rather than at call sites, and it is stated here in case another host with a re-basing reader reads the refusal as a safety net.

    Not consumed, and why. The auth-refresh demo is a non-case for us: Jellyfin stream URLs carry the token as a query parameter, not a header, and the app never mints a token mid-play — so a corrected header cannot reach our origin and there is nothing to correct with. No complaint; the primitive is the right shape regardless.

    The custom-source preferredDecodePath note is in the #461 report. Thank you for the closure spelling — seeding it from the session's current options let us mutate one named field without carrying load-time routing values back; our corrections named only the field they changed.

  3. superuser404notfound commented on Sep 3, 2026

    @superuser404notfound
    Owner

    Thank you for the confirmation, and more so for the paragraph about the custom-source branch. That was filed as a read rather than a measurement, and explicitly not as a bug in #460, so it would have been easy to file away. I put it on the harness instead. The read was right about the mechanism and understated the result, and two further defects were sitting underneath it.

    aetherctl customio --live gained a --reload-at S arm that fires reloadAtCurrentPosition(applying:) on the paced live spool through the real primitive (the correction it applies is httpHeaders, inert on a custom source on purpose: the subject is the rebuild, not the field).

    What the rewind actually costs. Sixty seconds into a live session, playhead at 41.5 s:

    RELOAD: playhead 41.52s -> 1.90s, reader cursor 15.0 -> 15.5 MB
      srcMB 15.0 -> 30.0 in one tick
    LOOKBACK: deepest reach-back 15.0 MB behind the live edge (61 s of source at this rate)
    

    The playhead going back was the expected half. The srcMB line is the one worth having: the reader delivered its whole window a second time, at I/O speed, because the rebuild re-read the spool from the base. On a session that has been running an hour that is the whole hour, and it is the host's tuner pull that pays for it.

    Cause, and it is not where either of us was looking. CustomIOReaderBridge.open() did answer the seekability question with a SEEK_SET 0, but that is not what re-based the reader. A fresh AVIOContext starts its byte axis at 0 no matter where the reader is, so libavformat reads the source from the beginning whether or not the probe moved anything. The reader's cursor and that axis have to be made to agree, and there are two ways to do it:

    • VOD rewinds the reader to 0. Load-bearing rather than incidental: the reopen has to re-read the container header, and the backend seeks to the resume position afterwards. Removing the rewind broke customio --reload on an mp4 at LOAD, which is how I found out it was doing real work.
    • Live now leaves the reader alone and moves the axis to the cursor instead. Same invariant from the other end, and the only one that is right for a source that has kept receiving. It also makes the rebuild the edge rejoin LiveReloadPolicy already performs on the URL branch, rather than a third behaviour nobody chose.
    [Demuxer] live reopen aligned to the reader's cursor at 15728640 bytes
    LOOKBACK: deepest reach-back 0.0 MB behind the live edge (0 s of source at this rate)
    

    Reach-back is the number to read, not the playhead: a live rejoin restarts the session-relative clock at 0 the way an initial join does, on this branch as on the URL one. Where the rebuild comes back is decided by the reader's cursor, so a viewer parked inside the window comes back inside the window, and one at the edge comes back at the edge. A reader that will not answer seek(0, SEEK_CUR) cannot be aligned to and is rewound as before, with a log line saying so instead of doing it silently.

    Two defects underneath, both of which are worth checking against your adapter.

    CustomIOReaderBridge.markClosed() forwards to IOReader.cancel() and was not idempotent. The torn-down bridge's own close() fired a second cancel a moment later, by which point the engine had already handed the same reader to the successor bridge, so that cancel landed in the REBUILT pump's read. On a live source that read is parked at the edge, so it came back -1 and the session died right after reporting itself playing:

    [AetherEngine] reload: state=.playing total=75ms
    [HLSVideoEngine] live custom-source pump exited (reason=readError(-1)); no in-engine reopen transport, requesting host retune
    [NativeAVPlayerHost] #2 item.status=failed err=AVFoundationErrorDomain/-11866 'Playback Stopped'
    

    Intermittent, and invisible on every VOD-shaped reader: those answer from a backlog and are almost never parked when the second cancel arrives. One cancel is all that was ever needed, since after the first no read reaches the host at all.

    That leads to the other one. cancel() is specified as "unblock only, do not invalidate" for a reader the engine may reload, because the rebuild reuses it. That requirement lived in one subordinate clause of a doc comment, which is not where a contract belongs when getting it wrong costs a session, so it now has a section in docs/formats.md alongside where a live reopen starts. The harness carries a deliberately non-conforming arm (--cancel-latches) that reads cancel as terminal the way a socket's in-flight-request cancel is terminal, and on that arm the reopen dies on stream info with libavformat's Operation not permitted. If the tuner adapter latches, the rebuild cannot work, and that is worth a look before the decode-path escape rides this on a live session.

    And #460's own contract had a hole in the same corner. The custom-source branch published its failure and returned as if the session had come back, so reloadAtCurrentPosition(applying:) reported a correction it had not made while the session sat in .error, which is precisely the distinction the throwing overload exists for. It throws what the rebuild threw now, the way the URL branch always has. A rebuild superseded by a newer load or stop still returns normally, since that is not a failure.

    What this changes on your side: the spool guard inside the primitive is no longer protecting against a rewind on a released build, once this ships. Worth keeping it until then, and worth keeping it in any case if the reader does not report SEEK_CUR. The reopen re-probes the container from a mid-stream byte offset, which MPEG-TS resyncs through within a GOP; a container that cannot be joined mid-stream would want the old rewind, and none of the live shapes here are that.

    6626b1f7 on fix/ae460-live-custom-reopen, not released yet. Leaving this open until it is.

  4. superuser404notfound commented on Sep 3, 2026

    @superuser404notfound
    Owner

    The three follow-ups from the custom-source read (6626b1f7: a live custom source rebuilt where the session left it, one cancel per reader, and a failed rebuild that throws instead of reporting success) are released in 6.67.0.

  5. cmcpherson274 commented on Sep 12, 2026

    @cmcpherson274
    Author

    Tried against our stack at the 6.81.0 pin (c7e7adb5, taken this morning): both adapter questions answered from our code, plus one finding of ours that changes why our spool guard stays.

    (a) Our cancel() does not latch

    AetherSpoolReader (App/AetherPlayerEngine.swift):

    func cancel() { (stream as? SpoolInputStream)?.wake() ?? stream.close() }

    wake() broadcasts on the spool ring's condition and changes no state; close() remains our one invalidation. The ?? stream.close() arm is dead: the reader factory exists only on the live spool arm, and LiveDVRSession.makeStream() always vends a SpoolInputStream, so the cast never fails.

    Two qualifications, because our shape is not your harness's:

    • Our wake makes a parked read re-evaluate, not return. The cancellation predicate the ring is handed is (self?.status ?? .closed) != .open, which wake() deliberately does not move, so a read parked at the growth edge re-parks and serves on the next delivery. Your isClosed check in front of every performRead (CustomIOReaderBridge.swift:166) makes that sufficient: after markClosed() no read reaches us at all.
    • Had we latched, the death would not have looked like your EPERM. Our closed-stream read returns 0, which the bridge maps to AVERROR_EOF (:169); your --cancel-latches arm returns -1 (aetherctl/LiveSpoolIO.swift:140). One host defect, two different-looking deaths — perhaps worth a clause in docs/formats.md:431, which names only the Operation not permitted signature.

    (b) Yes — and on a join-relative axis

    func seek(offset: Int64, whence: Int32) -> Int64 {
        let current = (stream.property(forKey: .fileCurrentOffsetKey) as? NSNumber)?.int64Value ?? joinOffset
        let target: Int64
        switch whence {
        case SEEK_SET: target = joinOffset + offset
        case SEEK_CUR: target = current + offset
        default: return -1   // SEEK_END / AVSEEK_SIZE: a live spool has no known end
        }
        guard target >= joinOffset,
              stream.setProperty(NSNumber(value: target), forKey: .fileCurrentOffsetKey) else { return -1 }
        return target - joinOffset   // FFmpeg's axis, not the spool's
    }

    joinOffset is captured once from the fresh stream's own position, and position only moves forward (reads advance it; the ring's floor clamp can push it past a pruned region, never back), so seek(0, SEEK_CUR) always answers non-negatively and your .cannotAlignReaderSilentOnPosition branch is unreachable here. The number will not read like yours:

    aetherctl customio --live our spool adapter
    what seek(0, SEEK_CUR) reports absolute spool offset (cursor from 0) bytes since this install's join
    your measured line aligned to the reader's cursor at 15728640 bytes — an absolute 15 MB in the same line would carry bytes-since-join

    Measured: the new probe against a real tuner spool

    Office2 (Apple TV 4K gen 3, tvOS 26.6), 6.81.0 installed 08:22 EDT, TEVEMATE_AETHER_LOG=1: five live legs between 08:29 and 08:42, six tunes, nine fresh spool installs (six initial loads, two armed-intent DVR rejoins, one in-place recovery), plus two live tunes on the simulator at the same pin (09:34 and 09:40). Cold tune:

    09-12 08:29:03.923 NOTE [livetv] aether live: spool armed — Live Rewind on the aether arm (E-3b)
    09-12 08:29:04.017 INFO [playback] [Aether] spool stream install (initial load)
    09-12 08:29:04.020 INFO [playback] [AetherLog] [AetherEngine] #361 startup 1/8 sourceOpened (gen 1)
    09-12 08:29:04.032 INFO [playback] [AetherLog] [AetherEngine] #361 startup 2/8 containerOpened (gen 1)
    09-12 08:29:04.682 INFO [playback] [AetherLog] [Demuxer] Opened: 2 streams, duration=-9223372036854775808 us
    09-12 08:29:09.180 INFO [playback] [Aether] started (route loopback, 5.3s)
    

    The probe pair runs inside provider.open() (CustomIOReaderBridge.swift:113-116, before 1/8); currentSourceOffset runs between 1/8 and 2/8 (Demuxer.swift:545-549), a 12 ms span here. On a fresh stream SEEK_CUR answers 0 and the following SEEK_SET 0 maps back to the join, so the decision is .readFromCurrentPosition and nothing is logged — 6.66.0's outcome. The three seek callbacks a live open now costs us (two in open(), one for currentSourceOffset) against 6.66.0's single SEEK_SET 0 are a code read, not a count we instrumented: the callbacks themselves are not logged, only the decision they feed. The negative is the evidence: none of Demuxer.swift:555, :556 or :560-564 appears in any of those eleven opens, and [Demuxer] Opened: (same .demux category, :819) proves the tap carried it.

    The composition — code-read, unmeasured

    Your avio_seek(cursor, SEEK_SET) re-enters our SEEK_SET, which adds joinOffset back; the reader does not move, both axes are bytes-since-join, and the two rebases compose to the identity. That is a read at 6.81.0, not a measurement: every route we drive into your custom branch is closed on our build (both host guards, live audio picks forced through a fresh install, the AUDIO SYNC stepper stood down on the spool arm, no in-engine reopen transport for a non-HLSLiveIngestReader, a tvOS background that cold re-tunes; the one engine-internal route left is the external-playback edge below) — and we built no throwaway with the guard relaxed this session. If we run it you get the line, at the edge and rewound.

    Why we keep the wrapper refusal regardless

    Your fix solves the bytes. It cannot solve our clock, and that half is ours: liveClockBaseline and the DVR session's joinSecs/engineSecs are rebuilt only inside our fresh-install path, which is what an in-place rebuild does not enter. A rebuild that consumed no new stream would come back correct at the edge while the rewind strip froze — the wrapper already carries that branch ([Aether] live clock ran <N>s behind its install baseline — clamped (spool axis)), and the clamp then freezes the playhead while the edge advances, so behind-live grows 1 s/s. Both are reads rather than measurements from this session: the figure recorded against that branch sits in the wrapper's own live-audio-pick comment and is an earlier sim reading from our port, with no log for it in this session's retained set. A second reading: our SpoolInputStream.position is an unguarded var, safe only under one-pump-per-stream, and your own fix comment (CustomIOReaderBridge.swift:135-142) says the successor can be reading while the predecessor tears down.

    So "keep the wrapper refusal" is what we did — for a reason that is ours to fix before the guard can come off, not for the rewind you removed; the guard's comment now says so. If it generalises, the corollary to docs/formats.md:433 is: a host whose own position arithmetic is keyed to vending a stream must re-key it before opting into in-place rebuilds.

    #526, and the one engine-internal route we do not guard

    A log-string change at most on our build. reinstall() asks sessionReloadRefusal up front and returns before calling, so we reach that throw only on a race with the await; when we do, one breadcrumb moves from session-preserving reload no-oped (…) to session-preserving reload threw (…) and the same install(…) runs underneath. The twenty-minute spinner was another host's, and we have not reproduced it here.

    The one engine-internal route we do not guard is AetherEngine.swift:5662-5669, the external-playback edge → Task { try? await reloadAtCurrentPosition() }. Our live session satisfies both of its guards — playbackBackend == .native on the loopback route, and a custom source's loadedURL is the synthetic placeholder (:1568-1570) — and the wired-HDMI exemption is not what keeps us off it: isWiredHDMIExternalDisplay() is #if os(iOS) and answers false on tvOS (:5702-5707). What keeps us off it is your own note one line above that — iOS-only; external playback never engages on tvOS (:5701) — so the observer is registered on our platform (:5453-5463) and the edge should never arrive. Code-read, unmeasured: we have no way to rig an external-playback edge on an Apple TV, so if you read tvOS differently, that is the one hole on our side.

    Disposition

    Nothing outstanding from us on the rebuild itself; close it when you like. The double-cancel could not have bitten us, structurally rather than by luck: every install consumes a fresh positioned stream, so we never hand a retained reader to a successor bridge and no cancel of ours has landed in a rebuilt pump's read. wakeReaders() is idempotent anyway.

    Open on our side: the throwaway-build alignment measurement (offered, not run); and re-baselining the live clock and DVR anchor for a stream-less rebuild, plus putting position behind its lock — the prerequisite for the guard ever relaxing. The external-playback route above needs nothing from us unless your reading of tvOS differs from the one in your own comment.

  6. superuser404notfound commented on Sep 12, 2026

    @superuser404notfound
    Owner

    Thank you for both answers, and for the one finding in there that is about your own side rather than mine: "keep the wrapper refusal, for a reason that is ours to fix" is a more useful sentence than a green retest would have been. Building the second half of this turned up something about where the axis round trip actually happens, so there is engine work in it after all.

    tvOS reads the same way here, and it is compiled out now rather than asserted

    Your reading is right in every part, including the parts that made it worth reporting. The observer really was registered on tvOS (observeExternalPlayback was #if !os(visionOS)), a custom source's loadedURL really is the aether-custom://source placeholder (AetherEngine.swift:3401) so that guard passes, and isWiredHDMIExternalDisplay() was never what kept an Apple TV off the wireless branch. What stood between a tvOS edge and Task { try? await reloadAtCurrentPosition() } was Apple's behaviour plus a comment of mine asserting it, and a comment is not where the reachability of a rebuild belongs.

    tvOS now joins visionOS: no observer, and isExternalPlaybackActiveNow is a compile-time false. The decisive reason is not that an Apple TV is the receiver, it is that both discriminators the edge handler classifies with are #if os(iOS), so a tvOS edge could only ever be read as a wireless receiver and buy a LAN-IP rewrite for a route the platform has not got, which on a custom live source is a rebuild the host pays for out of its own spool.

    With that gone the ladder is short enough to state completely: every session-preserving rebuild on tvOS now begins with a host call. selectAudioTrack(index:), selectTitle(id:), setAudioDelay(_:)'s re-anchor and the two reloads are all host-initiated, and the two internal load() re-entries that remain (#168's ingest reroute, the AE#246 / #154 one) are startup reroutes of a remote-HLS URL source, unreachable from a custom one. The external-playback edge was the only unbidden one.

    The join-relative composition, measured

    The throwaway can stay unbuilt; the harness grew the arm instead. customio --live --reader-axis join --join-offset-mb N vends a reader of your shape (reports and takes offsets counted from the join, SEEK_SET 0 re-bases to it), with absolute as the control and mismatched as a deliberately non-conforming third arm in the spirit of --cancel-latches. A 150 s 1280x720 H.264 + AAC MPEG-TS spool paced at 1700 kbit/s, --reload-at 45:

    axis=join join=2MB
      RELOAD at t=45s: playhead=38.82s cursor=11.5MB edge=11.5MB backend=native
    [Demuxer] live reopen aligned to the reader's cursor at 9994240 bytes
      RELOAD done: playhead 38.82s -> 0.00s, reader cursor 11.5 -> 12.3 MB, edge 11.5 -> 12.3 MB
    LOOKBACK: 8 seeks, deepest reach-back 0.0 MB behind the live edge (0 s of source at this rate)
    

    The two rebases do compose to the identity: the reader did not move, its cursor kept going forward across the rebuild, and nothing was re-delivered. And the number is the one you predicted rather than mine: 9994240 bytes on a cursor sitting 11.5 MB into the file, where the absolute-axis control on the same kind of session reports 9764864. Reading that line as a file position is the mistake the arm now exists to make visible.

    What the mismatched arm taught, which moved where the check belongs

    The round trip that requires the two axes to agree is not only the alignment. The seekability probe in CustomIOReaderBridge.open() makes the same one (seek(0, SEEK_CUR), then a SEEK_SET back to what it was just told), at every open including the first, so an axis mismatch costs a reposition at LOAD, long before any reload is asked for:

    axis=mismatched join=2MB
    [Demuxer] custom source: the reader reported byte 2097152 and answered a seek back to it with
    4194304, so its position report and its SEEK_SET argument are not on the same axis; the source
    has been repositioned by the seekability probe
    [Demuxer] live reopen aligned the axis to 4194304 bytes, but the reader then reported 6291456:
    its position report and its SEEK_SET argument are on different axes, so the source has been
    repositioned by the alignment
    

    2 MB at the load, 2 MB more at the reload (16220160 reported, 18317312 answered, 20414464 after the alignment), after which the session sat in loading from t=51 s to t=71 s reading a stretch the spool had not delivered yet. Forward, incidentally: the rewind is what the other direction's mismatch costs.

    So the first check went into the probe, where it is free. A conforming reader answers a SEEK_SET back to its own reported position with that position, on either axis, so comparing the probe's return against what it was just told needs no extra callback and covers every open, rebuilds included. The alignment then asks once more where the reader is, and that one does cost a seek(0, SEEK_CUR) per live reopen (four host seek callbacks on a live open now, not three). What it buys is the property round 2's third defect was about one level up: a reopen cannot report an alignment the reader did not hold. Named rather than corrected, because which axis a host means is not knowable from here.

    The two cancel signatures, and the corollary

    Both are in docs/formats.md. The EOF half is a clause I would not have written, since the harness only ever dies the one way:

    What that death LOOKS like is the reader's own convention, so one host defect has two signatures: a latched reader whose read returns a negative value produces the Operation not permitted above, while one that returns 0 is mapped to AVERROR_EOF and the session ENDS instead of failing, which on a live source is a stream that was never supposed to have an end.

    Your corollary is in there too, as its own paragraph next to the live-reopen rule: a rebuild consumes no new stream, so anything a host initialises at the point it hands one over (a live clock baseline, a DVR join anchor, the per-stream ownership that makes an unguarded cursor safe) is not re-initialised by a rebuild and will disagree with the session that comes back. The engine's alignment fixes the bytes; it cannot fix a clock it cannot see.

    4ffb64c2, merge db8fbb32, on main and not released yet. Leaving this open until it ships, then closing it, since nothing is outstanding on the rebuild itself.

  7. superuser404notfound commented on Sep 12, 2026

    @superuser404notfound
    Owner

    Released in 6.83.0 (4ffb64c2): the axis check in both places, the tvOS route compiled out, and the two docs/formats.md clauses.

  8. superuser404notfound commented on Sep 12, 2026

    @superuser404notfound
    Owner

    Closing as offered, now that it has shipped. The two follow-ups from this round (the axis check at the probe and at the alignment, and the tvOS reachability change) are in 6.83.0, so anything that turns up against them has a released build to name. Thank you for three rounds of reports that priced the alternative honestly each time; the groundwork ask this started as ended up producing more engine work than the feature did.

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