Repository navigation
fix(mcp): bound the pairing approval window so its sizing cannot raise on launch - #2933
Merged
Merged
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2930.
Root cause
AlertHelper.runHostedDecisionmeasured its SwiftUI root with an unbounded height proposal whilesizingOptions = []:PairingApprovalSheet's root is aForm(.grouped)closed by only aminHeight. A SwiftUI scroll container is greedy along its scroll axis, so it hands the whole proposal back. Measured:That raise is not contained. It happens inside the
@MainActorjobAppLaunchCoordinator.drain()starts, andswift_job_runImplpops itsExecutorTrackingInfowith a baretrackingInfo.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_isMainExecutorImplis now: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
swiftmainorrelease/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.ipsslice_uuidexactly. Crash PC+0xF7ADF0disassembles to the instruction afterbl _swift_task_isCurrentExecutorin the compiler-generated@objcMainActor preamble, soselfis never touched and a deallocated toolbar cannot be the cause. The faulting pointer handed toswift_getObjectTypeis a main-thread stack address0x4b0abovesp.The report also carries a
HIServices SOME_OTHER_THREAD_SWALLOWED_AT_LEAST_ONE_EXCEPTIONthread 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_isCurrentExecutorreproduces 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, inModalDecisionGate.swift) owns the bound.runHostedDecisionnow resolves the parent window before measuring, so the budget comes from the screen the decision actually lands on rather than fromNSScreen.main(pairing always passeswindow: nil). The screen'svisibleFramebounds the window, socontentBudget(within:styleMask:)converts it throughNSWindow.contentRect(forFrameRect:styleMask:)and the content gets what is left after the titlebar. The fitted size is then clamped withmin(). AnisFiniteguard would not have caught this, becauseCGFloat.greatestFiniteMagnitude.isFiniteistrue.This follows
QuickSwitcherPanel.swift:12-15, which already proposed a screen-bounded size;AlertHelperwas the only site in the app proposing.greatestFiniteMagnitudeto 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 makespreferredContentSizeinert: a window built from a hosting controller with onlypreferredContentSizeset comes out 1x32, the same as setting nothing. So the size has to be measured and written.PairingApprovalSheetcaps the one greedy child (.frame(maxHeight: 420)on theForm) instead of fixing the sheet's own height, so the rest of the sheet still grows with the text size. Measured: unbounded proposalINFINITEbefore,593.0after, and611.0with a taller header.The windowless arm no longer runs a nested modal loop.
NSApp.runModal(for:)was called synchronously from inside theasyncjob that routes the deep link, which nested an AppKit event loop inside a Swift concurrency job. Both arms now resolve throughawait 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 andfinishStartupIfNeededruns 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, soisContentWindownow excludesModalDecisionWindow: 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:
PairingRequest.redirectDisplayValueexisted for exactly that and was referenced nowhere, so the only thing on screen was theclientname the request chose for itself. A page can opentablepro://integrations/pair?client=Raycast&challenge=…&redirect=someotherapp://cb&scopes=fullAccessand 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.parsePairdropped unreadableconnection-idswithcompactMapand then collapsed an empty result tonil, which means "all connections" atPairingApprovalSheet.swift:35and: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, soconnection-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
mainthe 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 thescopes=readWritethe link asked for.Verified
verify.sh buildPASS,testPASS (132 cases),lintPASS (0 violations over the 6 changed Swift files),docsPASS.main, cold-launching the Debug build withopen -n -a TablePro.app "tablepro://integrations/pair?…"produced twoEXC_BAD_ACCESS at 0x1ecrash 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.PairingApprovalSheet.swiftandDeeplinkParser.swifttomainand 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 fedgreatestFiniteMagnitudespecifically, the real sheet measured with no bound, a very long client name, and that the fixed-size sibling root is unaffected) andDeeplinkPairParsingTests, since there were no tests overparsePairat all.No
TableProUITestscoverage: 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.pngand its dark twin are now stale and need re-capturing in both appearances at the 1560x960 the other shots use.