Skip to content

macOS runner aborts in CGS_REQUIRE_INIT on the first synthesized event with Xcode 27.2 (XCTDisplayInterface → SLSGetDisplaysWithRect) #4142

Closed

Description

@SamuelFranks

Note

🤖 Opus 5.5 responding on behalf of Sam

Summary. With Xcode 27.2, the macOS runner aborts on the first event it synthesizes in a fresh runner process (a click, coordinate tap, fill or scroll):

Assertion failed: (did_initialize), function CGS_REQUIRE_INIT, file CGInitialization.c, line 44.

The CLI then reports Error (COMMAND_FAILED): fetch failed. snapshot -i and get text keep working. Connecting the runner process to the window server in RunnerTests' class setUp fixes it locally (patch below).

Environment

  • agent-device 0.21.15, --platform macos, target app Brave Browser (Chromium)
  • Xcode 27.2 (27B52); xcodebuild -checkFirstLaunchStatus exits 0
  • macOS 26.6.2 (25G83), Apple silicon

I haven't tried 0.21.35. The release notes for 0.21.16–0.21.35 don't mention this, and a code search of main found no NSApplication warm-up in the runner tests.

Repro

  1. agent-device open "Brave Browser" --platform macos
  2. agent-device snapshot -i works.
  3. agent-device click @eN on any element. runner.log:
Tap "<window title>" Window[0.00, 0.00] -> (452.0, 114.0)
    Find the "<window title>" Window
    Check for interrupting elements affecting "<window title>" Window
    Synthesize event
Assertion failed: (did_initialize), function CGS_REQUIRE_INIT, file CGInitialization.c, line 44.

Crashed thread (AgentDeviceRunnerUITests-Runner crash report, EXC_CRASH SIGABRT):

libsystem_kernel.dylib   __pthread_kill
libsystem_pthread.dylib  pthread_kill
libsystem_c.dylib        abort
libsystem_c.dylib        __assert_rtn
SkyLight                 SLSGetDisplaysWithRect
SkyLight                 SLGetDisplaysWithRect
XCTAutomationSupport     static XCTDisplayInterface.allDisplayIDs(containing:)
XCTAutomationSupport     static XCTDisplayInterface.firstDisplayID(containing:)
XCTAutomationSupport     -[XCElementSnapshot displayID]
XCUIAutomation           +[XCUIElement(XCUIElementEventSynthesis) _dispatchEventWithEventBuilder:eventSynthesizer:…]

Observations

  • A runner process started before Xcode 27.2 was installed kept pressing.
  • Every runner started after the install crashed on its first synthesized event, with one exception: a run where a system dialog was on screen and XCTest's UI-interruption handling ran before the synthesis. So the crash seems to depend on whether anything has connected the runner process to the window server before the first event.
  • Rebuilding the runner from an empty cache (prepare ios-runner --platform macos) didn't change it.
  • Another project hit the same assert on Xcode 27 and fixed it the same way: Run UI tests on a GitHub-hosted Mac perezstudio/axo-browser#90 ("the UI test runner has no NSApplication. A fresh runner whose first test starts with a key press crashed in CGS_REQUIRE_INIT, so each UI test class now connects it to the window server in class setUp.")

Local patch

In dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift, after the instance setUp(). AppKit is already imported on macOS.

#if os(macOS)
  override class func setUp() {
    super.setUp()
    MainActor.assumeIsolated { _ = NSApplication.shared }
  }
#endif

After the rebuild (the runner cache key changed with the source), a click, a fill and a scroll on Brave all worked: 5 synthesized events, no assert. At startup the patched runner also logs a few [Connection] Unable to get synchronousRemoteObjectProxy and Unable to re-register with Process Instance Registry lines, which didn't affect any command.

The opt-in native macOS backend (ADR 0031) avoids XCTest altogether, but XCTest is still the default macOS backend. Would you consider adding this, or an equivalent window-server connection, to the macOS runner?

Activity

  1. added
    bug
    on Nov 2, 2026
  2. thymikee commented on Nov 2, 2026

    @thymikee
    Member

    Triage: bug; actionable without more input from you. Confirmed on main: the macOS UI-test runner never touches NSApplication.shared, so with Xcode 27.2 the first synthesized event reaches SLSGetDisplaysWithRect before the process is connected to the window server. A class-level setUp that connects it, as in your patch, is the intended fix. Thanks for the crash stack and the interruption-handler observation; that explains why some runs pass. Please also upgrade from 0.21.15; the fix will land on top of 0.21.35.

  3. added
    in-progress
    on Nov 2, 2026
  4. thymikee commented on Nov 2, 2026

    @thymikee
    Member

    An agent is picking this up; the PR will link here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugin-progressready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions