Skip to content

Expose an accurate in-flight seek signal (isSeeking / seekTarget) that spans the real loopback-HLS landing and covers native scrubs #38

Open

Description

@rrgomes

What should the engine do?

Publish isSeeking: Bool + seekTarget: Double? that are true from seek entry until the seek physically lands (not the optimistic .playing flip), uniform across programmatic engine.seek() and native AVPlayerViewController user scrubs.

Motivating media or use case

A host coordinating playback across multiple devices (synchronized viewing) needs to know "a seek is in flight, and where it's going" without inferring it from currentTime jumps — which are ambiguous against a rebuffer or an underflow skip. On the loopback-HLS path the real seek lands seconds after the call, and .seeking is currently left the moment seek(to:) returns, so there's no reliable window. Native transport-bar scrubs bypass engine.seek() entirely (they seek currentAVPlayer directly), so they're invisible to a consumer today.

Area

Public API surface

Host app / integration context

A custom tvOS client.

Would you be willing to open a PR?

Yes — a WIP exists for the programmatic half (see below).

WIP / notes

I have a branch that adds @Published isSeeking / seekTarget, set at seek entry and cleared on the real landing (by awaiting NativeAVPlayerHost.seek's AVPlayer completion handler), with a seekGeneration guard so a superseding seek owns the final state — builds, and all existing tests pass. The same await-the-landing change also fixes the clock-bounce in #37 as a side effect.

It is intentionally incomplete: it only catches programmatic engine.seek(). Native AVPlayerViewController scrubs would need the signal fired from the loopback out-of-range segment-request → restart path (where the seek-coalescing logic lives) — that part you'd know best. Happy to share the approach/diff if useful.

Related: #37 (the clock-bounce bug the same fix resolves).

Activity

  1. superuser404notfound commented on Jun 16, 2026

    @superuser404notfound
    Owner

    Implemented on main (commit 924951e, currently under [Unreleased]), covering both halves.

    Programmatic + the real landing: AetherEngine.isSeeking is now true from seek entry until the seek physically lands (awaiting AVPlayer's completion handler), not the optimistic .playing flip. seekTarget: Double? carries the in-flight destination on the source-PTS axis (same axis as currentTime). This is the await-the-landing change that also fixed #37.

    Native AVKit scrubs: these bypass engine.seek() and instead drive a producer restart when AVPlayer requests a segment out of the served LRU window, so the signal is fired from the requestRestart coalescer (the same place the #35 seek-coalescing lives): (true, segmentTime) at the start of a coalesced restart run, (false, nil) once it drains, folded onto the source-PTS seekTarget. It is purely additive to the coalescer, no change to its mechanics.

    One subtlety worth flagging: a programmatic seek to a far target itself triggers a producer restart, so the two paths are not mutually exclusive. They are tracked as two independent in-flight sources and OR-ed, so a restart finishing cannot drop isSeeking before a programmatic seek's AVPlayer landing, and vice versa. A stopInternal hard-clear keeps a stop landing mid-seek from stranding the signal.

    Off-device the aetherctl seektest probe confirms isSeeking is observed in-flight and cleared after the landing. Leaving this open for a device retest of the native-scrub half against a real synchronized-playback host. Thanks for the WIP and the clear split of the two halves.

  2. rrgomes commented on Jun 17, 2026

    @rrgomes
    ContributorAuthor

    Retested on device after pinning 3.7.0, using our 2-Apple-TV synchronized-playback setup (one device scrubs the native AVKit transport bar; the other follows via programmatic seeks our sync layer issues to catch up).

    First — the #37 seek-bounce fix is confirmed on real hardware. On 3.5.0 a transport-bar scrub visibly seeks to the target, snaps back through the pre-seek position, plays briefly, then returns; on 3.7.0 that bounce is gone. Thanks for the quick turnaround.

    On #38 itself: we haven't yet wired our host to consume isSeeking / seekTarget (planned), so I can't report on the published signal's accuracy from production use yet — I'll follow up when we do.

    But the retest surfaced something likely in your wheelhouse — I think the #35 class resurfacing under a sustained rapid seek sequence: the reported clock (currentTime) decouples from the actual decoded frame, with the frame running ahead of the clock, and the gap accumulates with seek count. Observed on both 3.5.0 and 3.7.0 (so not introduced by the #37 fix):

    • Natively-scrubbed device: timeline ~5:01, decoded frame a few seconds ahead.
    • Follower (the most seeks — ~1 programmatic seek/sec plus bursts): timeline ~5:02, decoded frame ~6:05 (≈63s ahead), audio several seconds out of sync and dropping out for seconds at a time.

    A solo light scrub self-recovers (consistent with #35 being fixed for that case), but a sustained high seek rate seems to drive clock and frame apart without reconciling — as if each seek leaves a small residual that accumulates when seeks arrive faster than the pipeline reconciles.

    I suspect this reproduces in aetherctl seektest widened to a sustained burst (e.g. 20–30 bidirectional seeks at ~1–3/sec), comparing engine.currentTime against the decoded frame's PTS after the burst. Happy to share our sync logs or put together a minimal repro. Reopen #35, or a new issue?

  3. superuser404notfound commented on Jun 17, 2026

    @superuser404notfound
    Owner

    Tracking the sustained-rate clock/frame divergence you hit on the retest as its own issue, #49, to keep it apart from the #35 re-fold and the #38 seek signal. Investigation notes and the diagnostics built so far are there, along with a couple of specifics that would help reproduce it (source keyframe cadence + a follower sync log). Thanks again for the thorough retest and the clean split of what reproduced and what did not.

  4. superuser404notfound commented on Jun 24, 2026

    @superuser404notfound
    Owner

    @rrgomes Any news about this?

  5. rrgomes commented on Jun 24, 2026

    @rrgomes
    ContributorAuthor

    Thanks for your patience — we were pinned to 3.11.6, which predated this, so we just bumped to 3.13.3. Diagnosing a WT desync today made the need obvious: our sync host was reading the engine's reported position during a seek and broadcasting it to followers, and during a rapid relative-skip burst that reported position leads the real AVPlayer landing by several seconds (exactly what this issue is about), so followers chase a position the authority hasn't reached yet. We're wiring isSeeking/seekTarget into the host now so we suppress position broadcasts and drift-correction until the seek lands. Will report device results once it's in.

  6. superuser404notfound commented on Jul 29, 2026

    @superuser404notfound
    Owner

    @rrgomes Checking back on this one. Last word here was that you were wiring isSeeking / seekTarget into the sync host so position broadcasts and drift correction stay suppressed until a seek physically lands. Any results from that on the 2-Apple-TV setup?

    No urgency, and nothing here is blocked on it. I mostly want to know whether the published signal holds up as the authority for "do not broadcast yet" in production, since that is the use case it was shaped around and it is the one thing the off-device probe cannot answer. If it did not work out, that is just as useful to hear.

  7. rrgomes commented on Jul 29, 2026

    @rrgomes
    ContributorAuthor

    It held up, and it is the authority now. Three things around it needed guards.

    Two Apple TVs on a LAN plus a WAN peer, in daily use since. The signal is mirrored into the sync adapter and does exactly what it was shaped for: while isSeeking is set we broadcast seekTarget — the known destination — instead of the live clock. On the loopback path the reported clock leads and bounces until it clears, so without that the heartbeat carries a position the source has not reached, a follower chases it, and drift blows past tolerance into a force-resync storm. Convergence heuristics could not do this: they cannot see a keyframe-granularity landing that settles a few seconds off the requested target, and they cannot tell a landing from a scrub.

    What the falling edge needed on top:

    It can precede the clock snap. On 5.0.5, captured over WAN 2026-07-15 22:02:22, isSeeking cleared while the reported clock still read the pre-seek position, and the clock snapped about 1.4 s later. So the read at the falling edge is not yet trustworthy. We anchor to the commanded target when one is in flight and hold the scrub detector off through a 1.5 s landing grace — anchoring alone does not cover the stale reads between the clear and the snap, which otherwise look like a fresh user scrub and get broadcast.

    isSeeking and seekTarget clear in the same recompute, with no ordering guarantee between the two publishers. At the falling edge both live mirrors can already be nil, so we retain the last non-nil target to build the landing reference from.

    A bounded-deadline seek lands with no pulse at all. When the falling edge arrives far from the known target, the engine has hit its budget, reconciled its clock back to the rendered pre-seek frame, and kept the seek alive as recovery intent. The true landing then arrives as a silent clock jump, possibly minutes later on a stalled source. We retain the unreached target for 180 s with a 4 s epsilon so the detector absorbs that jump as landing mechanics. Classified as a scrub it would broadcast and yank every peer back by however long the stall lasted.

    One case the signal cannot cover, for completeness: a seek issued before the session is ready is swallowed with no trace — no isSeeking, no deferral, because there is no session yet. Our join-position seed lands exactly there, so we track that separately rather than expecting the signal to see it.

    Net: as the authority for "do not broadcast yet" it is right, and it is strictly better than what we had. It is an edge signal rather than a level one — the rising edge is trustworthy, the falling edge means "probably landed, verify" rather than "landed".

    One caveat on currency: the version-specific observations above are from 5.0.5 and 5.4.1. We are pinned at 5.28.0 now and I have not re-verified whether the falling-edge timing still needs the grace, so treat those two as history rather than as current behaviour.

  8. added a commit that references this issue on Jul 29, 2026
  9. superuser404notfound commented on Jul 30, 2026

    @superuser404notfound
    Owner

    That is the most useful kind of report to get back on a signal: it says which part held, and it names the three places where the shape of the API made you build machinery around it. All four points are engine-side, and they are on main now in 90f2a92f (PR #252). Three are fixed; the fourth, the late landing after a give-up, is now expressible rather than fixed, because it is precisely the transition a level signal cannot carry.

    Where your 5.0.5 / 5.4.1 observations stand on 6.0.2, since you flagged them as history:

    • The falling edge preceding the clock snap. For programmatic seeks this is gone: every finalize writes currentTime before clearing the gate, so the reported clock sits at the target when the level falls. One caveat that is by design rather than an oversight: sourceTime still trails there, because since Clock/frame divergence accumulates under sustained seek rate (#35-class, #38 retest follow-up) #49 it tracks the rendered frame rather than the scrub target. For native AVKit scrubs your observation was still exactly right on 6.0.2, and structurally so: the level fell when the coalesced producer restart drained, which means the producer is now producing at the new index, not that AVPlayer rendered it. The 1.4 s you captured is the fetch and the decode after that point.
    • isSeeking and seekTarget clearing in one recompute. Unchanged and real. The order inside the recompute is deterministic, but nothing about it was contractual, and any consumer that hops a queue between the two sees them coalesced.
    • The bounded-deadline seek landing with no pulse. The mechanics moved a long way since 5.0.5: the clock is no longer reconciled back to the pre-seek frame but held at the target, the gate now survives the extension windows and the producer re-anchor, and a late landing settles through the rendered-time sink. Your point survived all of that intact, though. After the full budget the level clears, and the real landing after it produced no edge at all.
    • The seek swallowed before the session is ready. Partly covered since Seek requests can be silently dropped or land on the wrong position during VOD startup/restart (two related races in .loading guard and RestartCoalescer) #178 and iOS: quick app switches pay a full pipeline rebuild — grace period before paused-background teardown, warm reload, deferred pre-ready seeks, public readiness signal #127: such a seek is stashed and replayed at readiness instead of vanishing. But it published its target on currentTime with isSeeking false, which for your use case is worse than the swallow was: a position nothing has reached, with no flag saying not to broadcast it. Your join-position seed lands exactly there.

    What is on main

    AetherEngine.seekEvents: AnyPublisher<SeekEvent, Never>. Every accepted seek emits .began and exactly one of .landed(renderedTime:), .stalled or .superseded under the same id; a seek that never reaches a host emits a standalone .rejected(.noActiveSession) or .rejected(.liveWithoutDVR). Each event carries the target it belongs to and its origin (programmatic, nativeScrub, deferred). The one asymmetry in the contract is deliberate and is the reason the stream exists: a seek that spends its recovery budget reports .stalled and drops out of isSeeking, but it stays alive inside AVPlayer as recovery intent, so a .landed under the same id can still arrive minutes later on a source that finally serves the target.

    Every event is also an EngineLog line in the engine category (seek#12 programmatic landed rendered=90.00 target=90.00), so a capture is possible without wiring the stream first.

    Alongside it:

    • A native scrub's in-flight window now ends when the rendered frame reaches the restarted region, watched on the same rendered-time axis and bounded at 8 s, after which the honest report is .stalled rather than a latched signal. A restart that a programmatic seek itself caused is left to that seek's own events: the restart aims at the segment containing the requested time, so it can sit below where the picture ends up (an aetherctl seektest run measured a restart at 84.0 for a landing at 90.0), and watching for a landing at the restart target there would contradict the seek that landed fine.
    • Stashed pre-session seeks hold the seek signal for the whole stash window and hand over to their replay without a gap in the level.
    • seekTarget follows the most authoritative in-flight source instead of the last non-nil target ever written, which previously kept a settled programmatic seek's destination published while a scrub was in flight toward a different one.

    What that means for the three guards

    The events are meant to retire them rather than sit next to them. The 1.5 s landing grace is covered because .landed is emitted after the clock write, so the read at the event is trustworthy. The retained last non-nil target is covered because every event carries its own target and id, with no second property to race. The 180 s unreached-target map with the 4 s epsilon is covered by .stalled followed by .landed under the same id, which is the actual event rather than an inference from a jump. And the case the signal could not see at all now shows up as a .began with origin deferred.

    Verification, and what is not verified

    1300 unit tests including the new pairing, stash, give-up and scrub-landing cases; seektest grew a #38 SEEK EVENT LEDGER where an unpaired .began fails the run, and on the real loopback path it reports 11 begans, 11 terminators, none unpaired, with the existing #37/#38 probe still passing. What the headless harness cannot produce is a genuine AVKit scrub, so the armed landing watch is covered by unit tests on the predicate and the sink hook, not end to end. That half is the one your setup exercises every day, and the falling edge there is the one you measured at 1.4 s, so a retest on the two Apple TVs plus the WAN peer is what would actually settle it.

    A release follows shortly; the tag will be posted here so there is something to pin. Thanks again for running the signal in production and coming back with the edges instead of just the verdict.

  10. superuser404notfound commented on Jul 30, 2026

    @superuser404notfound
    Owner

    Released as 6.1.0 (68e9e4e5), so there is something to pin now.

    .package(url: "https://github.com/superuser404notfound/AetherEngine", from: "6.1.0")

    Drop-in from 5.28.0 as far as this signal goes: isSeeking and seekTarget keep their type and meaning, and the only behavioural difference for a host that ignores seekEvents is that a native scrub's in-flight window now spans the picture arriving rather than the producer restart draining.

    The retest that would actually settle this is the native-scrub half on the two Apple TVs plus the WAN peer, since the headless harness cannot produce a real AVKit scrub. Two things worth watching there: whether a .landed for a scrub now sits after the clock snap rather than 1.4 s before it, and whether an 8 s .stalled ever shows up for a scrub that did land, which would mean the landing watch is missing an arrival on your link rather than the source being slow. EngineLog carries every event, so a capture needs no wiring.

    No rush on any of it, and if the guards turn out to still be earning their keep somewhere, that is just as useful to hear.

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