Skip to content

waitForSwitch() still runs when suppressDisplayCriteria=true, adding a residual startup wait even when the host is the sole criteria writer #274

Closed

Description

@digilearn-dev

What happened?

With suppressDisplayCriteria=true (production mode), Aether correctly skips its own apply() (only runs .clearStale), leaving the host as the sole writer of display criteria. However, the play-gate waitForSwitch() still runs unconditionally on this path, regardless of suppressDisplayCriteria.

This surfaced as a real bug: our host-side rate write, made mid-load once the source frame rate was known, happened to overlap with this unconditional waitForSwitch(). Since Aether itself never applied anything (didApply == false on this path), the wait fell into the wrong branch and mis-logged a real, host-driven SDR rate switch as a failed HDR one:

[DisplayCriteria] WARN switch ended (~2450ms) but EDR headroom still 1.0 (panel stayed SDR despite HDR criteria)

That cost ~2.4s of VOD startup time on affected sessions. We fixed the overlap on our side by deferring the host's rate write until after engine.load() returns, which eliminated the WARN and the mislabeling entirely — confirmed across several fresh VOD plays, zero recurrences.

However, comparing before/after ttff_ms on network-latency-matched sessions, we only recovered part of the lost time (roughly 1.3–1.4s of the original ~2.4s). The likely explanation, and the reason for this report: waitForSwitch() is still called on every load even with suppressDisplayCriteria=true, and even with no host write overlapping it, it appears to still cost a real amount of time (a "Stage 1: no switch started" empty wait) rather than returning immediately. If the host has declared itself the sole criteria writer, we'd expect Aether's own play-gate to either skip this wait entirely or resolve it near-instantly when there's genuinely nothing for Aether to be waiting on.

Steps to reproduce

  1. Configure a session with suppressDisplayCriteria=true.
  2. Load VOD content and measure ttff_ms under load_profile=vod, isolating for network/first-byte latency (i.e. compare sessions with similar [AVIOReader] first data after Nms timing).
  3. Observe that even with no host-side criteria write overlapping the play-gate window (verified via our own fix — host write now deferred to after_load_complete, confirmed no WARN and isHDRCriteria=false correctly logged), overall ttff_ms still carries a residual cost beyond first-byte network time that's larger than expected for a no-op wait.

Example before/after from our own testing (same title class, comparable network conditions):

  | First-byte (network) | Total ttff_ms | Overhead beyond network -- | -- | -- | -- Before our fix (WARN present) | ~2542ms | 5689ms | ~3147ms After our fix (WARN absent) | ~2027ms | 3810ms | ~1783ms

AetherEngine version or commit SHA

6.4

Host app

Custom / my own integration

Platform

tvOS

OS version

tvOS 26.6 (beta)

Device / chip

Apple TV 4K (A15)

Playback path

Native AVPlayer

Source media (for playback bugs)

Various VOD titles (H.264 and HEVC, SDR and HDR sources), served via remote HTTP source (debrid-style proxy). Not codec/resolution-specific — this is a play-gate timing issue independent of content characteristics.

Error codes / log lines

The original symptom (now fixed on our side by deferring our own write):

[DisplayCriteria] WARN switch ended (~2450ms) but EDR headroom still 1.0 (panel stayed SDR despite HDR criteria)

Confirmed absent after our deferral fix, alongside our new diagnostic fields:

MEDIAHUB_VOD_UI event=display_criteria_rate_ready ... applyTiming=after_load_complete reason=avoid_aether_play_gate_waitForSwitch_overlap
MEDIAHUB_VOD_UI event=display_criteria_applied_by_host ... isHDRCriteria=false applyTiming=after_load_complete

No error-level output for the residual wait itself — it's a timing cost, not a logged failure, which is why we're reporting it as an observation/request rather than a crash-style bug.

Anything else

Our host-side fix (deferring the rate-criteria write until after load() returns) is shipped and working — this report is specifically about the remaining engine-side cost, not asking you to fix our overlap issue (that's resolved).

Proposed fix shape: when suppressDisplayCriteria == true, either skip waitForSwitch() entirely in the play-gate (since the host has declared itself sole writer, there's nothing Aether-initiated to wait on), or if some minimal handshake is still needed, ensure it resolves near-instantly rather than carrying a "Stage 1: no switch started" empty-wait cost. Separately, if the WARN ... despite HDR criteria log path can still theoretically fire in other scenarios, it might be worth having it check suppressDisplayCriteria before attributing an in-flight switch to HDR — since under that flag, Aether can't know what kind of switch the host initiated, only that one is in flight.

Happy to test a build against this — our host-side timing instrumentation (applyTiming, isHDRCriteria fields) is already in place, so before/after ttff_ms comparisons are straightforward for us to produce.

Activity

  1. added
    bug
    on Aug 1, 2026
  2. superuser404notfound commented on Aug 2, 2026

    @superuser404notfound
    Owner

    Thanks for the writeup, and especially for the before/after numbers with the network time isolated. Both halves of the report reproduce in the code, and there is a useful correction to one part of the model.

    What the ~2450 ms actually was. The play-gate is two stages: Stage 1 blind-polls up to 1000 ms for a switch to start, Stage 2 then waits up to 2000 ms for it to settle. The elapsed value printed in that WARN includes both, so ~2450ms means Stage 1 saw a switch start and Stage 2 spent ~1450 ms settling it. That was not an empty wait, it was the gate settling the real rate switch your host had just initiated, and then labelling it wrong. Your deferral removed the cost by moving the switch out of the load window entirely; the panel still switches, just later.

    Why the wait is not gated on suppressDisplayCriteria. That flag is the case the gate was built for. It was added in 5d60dbb for a sole-writer host whose criteria write comes from AVKit's auto path, which reads dvcC off the live AVPlayerItem.formatDescription and therefore fires later and more variably than the engine's synchronous pre-flight. Stage 1 went from 200 ms to 1000 ms in that same commit for exactly that reason. Dolby Vision Profile 5 has no HDR10 base layer, so its first frame must not land on a panel that is still SDR. Skipping the wait when the host is sole writer would trade your startup cost for a DV P5 cold-start regression on those hosts.

    What changed instead (PR #277). The budget is now sized by whether a dynamic-range switch can still reach the session at all, which is a question the engine can answer:

    session Stage 1 budget
    criteria already active (same-format zap) skipped
    engine is the criteria writer 200 ms
    sole-writer host, HDR/DV content 1000 ms
    sole-writer host, SDR content 200 ms
    sole-writer host, source probe failed (range unknown) 1000 ms

    The reasoning for the SDR row is the engine's own doctrine applied consistently: on SDR content the only write anyone can still make is rate-only, and the engine already declines to gate its own rate-only writes, because those settle sub-second. Stage 2 is unchanged, it only runs when a switch has genuinely started, and the entry fast-exit on EDR headroom still returns immediately when the panel is already in HDR.

    The WARN. Fixed at the source rather than by checking the suppression flag: the classification read "engine did not write criteria this session" as the HDR branch. There is now a third, neutral outcome for a switch the engine did not initiate, since it has no target range to compare the SDR end state against. Your isHDRCriteria=false sessions will no longer produce that line even if the write does overlap the gate.

    For the retest, the no switch started (...) after Nms; proceeding line now names the budget that was actually used, so 200 vs 1000 is visible without inference. On your SDR VOD titles the blind portion should drop by 800 ms. HDR/DV titles keep the full budget by design, and with your write deferred to after load() returns the engine has no way to know nothing is inbound. If your numbers show that case still hurting, an explicit LoadOptions opt-out for hosts that program criteria outside the load window is a reasonable follow-up, but that should be driven by your measurement rather than added on suspicion.

  3. added a commit that references this issue on Aug 2, 2026
  4. superuser404notfound commented on Aug 2, 2026

    @superuser404notfound
    Owner

    Released as 6.4.3 (7731f0b, fix in 3e329f19).

    For the retest, the line to watch is [DisplayCriteria] no switch started (EDR headroom ...) after Nms; proceeding, which now prints the budget that was actually spent. On a session with suppressDisplayCriteria = true and SDR content that reads 200ms; HDR/DV content on the same host still reads 1000ms by design. If a switch does start, Stage 2 is unchanged, so a settle time in the log means real handshake work rather than a blind wait.

    Leaving this open until the ttff_ms comparison is in.

  5. digilearn-dev commented on Aug 2, 2026

    @digilearn-dev
    Author

    Retested on 6.4.3 across three fresh VOD sessions (two SDR, one HDR/DV Profile 8.1), isolating network time to properly compare. The fix is confirmed working exactly as designed in every case:

    SDR: [DisplayCriteria] no switch started (EDR headroom 1.00 after 200ms); proceeding
    HDR/DV: [DisplayCriteria] no switch started (EDR headroom 1.00 after 1000ms); proceeding
    SDR sessions correctly got the 200ms budget, down from 1000ms.
    The HDR/DV session correctly kept the full 1000ms budget — no regression there, exactly as intended for the DV Profile 5 protection you described.
    Zero occurrences of the despite HDR criteria WARN across all three, including the HDR/DV case where the old misclassification would have been most likely to show up.

    Total ttff_ms on these sessions was actually higher than our original numbers, but tracing the full timeline showed that's entirely unrelated to this fix — it's dominated by a sequential network round-trip pattern on our source's non-fast-start MP4s (three connections needed before frame rate is even known), which happens well before DisplayCriteria engages. Opened that separately as its own issue rather than conflating it with this one.

    This one's resolved on our end — thanks for the fast, well-explained fix, and for correcting our model on what the original wait actually was.

  6. superuser404notfound commented on Aug 2, 2026

    @superuser404notfound
    Owner

    Retest confirmed, closing this out.

    Both budgets landing where they should (200ms on SDR, the full 1000ms on the DV Profile 8.1 session) plus zero WARN lines is a cleaner verification than a raw ttff delta would have been, since it separates what the gate spends from what the transport spends. That distinction is exactly why the log line was changed to name the budget it actually used.

    On the LoadOptions opt-out offered last round: dropping it for now. By the numbers the only blind wait left is the 1000ms on HDR/DV content, and that one is the DV Profile 5 cold-start guarantee itself. An opt-out there would move the risk onto the host without a measurement asking for it. If a criteria write placed outside the load window ever shows up as a measurable cost on HDR titles specifically, that is the point to revisit it.

    Good call filing the cold-start round-trip pattern as #281 instead of folding it in here. The two live at completely different layers, and the numbers there are worth reading on their own terms.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions