Skip to content

fix(mcp): bound the pairing approval window so its sizing cannot raise on launch - #2933

Merged
datlechin merged 1 commit into
mainfrom
fix/pairing-approval-sheet-sizing
Sep 16, 2026
Merged

datlechin merged 1 commit into
mainfrom
fix/pairing-approval-sheet-sizing

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #2930.

Root cause

AlertHelper.runHostedDecision measured its SwiftUI root with an unbounded height proposal while sizingOptions = []:

host.sizingOptions = []
let fitted = host.sizeThatFits(in: NSSize(width: fittingWidth, height: CGFloat.greatestFiniteMagnitude))
host.view.frame = NSRect(origin: .zero, size: fitted)
let sheetWindow = ModalDecisionWindow(contentViewController: host)   // raises here

PairingApprovalSheet's root is a Form(.grouped) closed by only a minHeight. A SwiftUI scroll container is greedy along its scroll axis, so it hands the whole proposal back. Measured:

fitted = (520.0, 1.7976931348623157e+308)
host.view.frame = (0.0, 0.0, 520.0, 35184372088832.0)
NSInternalInconsistencyException: Invalid parameter not satisfying:
  CGRectContainsRect(CGRectMake((CGFloat)INT_MIN, (CGFloat)INT_MIN,
  (CGFloat)INT_MAX - (CGFloat)INT_MIN, (CGFloat)INT_MAX - (CGFloat)INT_MIN), frame)

That raise is not contained. It happens inside the @MainActor job AppLaunchCoordinator.drain() starts, and swift_job_runImpl pops its ExecutorTrackingInfo with a bare trackingInfo.leave() after the job body, with no RAII and no unwind cleanup, on a stack local whose address is in a thread-local slot. Unwinding skips it, AppKit swallows the exception at the run-loop boundary, and the main thread is left with a dangling executor.

Swift 6.2 then turns that into a segfault. swift_task_isMainExecutorImpl is now:

HeapObject *identity = executor.getIdentity();
return executor.hasSerialExecutorWitnessTable() &&
       _swift_task_isMainExecutorSwift(identity, swift_getObjectType(identity), ...);

It dereferences the identity. In 6.1 it was swift_executor_getIdentity(executor) == (SwiftHeapObject *)&_dispatch_main_q, a pointer compare, so the same corruption was silent. So the next Swift 6 main-actor isolation check anywhere on the main thread crashes, and which one is incidental: the reporter got AppKit's delayed toolbar validation calling -[MainWindowToolbar validateToolbarItem:], my local reproduction got the sheet's own one-second timer.

The runtime deref is an Apple regression with no fix on swift main or release/6.3; it is reported separately. The raise is ours, and it is the only fixable link.

Evidence

The crash report symbolicates against /Applications/TablePro.app, whose Mach-O UUID matches the .ips slice_uuid exactly. Crash PC +0xF7ADF0 disassembles to the instruction after bl _swift_task_isCurrentExecutor in the compiler-generated @objc MainActor preamble, so self is never touched and a deallocated toolbar cannot be the cause. The faulting pointer handed to swift_getObjectType is a main-thread stack address 0x4b0 above sp.

The report also carries a HIServices SOME_OTHER_THREAD_SWALLOWED_AT_LEAST_ONE_EXCEPTION thread created 162 ms before the crash.

A standalone C probe that writes a fake tracking info with a stack-address identity into the main thread's tracking-info TLS slot and then calls the real swift_task_isCurrentExecutor reproduces the crash at identical symbol offsets (swift_getObjectType+204 / swift_task_isMainExecutorImpl+36 / isMainExecutor()+24 / isCurrentExecutorWithFlagsImpl+72). A clean slot and a valid tracking info both return 1.

What changed

ModalDecisionWindowSizing (new, in ModalDecisionGate.swift) owns the bound. runHostedDecision now resolves the parent window before measuring, so the budget comes from the screen the decision actually lands on rather than from NSScreen.main (pairing always passes window: nil). The screen's visibleFrame bounds the window, so contentBudget(within:styleMask:) converts it through NSWindow.contentRect(forFrameRect:styleMask:) and the content gets what is left after the titlebar. The fitted size is then clamped with min(). An isFinite guard would not have caught this, because CGFloat.greatestFiniteMagnitude.isFinite is true.

This follows QuickSwitcherPanel.swift:12-15, which already proposed a screen-bounded size; AlertHelper was the only site in the app proposing .greatestFiniteMagnitude to a hosting controller.

