Skip to content

fix(display): a rate the panel switched to waits for the switch end (#950) - #952

Merged
superuser404notfound merged 2 commits into
mainfrom
fix/950-rate-switch-relock
Nov 1, 2026
Merged

superuser404notfound merged 2 commits into
mainfrom
fix/950-rate-switch-relock

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Fixes the cause of #950 (reporter retest still pending).

What

The #449 exit released a rate-only play gate as soon as the display link read the requested rate. A display link reads the new cadence once the compositor runs at it, which is long before the HDMI sink has re-locked. On the reporter's LG C2, a 23.976 start from the 50 Hz home screen released 50 to 135 ms after the switch started. tvOS reports switches on that panel ending after ~2.5 s, and three of six starts flashed pink noise over the black.

The exact reading cannot tell those two cases apart. The panel's cadence before the write can:

  • loadSession starts a DisplayLinkSampler across the probe (beginPreWriteCadence), and apply() reads it just before the write and stops it. The reading is stored with the write's arm generation, so a later gate with no write of its own cannot use it.
  • rateOnlySwitchIsSettled takes the optional preWrite relation. If it is .different, the panel had to switch, so neither an exact reading nor a multiple settles the gate. It then waits for modeSwitchEnd, the in-progress flag or the cap, the same as an HDR write.
  • If the panel was already at the rate (the A rate-only criteria write for a rate the panel already runs spends the full 2 s cap holding play() #449 case: a start notification with no end), it keeps the fast exit. A missing reading (nil / .unmeasured) keeps the old behaviour.

Diagnostics

  • The SET: line now ends with before write: <relation>.
  • A gate that turns down an exact reading or a multiple for this reason logs one #950: line saying so. The modeSwitchEnd or cap line then shows how long the switch actually ran.

Cost

A start that changes the refresh rate goes back to waiting for the switch, about 2.5 s on this panel. While the panel re-locks it shows black at best, so releasing early only played content into the dark, and on this panel it also showed noise. Same-rate starts and zaps are unchanged.

Residue

A load issued within a second or two of a stop() can still read the old rate while the panel is switching back to the home mode. That reading counts as "already at rate" and takes the old path.

Tests

Issue950RateSwitchRelockTests (4). The display suites pass (162 tests in 18 suites), and the tvOS build succeeds.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SeT6NgupsgTSme7g6RFnE5

…950)

The #449 exit released a rate-only play gate as soon as the display
link read the requested rate. A display link reads the new cadence once
the compositor runs at it, long before the HDMI sink has re-locked: on
an LG C2, a 23.976 start from the 50 Hz home screen released 50 to
135 ms after the switch started, tvOS reported such switches ending
after ~2.5 s, and three of six starts flashed pink noise over black.

The engine now reads the panel cadence across the probe, before it
writes the criteria. A panel already at the rate (the #449 case, a
start with no end) keeps the fast exit; one that had to switch waits
for the end notification, the in-progress flag or the cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SeT6NgupsgTSme7g6RFnE5

@quint-aether quint-aether Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review

Status: 🟡 Minor follow-ups. Only small touch-ups left.

The PR samples the panel's cadence during the probe and keys that reading to the arm generation of the criteria write. A rate-only write the panel had to switch to then waits for modeSwitchEnd, the in-progress flag or the cap. The #449 exit still applies when the panel was already at the requested rate. The fix is in the engine and addresses the cause: the display link reports the compositor's new cadence before the HDMI sink has re-locked. It keeps the #449 fast path, and a missing reading falls back to today's behaviour.

Findings

  • Nit: If two loads overlap, the superseded load's defer can stop the sampler the newer load is relying on. The newer write then reads .unmeasured and takes the old fast exit. This is safe, but on rapid zaps #950 can come back. (Sources/AetherEngine/AetherEngine.swift:4419)
  • Nit: The CHANGELOG says a switched start waits for "the 6 s cap". That cap (observedEndCapMs) only applies to .awaitObservedEnd gates. Live loads use the .standard cap and still release before a ~2.5 s re-lock. Saying "the cap" or "6 s for VOD" would match the code.

I checked that the generation key holds. A .unchanged apply does not re-arm, but both play gates get .skip grace on that path (playGateGrace), so a stale relation cannot settle or block them. reset() clears it as well.

Checklist: CHANGELOG yes, docs n.a., tests yes (pure policy; the sampling and the generation keying need a device), traits both ways n.a.

Needs a device run: the reporter's LG C2 retest, to confirm that the pre-write reading reads 50 Hz before the write and that the gate now holds until the switch ends (~2.5 s) with no noise flash. A #449-style panel (50.002 Hz, rate=50.000 write) should also be checked to confirm that before write: reads exact and the fast exit is unchanged.

Thanks for the careful diagnostics and the clearly stated residue.

Automated review by Quint (Claude) of abddb5b. It reads the code, it does not build or run it; a maintainer reviews and merges.

Comment thread Sources/AetherEngine/AetherEngine.swift Outdated
// AE#950: the panel's cadence before the criteria write, so the play gate can tell a rate the panel
// already ran from one it had to switch to. Runs across the probe, `apply()` reads and stops it.
if options.engineWritesDisplayCriteria { displayCriteria.beginPreWriteCadence() }
defer { displayCriteria.endPreWriteCadence() }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: loads are not serialised. stopInternal bumps loadGeneration, and the older load unwinds when it next checks. Here is the sequence. Load A starts the sampler and suspends in its probe. Load B enters loadSession, and beginPreWriteCadence() does nothing because preWriteCadence != nil (it reuses A's sampler, which is fine). Then A's probe returns, A sees it was superseded and throws, and this defer invalidates the sampler B is still counting on. B's apply() then reads nil -> .unmeasured, so a switched SDR start takes the pre-#950 exact-rate exit again. The fallback is safe (it matches main), but rapid zapping is where it would show. One fix: have beginPreWriteCadence() return an ownership token (a counter), and make endPreWriteCadence(token:) stop the sampler only when the token is still current. The newer load's begin would take over the existing sampler by bumping the counter.

…e reading (#950 review)

Quint found two nits on #952: the superseded load's defer could stop the
sampler a newer load relied on, which sent the newer write back to the
old fast exit, and the changelog's 6 s cap holds for VOD only. Each load
now owns its reading by token, a newer load replaces the older one's,
and the changelog names both caps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SeT6NgupsgTSme7g6RFnE5

@quint-aether quint-aether Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review

Status: 🟢 Clean. Nothing left to fix, ready for a maintainer.

The PR samples the panel's cadence across the probe and keys that reading to the write's arm generation, so an SDR write the panel had to switch to waits for the end of the switch instead of taking the #449 exact-rate exit. The fix is in the engine and addresses the cause.

Findings

  • Both nits from the last review are fixed. beginPreWriteCadence() now returns a token, and a superseded load's defer can no longer stop the sampler the newer load needs. The CHANGELOG now gives the cap as 6 s for VOD and says live keeps its 2 s cap.

No new findings. When a newer load arrives, its fresh sampler may not have ticked by the time it writes the criteria. The reading is then .unmeasured and the gate takes the pre-#950 path, which is the safe fallback the PR describes.

Checklist: CHANGELOG yes, docs n.a., tests yes (pure policy; the sampling and the generation keying need a device), traits both ways n.a.

Needs a device run: the reporter's LG C2 retest. It should confirm that before write: reads 50 Hz and that the gate holds until the switch ends (~2.5 s) with no noise flash. A #449-style panel should also be run to confirm the reading is exact and the fast exit is unchanged.

Thanks for the quick follow-up on the token handoff.

Automated review by Quint (Claude) of 81e7dff. It reads the code, it does not build or run it; a maintainer reviews and merges.

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