Skip to content

Make the panel mode switch observable, and stop guessing its end (#339) - #345

Merged
superuser404notfound merged 5 commits into
mainfrom
fix/339-arm-switch-observers-at-write
Aug 9, 2026
Merged

superuser404notfound merged 5 commits into
mainfrom
fix/339-arm-switch-observers-at-write

Conversation

@superuser404notfound

@superuser404notfound superuser404notfound commented Aug 9, 2026 •

Copy link
Copy Markdown
Owner

Device-verified on an Apple TV 4K (3rd generation), tvOS 26.5, HDR10 over HDMI, four rounds of three playbacks each. Fixes #339.

What was wrong

waitForSwitch registered its AVDisplayManagerModeSwitchStart / ...End observers with object: <the display manager the criteria are written to>. tvOS posts them from an AVSharedDisplayManager, so every one of them was dropped:

[ModeSwitchProbe] FIRED AVDisplayManagerModeSwitchStartNotification object=AVSharedDisplayManager@0x10b581a10
[ModeSwitchProbe] our manager=AVDisplayManager@0x1036fdfa0

Six start/end pairs arrived in three playbacks while the engine recorded none. With both notifications invisible, the gate fell back on isDisplayModeSwitchInProgress and on the EDR headroom, and the headroom peaks during the transition. The result was a gate that released play() 2478 ms before the panel finished switching, which is the "first frame hits a mid-transition panel" case the wait exists to prevent, and the shape Sodalite#49 was reported as.

The original theory for #339, that the observers were merely registered too late, was wrong. Arming them at the criteria write is still in this PR as the first commit, and it earned its place differently: it made the settle line say flag only, start notification missed, which is what turned a suspicion into a one-run answer.

The four changes

  1. Observe from the manager that posts. object: nil, documented with the probe output above.
  2. Arm at the criteria write, not at the gate, so a switch that starts and finishes during the load is knowable rather than invisible. Guarded three ways: an end without a start never settles a gate (a sole-writer load's criteria reset produces one, and crediting it would hand a DV P5 cold start to an SDR panel), the in-progress flag may only veto a settle, and a record is evidence only for the load it was armed in.
  3. The headroom is no longer an end signal for a switch we saw start. The deciding input is whether this load recorded a start at all, not whether one arrived since this gate opened: a load runs two gates, and reading "no new start" as "no observable switch" ended a wait 759 ms early on the very next device run. Panels that record no start keep the headroom, which is the unobservable-DV case the cap exists for.
  4. Both gates of a load read the same record. The pre-flight passes consumesRecord: false, so the play gate can settle immediately instead of paying Stage 1's grace to rediscover a switch that has ended.

Measurements this produced

Twelve switches, dynamic-range and range-plus-rate alike: 2779, 2790, 2801, 2850, 2851, 2852, 2854, 2858, 2862, 2877, 2884, 2895 ms. The in-progress flag cleared within 1 ms of the end notification, so on this panel it is an accurate second signal. The settle line now carries the number:

[DisplayCriteria] switch settled via modeSwitchEnd (start pre-gate (start notification, before gate entry)
  0ms before gate entry, total 156ms, switch 2852ms end to end)

Gate exit relative to the real end of the switch, same configuration, across the rounds:

round worst case
before 2478 ms early
after 1 + 2 759 ms early
after 3 +42 ms late
after 4 +26 ms late

Deliberately not changed

Budgets, the grace sizing and the 2000 ms Stage 2 cap. The cap is knowingly smaller than a real switch here, and that turns out to be load-bearing rather than broken: breaking out of it is what lets loadNative run while the switch finishes. Raising it to "fit" the measurement re-serialises the two and costs a full load, ~820 ms on this hardware. That is now written on the constant, and the way to spend the time properly is AE#348.

Verification

swift test: 1651 tests, 242 suites, green. tvOS build green. 18 tests cover the pre-gate verdict, the three settle guards, both headroom rules and the evidence lifetime. Device: four rounds of three playbacks as above. The DV path is unchanged and untested here, the test panel does not support Dolby Vision.

Vincent Herbst added 5 commits August 9, 2026 10:52
…339)

waitForSwitch registered its AVDisplayManagerModeSwitchStart/End observers when
the gate opened. The engine's own criteria write happens in the pre-flight,
before the item is built, so a switch could start and finish outside that
window: both notifications were lost and the gate fell back on
isDisplayModeSwitchInProgress, a flag its own call site documents as unreliable
right after a write. Two of the three device runs in Sodalite#49 spent the full
Stage 2 cap that way, waiting out an end that had already happened, and a third
labelled a switch it had watched begin as one that predated it.

SwitchObservation replaces the two per-gate SwitchFlags: it owns the observers,
records the first start and the latest end with timestamps, and is armed
immediately before a write. apply() arms for the engine's own write; the load
and reload paths arm for a sole-writer host, whose AVKit write lands inside
loadNative. What the gate then reads is a measurement rather than an inference:

- start and end both recorded, panel idle: settled, no wait at all
- start recorded, no end: skip Stage 1, wait out the end
- nothing recorded: Stage 1 exactly as before

Three rules keep that from settling a gate it should not. An end without a
start is never a settle (the criteria reset a sole-writer load performs makes
one, and crediting it would hand a DV P5 cold start to a panel still in SDR);
isDisplayModeSwitchInProgress may only veto a settle, never confirm one; and a
record is evidence once, for the load it was armed in, so an engine-writer
reload that arms nothing cannot inherit the previous load's start and wait for
an end that can no longer arrive.

The settle line now also reports the panel's own switch duration whenever both
notifications were seen. That is the number the .brief budget's sub-second
premise has never been checked against on hardware, and before this an
engine-written switch could not produce it at all. StartSignal.preGate keeps its
place but says what it now means: a switch this session's write never
announced, rather than standing in for a notification.

Budgets, caps and grace sizing are unchanged.
…339)

Device probe on an Apple TV 4K (3rd gen), tvOS 26.5, listening on all
objects: tvOS posts AVDisplayManagerModeSwitchStart/End from an
AVSharedDisplayManager, not from the AVDisplayManager that
window.avDisplayManager returns and that preferredDisplayCriteria is
written to.

    FIRED AVDisplayManagerModeSwitchStartNotification object=AVSharedDisplayManager@0x10b581a10
    our manager=AVDisplayManager@0x1036fdfa0

Six start/end pairs arrived across three playbacks while the engine's
observers, filtered on its own manager, recorded none. That filter is
why no run in Sodalite#49 ever reported an end, why Stage 2 spent its
full cap, and why every settle line fell back on the in-progress flag.
The arming point fixed in the previous commit was not the cause; it is
what made this visible in one run instead of another log round.

The same run measured what the notifications carry: six switches at
2779, 2790, 2801, 2851, 2854 and 2877 ms, on SDR/HDR criteria writes.
The in-progress flag cleared within 1 ms of the end notification, so on
this panel it is an accurate end signal. The EDR headroom is not:

- Stage 2 no longer accepts a raised headroom as the end of a switch it
  watched start. In one run the headroom hit 1.20 at +374 ms for a
  switch that ended at +2851 ms, so the gate released play() 2.5 s into
  a running handshake, which is the first-frame-mid-transition case the
  wait exists to prevent.
- The entry fast-exit now requires the in-progress flag to be clear. A
  panel already in HDR and a panel mid-transition present the same
  raised headroom, and the play gate took the second for the first and
  returned in 0 ms with 2.4 s of switch left.

Budgets and the Stage 2 cap are unchanged; with real switches measured
at ~2.8 s against a 2000 ms cap, that sizing now has numbers behind it
and belongs in its own change.
…om (#339)

Device rerun with the notification fix in: two of three playbacks now
settle on the end notification and report the panel's switch at 2852 and
2850 ms. The third still released play() 759 ms early, through the
Stage 1 headroom exit.

Cause was the condition itself. It asked whether a start notification
had arrived since this gate opened, but a load runs two gates and the
pre-flight consumes the record, so the play gate read "no new start" as
"no observable switch" and let a headroom raised BY the running
transition end the wait. The input that answers the question is whether
this load recorded a start at all: if it did, an end will follow and the
notification (or the flag, exact to 1 ms here) is the authority.

Stage 1 additionally refuses the headroom while the panel reports a
switch in progress, which is the same rule the entry fast-exit already
follows. Panels that record no start keep the headroom as their end
signal in both stages: that is the unobservable-DV case the cap exists
for, and nothing about it changed.

Measured on the device, three playbacks, before -> after:
  gate exit vs. real switch end: -2478 ms -> -759 ms -> (this change) 0
)

The record was spent by whichever gate read it first. A load runs two:
the pre-flight waits an HDR switch out before the item is built, then
the play gate runs after loadNative. On the device, a play gate that
opened after its switch had already ended found the record spent, fell
back to Stage 1 and paid the full 200 ms grace to rediscover that
nothing was pending.

Reading and spending are now separate. The pre-flight passes
consumesRecord: false, so the play gate of the same load still sees the
start and end timestamps and can settle immediately; a later gate with
no arm of its own still sees nothing, which is what keeps an
engine-writer reload from inheriting the previous load's start.
…E#348)

Twelve device measurements put a real panel switch at 2779-2898 ms
against a 2000 ms cap, so the pre-flight gate always breaks out with the
panel still switching. That reads as a defect and is load-bearing:
breaking out is what lets loadNative run during the remaining switch,
and the play gate waits out the rest. Raising the cap to match the
measurement serialises them again and costs a full load, ~820 ms on this
hardware.

Written on the constant so the next well-meant correction starts from
the numbers. The way to spend that time properly is AE#348.
@superuser404notfound superuser404notfound changed the title Arm the mode-switch observation at the criteria write, not at the play gate (#339) Make the panel mode switch observable, and stop guessing its end (#339) Aug 9, 2026
@superuser404notfound
superuser404notfound merged commit 63665c7 into main Aug 9, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/339-arm-switch-observers-at-write branch August 9, 2026 12:04
superuser404notfound pushed a commit that referenced this pull request Aug 10, 2026
fix: sequential-origin declaration for fake-range IPTV timeshift archives

Merged locally: the branch conflicted with main's --switch-audio aetherctl
flags (#345). Both flag sets kept, engine changes untouched.
superuser404notfound pushed a commit that referenced this pull request Aug 10, 2026
Both are new since the 1.0 warning sweep and neither changes behaviour.

armSwitchObservation binds a window it never reads (#345). arm() registers
its observers with object: nil, so the window is a presence test only, which
is what the guard now says. The site is inside #if os(tvOS), so a macOS
swift build cannot see it; only the tvOS xcodebuild leg does.

The #303 frontier test wrapped its read in try? #require, which the current
Testing macro reports as redundant. The direct comparison is the form the
rest of the file already uses and fails identically on nil.

Sweep: Sodalite tvOS/iOS Debug + Release, AetherEngine swift build
--build-tests, xcodebuild tvOS Release, AetherEngineSMB iOS + macOS Release,
AetherEngineTests build-for-testing on tvOS and iOS simulators, Sodalite-tvOS
build-for-testing. All zero warnings after this commit.

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.

Display-criteria gate: observers register at gate entry, so an engine-written switch is unobservable end to end

1 participant