sizingOptions = [] stays. It is the firewall that keeps hosted content from pinning the window's split dividers (#1872), and measured, it also makes preferredContentSize inert: a window built from a hosting controller with only preferredContentSize set comes out 1x32, the same as setting nothing. So the size has to be measured and written.

PairingApprovalSheet caps the one greedy child (.frame(maxHeight: 420) on the Form) instead of fixing the sheet's own height, so the rest of the sheet still grows with the text size. Measured: unbounded proposal INFINITE before, 593.0 after, and 611.0 with a taller header.

The windowless arm no longer runs a nested modal loop. NSApp.runModal(for:) was called synchronously from inside the async job that routes the deep link, which nested an AppKit event loop inside a Swift concurrency job. Both arms now resolve through await gate.value(). This was previously unreachable on the reported path because the crash pre-empted it, so the sizing fix alone would have made it live for the first time.

The trade is worth naming: the detached arm is no longer application-modal, so the menu bar stays live while the decision is pending. Nothing else opens a window during it (AppLaunchCoordinator.drain() is serialized and finishStartupIfNeeded runs after it), approval still needs an explicit click on the gate-backed button, and Escape and window close both cancel. The one real consequence is that a titled decision window would otherwise qualify as a sheet parent for the next alert, so isContentWindow now excludes ModalDecisionWindow: no alert can open as a sheet on the consent dialog it is asking about.

Two consent defects in the same flow, found while investigating:

  • The approval sheet never showed where the one-time code goes. PairingRequest.redirectDisplayValue existed for exactly that and was referenced nowhere, so the only thing on screen was the client name the request chose for itself. A page can open tablepro://integrations/pair?client=Raycast&challenge=…&redirect=someotherapp://cb&scopes=fullAccess and the sheet reads "Allow Raycast to access TablePro?" with nothing naming the destination. The sheet now shows it, truncated in the middle so the scheme and host stay readable, and the client name is line-limited.
  • DeeplinkParser.parsePair dropped unreadable connection-ids with compactMap and then collapsed an empty result to nil, which means "all connections" at PairingApprovalSheet.swift:35 and :216. A request scoped to one connection opened pre-ticked to every connection. Presence of the parameter is now the test rather than a non-empty value, and empty fields are kept rather than dropped, so connection-ids=, connection-ids=,, and one bad entry among good ones all refuse the link instead of widening it.

Before / After

There is no before shot: on main the app dies before anything is drawn, so the sheet has never appeared on this path. After, from a cold launch driven by the deep link. The new line under the heading is the delivery address, and the permission level is the scopes=readWrite the link asked for.

The pairing approval window, headed Allow Raycast to access TablePro, showing the delivery address, a permission level picker set to Read and Write, a connections picker and an expiration picker

Verified

  • verify.sh build PASS, test PASS (132 cases), lint PASS (0 violations over the 6 changed Swift files), docs PASS.
  • End to end: on main, cold-launching the Debug build with open -n -a TablePro.app "tablepro://integrations/pair?…" produced two EXC_BAD_ACCESS at 0x1e crash reports with the same runtime frames and symbol offsets as the issue. On this branch the same launch reaches the approval window (AXStandardWindow, 520 x 625) and no crash report is produced.
  • Mutation check: reverting PairingApprovalSheet.swift and DeeplinkParser.swift to main and re-running the two new suites fails 7 cases, the 3 sheet-sizing ones and the 4 parser ones, while the 10 that exercise the new clamp still pass.

New tests: ModalDecisionWindowSizingTests (the clamp fed greatestFiniteMagnitude specifically, the real sheet measured with no bound, a very long client name, and that the fixed-size sibling root is unaffected) and DeeplinkPairParsingTests, since there were no tests over parsePair at all.

No TableProUITests coverage: the flow needs a cold launch driven by a URL-scheme Apple Event, which XCUITest cannot deliver, and the windowless arm is chosen by whether any titled window is visible at that instant.

The approval sheet gained a line, so docs/images/mcp-pairing-approval-sheet.png and its dark twin are now stale and need re-capturing in both appearances at the 1560x960 the other shots use.

@mintlify

mintlify Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
TablePro 🟢 Ready View Preview Sep 16, 2026, 6:46 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@datlechin
datlechin merged commit 73d0a8d into main Sep 16, 2026
9 of 13 checks passed
@datlechin
datlechin deleted the fix/pairing-approval-sheet-sizing branch September 16, 2026 20:06

This branch was successfully deployed

1 active deployment
staging - docs — db6657dc Deployed Sep 16, 2026 by mintlify[bot]
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.

Crash on cold launch via "Pair with TablePro" from Raycast extension (SIGSEGV, freed executor in Swift Concurrency)

1 participant