Skip to content

Defer browser view hierarchy mutations to prevent Auto Layout recursion - #662

Closed
lawrencecchen wants to merge 1 commit into
mainfrom
issue-653-autolayout-crash
Closed

lawrencecchen wants to merge 1 commit into
mainfrom
issue-653-autolayout-crash

Conversation

@lawrencecchen

Copy link
Copy Markdown
Contributor

Summary

  • macOS 26 Tahoe enforces stricter Auto Layout validation, crashing with EXC_BREAKPOINT when addSubview/removeFromSuperview is called during a layout pass
  • Wraps attach/detach/dismantle view hierarchy mutations in scheduleDeferredHierarchyMutation (DispatchQueue.main.async) with generation guards to prevent stale mutations
  • Adds regression test that rapidly switches between browser and terminal workspaces 120 times

Closes #653

Test plan

  • Switch between browser-active and terminal workspaces rapidly on macOS 26
  • Verify no crash (was EXC_BREAKPOINT/SIGTRAP previously)
  • Verify browser panels still attach/detach correctly during normal tab switching
  • Verify DevTools restoration still works after workspace switch

macOS 26 enforces stricter Auto Layout validation and crashes with
EXC_BREAKPOINT when addSubview/removeFromSuperview is called during a
layout pass. Wraps attach/detach/dismantle mutations in
scheduleDeferredHierarchyMutation (DispatchQueue.main.async) with
generation guards to prevent stale mutations.

Closes #653
@vercel

vercel Bot commented Feb 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cmux Building Building Preview, Comment Feb 28, 2026 1:30am

@coderabbitai

coderabbitai Bot commented Feb 28, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@lawrencecchen has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c5f7496 and 14ad5a1.

📒 Files selected for processing (3)
  • Sources/Panels/BrowserPanelView.swift
  • tests/test_browser_panel_stability.py
  • tests_v2/test_browser_panel_stability.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-653-autolayout-crash

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR successfully addresses macOS 26 Tahoe's stricter Auto Layout validation by deferring view hierarchy mutations (addSubview/removeFromSuperview) using DispatchQueue.main.async. The implementation uses generation guards to prevent stale mutations and properly cancels pending operations during state transitions.

Key changes:

  • Added scheduleDeferredHierarchyMutation helper that wraps hierarchy changes in async blocks with cancellation support
  • Deferred all attach, detach, and dismantle operations that modify the view hierarchy
  • Generation counter increments prevent stale deferred mutations from executing after coordinator state changes
  • Comprehensive regression test validates the fix with 120 rapid workspace switches

Implementation quality:

  • Thread safety: All mutations properly dispatched to main queue with DispatchQueue.main.async (follows project threading guidelines)
  • Memory safety: Weak references to views prevent retain cycles, coordinator strongly captured to maintain generation guard integrity
  • Cancellation: Deferred mutations cancelled appropriately when scheduling retries, entering portal mode, or dismantling
  • Testing: Regression test thoroughly exercises the crash path with rapid workspace switching

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk after testing on macOS 26
  • The implementation is solid with proper generation guards, thread safety, and weak references. The one minor suggestion is for consistency in the retry path. The fix directly addresses a critical crash and includes comprehensive regression testing.
  • Verify Sources/Panels/BrowserPanelView.swift works correctly on macOS 26 Tahoe by running the regression test and manual workspace switching

Important Files Changed

Filename Overview
Sources/Panels/BrowserPanelView.swift Added deferred hierarchy mutation mechanism to prevent Auto Layout recursion crashes on macOS 26. Wraps view attach/detach operations in DispatchQueue.main.async with generation guards.
tests/test_browser_panel_stability.py Added regression test that rapidly switches between browser-active and terminal workspaces 120 times to verify the Auto Layout fix works correctly.
tests_v2/test_browser_panel_stability.py Duplicate of tests/test_browser_panel_stability.py with identical workspace switching regression test.

Last reviewed commit: 14ad5a1

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

Sources/Panels/BrowserPanelView.swift
For consistency with immediate attach path (line 3561), consider wrapping in scheduleDeferredHierarchyMutation to ensure deferred execution even in retry path.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch was successfully deployed

1 active deployment
Preview — 14ad5a1c Deployed Feb 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale-revisit Closed after 30+ days without activity; preserved for possible revisit or reopening.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when switching tabs in vertical tab mode (Auto Layout recursion, macOS 26.0.1)

2 participants