Skip to content

Recovery paths must not read AVPlayer on the main actor (#422) - #425

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/ae422-main-actor-player-reads
Aug 25, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/ae422-main-actor-player-reads

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

The 13.3 s main-thread block @rrgomes measured, and the audit it prompted.

The rule that existed but was not applied

AVFoundationOffMain has carried the reason since #134: these getters are synchronous XPC round trips to mediaserverd, and "on the main actor a momentarily busy media server turns any of them into a fully blocked main thread and, past the watchdog threshold, a process kill". Only the 30 s memory probe used it. The paths that run precisely BECAUSE the server is not answering read the player directly.

path reads per pass now
seek-deadline loop 1 island + 3 bufferedEnd one batched seekBufferSnapshot, off-main
stall nudge / item reload currentTime() at the call site and again inside renderedPositionMirror
VOD shift-publish line avPlayerBufferAheadSeconds() awaited off-main
premature-end recovery (#287) playhead + seekable + loaded one batched reading

The seek-deadline loop is the sharpest of these: it runs while a seek is not landing, which is exactly the state the block was measured in, and it was taking four round trips per pass.

The mirror is also the right value

recoveryAnchorPosition(currentRendered:) exists to keep a recovery anchor from sitting below the frame already on screen (#115). currentTime() is the clock, and the clock diverges from the rendered frame during exactly the landing these paths run in (#123). The wedge path was already passing the mirror; the stall watchdog beside it was reading the player. So this is a correctness fix as much as a threading one.

Left alone on purpose

The reads inside load() and the seek completion. Both run at a moment where AVPlayer has just answered.

A property nobody had written down

Taking the reads off the main actor took the logic out with them: bufferedEnd was a @MainActor property wrapped around a blocking round trip, so its rule had no test at all. contiguousBufferedEnd is pure now and has eight. One of them records something the old shape hid: ranges are judged against the playhead rather than against the running end, so [100,152] and [152,170] do not chain and the figure understates the buffer. Recorded rather than changed, because seekIsWedged reads an understated buffer as starvation, and that deserves its own measurement.

Verification

2078 tests green. seektest reports the same tallies and the same settleError as before the change, and a --picture-probe run is unchanged. The block itself needs a wedged media server and can only be confirmed on the reporting setup.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbWZLwBVLGM1xUVXa9NeJ1

…422)

AVPlayer's figplayer-backed getters are synchronous XPC round trips to
mediaserverd. AVFoundationOffMain has carried that warning since #134, including
what it costs ("past the watchdog threshold, a process kill"), but only the 30 s
memory probe ever hopped off. The paths that run precisely BECAUSE the media
server is not answering read it straight from the main actor.

The reporter measured the consequence on macOS: currentTime() from a host's main
actor did not return for 13.3 s during a consumer wedge, returning 30 ms after
the re-engage watchdog fired, with the app blocked throughout.

  seek-deadline loop     4 round trips per pass -> one batched seekBufferSnapshot
  stall nudge / reload   currentTime() twice    -> renderedPositionMirror
  VOD shift-publish line avPlayerBufferAhead()  -> awaited off-main
  premature end (#287)   3 witnesses            -> one batched reading

For the recovery anchors the mirror is not just the non-blocking choice, it is
the correct value. recoveryAnchorPosition(currentRendered:) exists to keep the
anchor from sitting below the frame on screen (#115), and currentTime() is the
clock, which diverges from the rendered frame during exactly the landing these
run in (#123). The wedge path was already passing the mirror; the stall watchdog
beside it was reading the player.

Left synchronous on purpose: the reads inside load() and the seek completion.
Both run at a moment where AVPlayer has just answered.

Taking the reads out of the main actor also took the logic out with them.
bufferedEnd was a @mainactor property wrapped around a blocking round trip, so
its rule had no test; contiguousBufferedEnd is pure and now has eight. One of
them records a property nobody had written down: ranges are judged against the
playhead rather than against the running end, so two adjacent ranges do not
chain and the figure understates the buffer. Recorded, not changed, because
seekIsWedged reads an understated buffer as starvation and that deserves its own
measurement.

2078 tests green. seektest reports the same tallies and the same settleError as
before, and a picture-probe run is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01RbWZLwBVLGM1xUVXa9NeJ1
@superuser404notfound
superuser404notfound merged commit ee8780f into main Aug 25, 2026
4 checks passed
@superuser404notfound
superuser404notfound deleted the fix/ae422-main-actor-player-reads branch September 4, 2026 06:57
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