Skip to content

fix(airplay): every session-preserving rebuild holds the external-playback edge (#227 round 2) - #562

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/hold-airplay-edge-on-every-rebuild
Sep 19, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/hold-airplay-edge-on-every-rebuild

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Found while working Sodalite#156 (the iOS remote view). Reported by Vincent as "switching the audio language during AirPlay reconnects and restarts the title"; the reconnect half is measured and fixed here.

The asymmetry

#227 established that an external-playback edge arriving mid-rebuild describes the teardown, not the route, and must be held until the rebuilt item settles. That hold was put on exactly one rebuild, reloadAtCurrentPosition's URL branch. Three others go without it, all through reloadWithAudioOverride:

  • the audio pick (selectAudioTrack)
  • the disc-title pick (selectTitle)
  • reloadAtCurrentPosition's own custom-source branch, which returns before the flag is set

What it costs, from the device log (2026-09-19, iPhone 17 Pro to Apple TV)

The log shows the two paths side by side. The audio rebuild:

18.165  [AirPlay] external playback active=false        <- no hold
18.183  serving on http://127.0.0.1:64632/...
18.185  #3 load url=http://127.0.0.1:64632/...
18.212  [AirPlay] external playback active=true
18.215  [AirPlay] external playback active (wireless) -> LAN reload

and the reloadAtCurrentPosition it triggered:

18.400  [AirPlay] external playback active=false
18.402  [AirPlay] ... holding the edge until the rebuilt item settles
18.459  [AirPlay] external playback active=true
18.462  [AirPlay] ... holding the edge until the rebuilt item settles
18.548  [AirPlay] reconciling the held edge after the reload: active=true

The unheld false cleared airPlayActive before loadNative read it, so the pick rebuilt the session on 127.0.0.1:64632, an address a receiver cannot reach. The Apple TV (10.20.30.12) never requested that port at all; it appears only against the second session on 64638. One audio pick, two full session rebuilds, the first dead on arrival for the receiver.

The fix

The hold moves into the shared funnel, so all three rebuilds inherit it. Both sites now restore the flag instead of clearing it, and only the outermost rebuild reconciles: a nested one that reconciled would start a reload inside the teardown of the rebuild still running, which is #227's loop reached from the inside rather than from the KVO.

Tests

The invariant is structural (WHERE the hold is raised), so the test is structural too, the shape Issue541ReloadCarriesHDRRouteTests already uses to pin a reload call site. Both source-level tests were run against the pre-fix sources first and are red there:

AetherEngine.swift: clears=2 declares=1 -> restore test RED
AetherEngine+Loading.swift: funnel raises hold=False reconciles=False -> funnel test RED

Full suite, both runners: swift-testing 3104 tests in 423 suites, XCTest 17 tests, 0 failures.

Not covered

The reporter also saw a title restart at its head after a pick. That is no longer reproducible, which fits a race rather than a deterministic fault: positionForSessionRebuild returns the parked position only while state == .loading, and the stacked second rebuild this fix removes is what opens that window. Removing the window makes it likely to be gone, but that is reasoning, not a measurement, and it is not claimed as fixed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F

…yback edge (#227 round 2)

#227 put the edge hold on one rebuild, `reloadAtCurrentPosition`'s URL branch.
The other three went without it: the audio pick, the disc-title pick, and that
same function's custom-source branch, all of which rebuild through
`reloadWithAudioOverride`. Every rebuild tears down the item the
external-playback KVO watches, so every one of them raises a `false` edge that
describes the teardown and not the route.

Measured on an AirPlay route, device log 2026-09-19 (Sodalite#156). The
asymmetry is visible in the log itself: no "holding the edge" line during the
audio rebuild, two of them during the reloadAtCurrentPosition that followed it.
The unheld `false` cleared `airPlayActive` before `loadNative` read it, so the
pick rebuilt the session on 127.0.0.1, which a receiver cannot reach. The Apple
TV never requested that port at all. The receiver then re-engaged and the true
edge paid for a SECOND full rebuild to get back onto the LAN URL: one audio
pick, two session rebuilds, the first dead on arrival.

The hold is now raised in the shared funnel, so the three rebuilds that go
through it inherit it. Both sites restore the flag rather than clearing it, and
only the outermost rebuild reconciles: a nested one that reconciled would start
a reload inside the teardown of the rebuild still running, which is #227's loop
reached from the inside instead of from the KVO.

The invariant is structural, so the test is too, the shape
Issue541ReloadCarriesHDRRouteTests already uses to pin a reload call site. Both
new source-level tests were checked against the pre-fix sources and are red
there.

Not covered by this: the reporter also saw a title restart at its head after a
pick, which is no longer reproducible. It fits a race this stacked second
rebuild opens (`positionForSessionRebuild` returns the parked position only
while state is .loading), and removing the second rebuild removes the window,
but that is reasoning, not a measurement.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015PM3xUJB6ZQyqnmGK1fp6F
@superuser404notfound
superuser404notfound merged commit e57a569 into main Sep 19, 2026
7 checks passed
@superuser404notfound
superuser404notfound deleted the fix/hold-airplay-edge-on-every-rebuild branch September 19, 2026 14:25
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