Skip to content

fix(display): size the play-gate start grace by what can still switch (#274) - #277

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/274-play-gate-start-grace
Aug 2, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/274-play-gate-start-grace

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Closes nothing yet: reporter retest pending.

What the report found

With LoadOptions.suppressDisplayCriteria = true the engine skips its own apply() (only .clearStale runs), but the post-load play-gate still called waitForSwitch() with the same budget as every other session. @digilearn-dev measured a residual startup cost on VOD loads where nothing was in flight for the engine to wait on, plus a mis-attributed WARN ... panel stayed SDR despite HDR criteria for a switch their own host had initiated.

Root cause

Two independent defects, both from the gate not knowing who writes criteria.

1. Stage 1 budget. waitForSwitch Stage 1 blind-polls for a switch to start. It went 200 ms -> 1000 ms in 5d60dbb for one architecture: an AVKit-sole-writer host whose criteria write fires from the live AVPlayerItem.formatDescription during the load. DV P5 has no HDR10 base layer, so its first frame must not hit an SDR panel, and that budget is what made the cold start land. Every other session paid it for a write that could not arrive:

  • Engine-writer sessions wrote synchronously before loadNative. Whatever switch that triggered started long before the gate runs, and a .willSwitch was already settled by the pre-flight waitForSwitch. A second full blind poll buys nothing.
  • SDR content reaches no dynamic-range switch at all. The only write still possible is rate-only, and the engine already declines to gate its own rate-only writes (apply() returns .applied with no pre-flight wait) because those settle sub-second.

2. Settle attribution. Stage 2's classification was didApply && !lastCriteriaWasHDR -> rate-only, else -> WARN HDR failure. On a sole-writer host didApply is false, so a host SDR rate write that correctly ended SDR fell into the HDR-failure branch. The engine cannot attribute a switch it did not initiate.

The fix

waitForSwitch(startGrace:) takes .skip / .brief (200 ms) / .full (1000 ms). AetherEngine.playGateGrace is the pure decision:

session grace
criteria unchanged (#133 same-format zap) skip
engine is the criteria writer brief
sole-writer host, probe failed (range unknown) full
sole-writer host, SDR content brief
sole-writer host, HDR/DV content full

A switch that genuinely started still settles in Stage 2 unchanged, and the entry fast-exit on EDR headroom is untouched, so an already-HDR panel still returns instantly. The audio-switch reload gate routes through the same rule: it preserves the criteria (resetDisplayCriteria: false) and re-applies none, so only a host re-write on the swapped item can switch anything there.

switchEndOutcome(didApply:lastCriteriaWasHDR:) adds the third case and logs it neutrally instead of warning.

What deliberately did not change

The report proposed skipping waitForSwitch entirely when suppressDisplayCriteria == true. That is the one case the gate was built for (5d60dbb, validated on DrHurt's Build 173 DV P8.4 testing), so skipping there would trade this startup cost for a DV P5 cold-start regression on AVKit-auto hosts. The budget is now sized by whether a dynamic-range switch can reach the session, which covers the reporter's SDR loads without touching that guarantee.

Verification

  • swift test: 1396 tests in 210 suites pass, including the new DisplayCriteriaPlayGateTests (both decisions are pure).
  • xcodebuild -scheme AetherEngine -destination 'generic/platform=tvOS Simulator' build: clean.
  • Device verification of the startup timing is the reporter's retest; their host already logs applyTiming / isHDRCriteria, and the new no switch started ... after 200ms line names the budget that was used.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE

…#274)

The post-load play-gate calls waitForSwitch() before nativeHost.play() so
the first decoded frame does not hit a mid-transition panel. Its Stage 1
blind-polls up to 1000 ms for a switch to START, a budget raised from
200 ms in 5d60dbb for exactly one case: a sole-writer host
(suppressDisplayCriteria) whose criteria write lands during the load, from
AVKit's auto path reading dvcC off the live AVPlayerItem. DV P5 cold start
needs it. Every other session paid the same 1000 ms for a write that could
not arrive, which is dead startup time, not safety:

- Engine-writer sessions wrote their criteria synchronously before
  loadNative. Any switch that write triggers started long before the gate
  runs, and .willSwitch already settled it in the pre-flight, so a second
  full blind poll buys nothing.
- SDR content reaches no dynamic-range switch at all. The only write anyone
  can still make is rate-only, and the engine already declines to gate its
  own rate-only writes (apply() returns .applied with no pre-flight wait)
  because those switches are sub-second.

waitForSwitch takes a StartGrace (skip / brief 200 ms / full 1000 ms);
AetherEngine.playGateGrace is the pure decision, covering the #133
unchanged-criteria skip as well. A failed probe keeps the full budget on a
suppressed host, because the source range is then unknown and a DV write may
still be inbound. The audio-switch reload gate goes through the same rule:
it preserves the criteria and re-applies none, so only a host re-write on
the swapped item can switch anything.

Second defect from the same report: the Stage 2 settle classification read
didApply == false as the HDR branch, so a sole-writer host's own SDR rate
write settling with EDR headroom 1.0 logged "WARN switch ended but EDR
headroom still 1.0 (panel stayed SDR despite HDR criteria)". The engine has
no target range to compare against for a write it never made.
switchEndOutcome makes that a third, neutral case.

Both decisions are pure and unit-tested (DisplayCriteriaPlayGateTests).

Reported and measured by @digilearn-dev (#274).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant