Fix re-entrant exclusive-access crash in drag handle hit test

Merged
LA
9mo ago
+61-0

Summary

Fixes https://github.com/manaflow-ai/cmux/issues/761.

SIGABRT crash caused by re-entrant calls to windowDragHandleShouldCaptureHit during the sibling hit-test walk. When sibling.hitTest() triggers a SwiftUI layout pass, AppKit calls back into the drag handle's hit resolution while the outer invocation is still walking siblings. This violates Swift's exclusive-access rules on SwiftUI view state.

The fix adds a module-level re-entrancy guard (_windowDragHandleIsResolvingSiblingHits) that bails out on nested calls to the sibling walk. Main-thread only, no lock needed.

Crash stack: DraggableView.hitTest -> windowDragHandleShouldCaptureHit -> sibling.hitTest -> SwiftUI body eval -> hitTest (re-entry) -> exclusive-access violation -> SIGABRT.

Test plan

  • Added testDragHandleSiblingHitTestReentrancyDoesNotCrash regression test that simulates the re-entrant call path
  • Existing drag handle tests continue to pass (same 4 pre-existing failures on main)
  • Reproduced on macOS Sequoia 15.1.1 VM, deployed fix, verified crash no longer occurs