Skip to content

fix(display): in-flight switch end no longer settles a new write; real rate switch holds for the sink (#950) - #1003

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/950-inherited-end
Nov 8, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/950-inherited-end

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Round 2 of #950 (reporter retest on 7.58.0, Apple TV 4K 3rd gen, LG C3).

  • Restart within ~2 s of stop: the write landed while the reset's switch back to 50 Hz was running, and that switch's modeSwitchEnd settled the gate at 50.001 Hz. apply() now records whether a switch was in flight at the write (SET: ... a switch already in flight). A gate with no start notification since such a write waits that switch out, removes its end from the record, and gives the write's own switch the full 1000 ms start grace ([DisplayCriteria] #950: a switch was in flight at the write ...).
  • Noise after a correct end (1 start in 4): an engine rate-only write whose panel read another rate before it now holds rateSwitchSinkSettleMs (1000 ms, measured from the end) after modeSwitchEnd or the flag clearing, for sinks that re-lock after tvOS reports the end.

Tests: Issue950RateSwitchRelockTests (+3). Full suite green (5795 swift-testing, 833 XCTest), tvOS build green. /code-review low over the commit: no findings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SeT6NgMt1vv32kPBhUmsUz

…, and a real rate switch holds for the sink (#950)

Round 2 from the reporter on 7.58.0 (Apple TV 4K 3rd gen, LG C3):

- A restart within ~2 s of stop() wrote its criteria while the reset's switch
  back to 50 Hz was still running. The write announced no start of its own,
  and the reset's modeSwitchEnd settled the gate with the panel at 50.001 Hz.
  apply() now records whether a switch was in flight at the write; a gate
  with no start since such a write waits that switch out, takes its end off
  the record and gives the write's own switch the full 1000 ms start grace.
- One fresh start in four still flashed pink noise after a correctly observed
  modeSwitchEnd, with identical engine logs for clean and noisy starts.
  tvOS posts the end before every sink has re-locked, so an engine rate-only
  write whose panel read another rate before it now holds 1000 ms after the
  end (measured from the end) before releasing play.

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

@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: 🟠 Needs changes. Real issues to fix before merge.

This is round 2 of #950. When a write lands while the reset's switch is still running, the gate now waits that switch out and keeps its end from settling the gate. After a real rate switch ends, an engine rate-only write also holds 1000 ms more for the sink to re-lock. The in-flight part goes after the cause and the direction is right. The 1000 ms hold is a fixed margin, so I have a question about who pays for it.

Findings

  • Should fix: The new wait can still be undone by a late end. It stops when the in-progress flag clears or when this write's own start shows up, and in both cases it takes a fresh snapshot at that moment. If the old switch's modeSwitchEnd is delivered after that snapshot, Stage 1 or Stage 2 reads it as a new end and settles the gate on the old switch. That is the 50 Hz release this PR is fixing (DisplayCriteriaController.swift:1168).
  • Question: rateSwitchSinkSettleMs adds 1000 ms to every engine rate-only start whose panel read a different rate before the write, on every sink. The evidence is one LG C3 flashing in one start of four. The .brief doc in this file says one panel is not grounds for making every session's cold start wait longer. Is the cost intended for all sinks? Is there a measurement that the panel is still dark during that second on sinks that locked cleanly? (DisplayCriteriaController.swift:666)
  • Housekeeping: CHANGELOG.md has no entry under [Unreleased]. Both behaviours are user-visible (the wrong-rate start after a quick restart, and the pink-noise flash). The second also changes startup time.

Checklist: CHANGELOG no, docs n.a., tests yes (pure helpers only; the stage-0 wait itself cannot be tested without a device), traits both ways n.a.

Needs a device run: The LG C3 restart within about 2 s of stop. Check that the gate now settles on this write's own end and not at 50.001 Hz. Also check that the 1000 ms hold stops the one-in-four flash, and what the hold costs at startup on a sink that never flashed.

Thanks for chasing this down to the exact ordering in the reporter's logs.

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

outcome = "ended via modeSwitchEnd after \(Self.elapsedMs(since: stage0Entry))ms"
break
}
if !displayManager.isDisplayModeSwitchInProgress {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This wait can stop before the old switch's end notification has arrived, and nothing guards against it arriving later.

  • Flag exit: isDisplayModeSwitchInProgress clearing is a different signal from modeSwitchEnd, and the notifications come in on an arbitrary queue. The flag can clear a few ms before the old switch's end is recorded. The snapshot at 1179 then still has the old endCount.
  • Then Stage 1: the late end makes observation.hasNewEnd(since: gateSnapshot) true, and the gate logs "settled during start phase" and returns. On the C3 that is the same release at 50 Hz this block exists to prevent.
  • Start exit: the same thing happens when the loop stops on hasNewStart (line 1160) before the old end arrives. Stage 2 then settles on the old end via hasNewEnd.

Suggested fix: when this block ran, accept an end in Stage 1 and Stage 2 only once this write has recorded its own start (observation.hasNewStart(since: gateSnapshot)). Do not accept an end on its own. Another option is to keep a flag that ignores the first end that arrives after this block, as long as no new start came before it.

return max(0, rateSwitchSinkSettleMs - msSinceEnd)
}

nonisolated static let rateSwitchSinkSettleMs = 1000

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Question: this margin applies to every engine rate-only write whose panel read .different before the write, so roughly every SDR start that changes the refresh rate, on every sink. The only evidence is one LG C3 flashing in one start of four, and the comment notes that the clean and the noisy logs were identical.

The doc comment says the cost is "paid only where the panel was dark anyway". After a modeSwitchEnd on a sink that has already locked, the panel is no longer dark, so that second is added startup time. It also cuts against the .brief note above ("one panel is not grounds for making every session's cold start wait longer").

If the cost is intended, please keep the measurement next to the constant: the release-to-flash timing, and whether a 1000 ms hold removed the flash on the C3. If it is not, the hold could start smaller, or be tied to evidence that the sink re-locks late, rather than applying everywhere.

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