Skip to content

fix: capture screen recordings on tvOS and in CDP attach mode - #5

Merged
DouweBos merged 4 commits into
mainfrom
maestro-tvos-recording-hang-4e8d33
Sep 3, 2026
Merged

DouweBos merged 4 commits into
mainfrom
maestro-tvos-recording-hang-4e8d33

Conversation

@DouweBos

@DouweBos DouweBos commented Sep 3, 2026 •

Copy link
Copy Markdown

Screen recording get-well: everything that was silently broken about capturing video, in one place. Four commits, each independently reviewable.

1. tvOS simulators never captured anything (fix(ios))

simctl io recordVideo takes --display, defaulting to internal. tvOS only supports external. screenrecord.sh never passed the flag, so on a tvOS simulator simctl was asked to record a display that does not exist: it never processed a first video frame, wrote nothing, and — in that pre-start state — did not respond to SIGINT. The script's wait never returned, stopScreenRecording's unbounded waitFor() blocked, and a suite stalled for 59 minutes with orphaned simctl processes and a 0-byte mp4.

Reproduces across Xcode 16.2–26.3 × tvOS 18.5/26.1/26.2. Newer simctl (26.5) masks it by auto-selecting a display, so it only fails on older toolchains.

Fix: pass --display external for tvOS simulators; iOS keeps simctl's default. The platform is plumbed from MaestroSessionManager (which already computes isTV(deviceId) to pick the driver bundle) into SimctlIOSDevice and on to startScreenRecording, falling back to the lookup only for callers that don't know. The external alias is deliberate — display names/IDs (--display TVOut, --display 2) are rejected by Xcode ≤ 26.3.

Verified end-to-end on a booted Apple TV 4K (tvOS 26.5): ffprobe reports 51 frames over 8.5s, recorder exits cleanly on SIGINT.

2. No teardown may block a suite forever (fix(ios))

The safety net, not the fix — but still correct whatever the cause.

  • stopScreenRecording waits with a timeout (2 min default, overridable), then warns and force-terminates the recorder and its descendants — ProcessHandle.descendants() collected before killing the parent, since killing only the bash script is what left orphaned xcrun/simctl in CI.
  • screenrecord.sh escalates itself: after kill -SIGINT it polls for 60s, then kill -KILL, so the moov atom gets a fair chance to flush first.
  • Normalization is skipped for an empty file and Mp4DurationNormalizer catches Throwable, so a truncated recording can't throw out of teardown.

(xcrun execs into simctl rather than forking, so signal targeting was never the problem.)

3. CDP attach mode recorded nothing (feat(web))

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron over CDP made startScreenRecording a no-op returning an empty file. It now drives Page.startScreencast over the raw CDP socket and feeds frames to the same encoder, acking each frame so Chrome's delivery gates on the consumer, and joining the screencast before finishing the encoder so no frame is mid-encode.

4. "Cannot record" handled uniformly (fix)

Drivers signalled it three different ways — TODO() (physical iOS via devicectl), error("Not supported") (XCTest), a silent no-op (CDP attach), plain exceptions (Roku, Vega) — so the same situation crashed, failed a flow, or produced an empty file depending on the platform. Now:

  • ScreenRecordingUnsupported (a typed UnsupportedOperationException in maestro-utils) is what drivers throw.
  • startRecording in a flow and the debug-bundle full-run recording skip with a warning/insight and delete the empty artifact — recording is incidental, it shouldn't fail the run.
  • maestro record fails with a clear CliError — recording is the entire point there.
  • Maestro.startScreenRecording no longer marks the session as recording before the driver succeeds; it used to leave the flag stuck, silently no-oping every later recording in the session.

Tests

  • ScreenRecordCommandTest — runs the real screenrecord.sh against a stub xcrun on PATH and asserts the command line: tvOS gets --display external, iOS gets none. Fails when the display selection is removed.
  • LocalSimulatorUtilsScreenRecordingTest — a recorder that traps INT/TERM and holds a child must not block stopScreenRecording and must leave no descendants. Hangs (build killed by timeout) against the old unbounded waitFor().
  • CdpScreencastTest — real WebSocket server standing in for DevTools: frames reach the consumer and each one is acked; a dead endpoint surfaces a failure instead of hanging.
  • MaestroScreenRecordingTest — a failed start doesn't disable later recordings (fails without the flag fix); a second concurrent recording stays a no-op.
  • IntegrationTest case 099 — a driver that can't record skips the recording, the flow still passes, and no empty mp4 is left (fails without the Orchestra catch).

./gradlew :maestro-ios-driver:test :maestro-client:test :maestro-web:test :maestro-orchestra:test :maestro-test:test :maestro-cli:compileKotlin is green.

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.
simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.
@DouweBos DouweBos changed the title fix(ios): bound simulator screen recording teardown fix(ios): record the external display on tvOS simulators Sep 3, 2026
WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.
Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
@DouweBos DouweBos changed the title fix(ios): record the external display on tvOS simulators fix: screen recording get well Sep 3, 2026
@DouweBos DouweBos changed the title fix: screen recording get well fix: capture screen recordings on tvOS and in CDP attach mode Sep 3, 2026
@DouweBos
DouweBos merged commit ccd6e9e into main Sep 3, 2026
18 checks passed
@DouweBos
DouweBos deleted the maestro-tvos-recording-hang-4e8d33 branch September 3, 2026 16:18
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
DouweBos added a commit that referenced this pull request Oct 9, 2026
* fix(ios): bound simulator screen recording teardown

simctl can ignore the SIGINT that stops recordVideo (seen on headless tvOS
simulators), and the unbounded waitFor in stopScreenRecording then hangs the
whole suite. Wait with a timeout and force-kill the recorder plus its
descendants on expiry, escalate to SIGKILL inside screenrecord.sh so the moov
atom still gets a chance to flush, and never let normalization throw out of
teardown.

* fix(ios): record the external display on tvOS simulators

simctl io recordVideo defaults to --display internal, which tvOS does not have,
so it never processed a frame, wrote no file, and ignored the SIGINT that stops
it - which is what wedged the recorder teardown. Pass --display external for
tvOS simulators, plumbing the platform down from the session manager, which
already knows it.

* feat(web): record the screen over CDP in attach mode

WebScreenRecorder is Selenium-backed, so attaching to a running Chrome/Electron
left startScreenRecording a silent no-op that produced an empty file. Drive
Page.startScreencast over the raw CDP socket instead and feed the frames to the
same encoder, acking each frame so Chrome's delivery gates on the consumer.

* fix: handle unsupported screen recording uniformly

Drivers signalled 'cannot record' three different ways - TODO(), error() and a
silent no-op - so the same situation crashed, failed a flow or produced an empty
file depending on the platform. Report it as ScreenRecordingUnsupported and let
each caller decide: flows and debug artifacts skip the recording with a warning
and no 0-byte file, while 'maestro record' fails with a clear message. Also stop
marking a session as recording before the driver actually started, which left
every later recording a silent no-op.
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