Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1ae7e92
test: cover framework viewport callbacks
austinywang Oct 7, 2026
cd10be4
fix: avoid actor checks in browser framework callbacks
austinywang Oct 7, 2026
a8a5ccd
Merge main (a1ae4f9ae74e) into codex-17491-webkit-crash
austinywang Oct 7, 2026
6f9a7ff
fix: import os for browser routing lock
austinywang Oct 7, 2026
9d9c699
fix: close inherited actor checks in browser callbacks
austinywang Oct 7, 2026
fb0aee2
Merge main (3cab11d06dac) into codex-17491-webkit-crash
austinywang Oct 7, 2026
e52f9e7
fix: hop scheduler cancellation from AppKit callback
austinywang Oct 7, 2026
a16a42b
Merge main (7a5ff8674d11) into codex/pr18318-ci-repair
austinywang Oct 7, 2026
752d378
fix: hop WebKit script callbacks onto MainActor
austinywang Oct 7, 2026
2201404
fix: preserve synchronous browser cancellation contracts
austinywang Oct 7, 2026
68ea4e1
test: cover discard decisions during sleep notification delivery
austinywang Oct 7, 2026
fc40254
Merge branch 'codex-17491-webkit-crash' of https://github.com/manaflo…
austinywang Oct 7, 2026
693c93a
test: preserve navigation replacement ordering through panel callbacks
austinywang Oct 7, 2026
f752b91
fix: preserve ordering across browser callback boundaries
austinywang Oct 7, 2026
ceec671
fix: retain synchronous script and input delivery contracts
austinywang Oct 7, 2026
e5d1cf6
test: control watchdog deadlines in coordination scenarios
austinywang Oct 7, 2026
317e0ca
fix: inspect detached inspector ownership before teardown
austinywang Oct 7, 2026
dcf6b79
fix: preserve actor isolation for browser drop routing
austinywang Oct 7, 2026
2df958d
ci: record intentional Swift isolation warnings
austinywang Oct 7, 2026
19436dc
fix: preserve synchronous window key notifications
austinywang Oct 7, 2026
6336b99
test: cover dock configuration during divider drags
austinywang Oct 7, 2026
8153796
fix: defer inspector dock changes during divider drags
austinywang Oct 7, 2026
180778d
test: trigger dock configuration callback deterministically
austinywang Oct 7, 2026
116a5dc
test: keep bottom dock stable after divider drag
austinywang Oct 7, 2026
b6814d7
fix: keep bottom inspector dock inline after drag
austinywang Oct 7, 2026
1b534e4
Merge main (5d12d7b4087f) into codex/pr18318-ci-repair
austinywang Oct 7, 2026
f94fa48
fix: keep inspector replay on main actor
austinywang Oct 7, 2026
dcf985e
Merge main (1a64e24339b1) into codex/pr18318-ci-repair
austinywang Oct 7, 2026
80409a8
fix: preserve AppKit mouse-up executor boundary
austinywang Oct 7, 2026
dec0748
test: await render host key transition
austinywang Oct 7, 2026
782d792
Merge main (8aae7c01b0d9) into codex/pr18318-ci-repair
austinywang Oct 7, 2026
f08b8aa
fix: close remaining browser callback races
austinywang Oct 7, 2026
2291629
fix: preserve WebKit mobile callback executor hop
austinywang Oct 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
491 changes: 491 additions & 0 deletions .github/swift-warning-budget.tsv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public import Foundation
) -> CandidateLookupCancellation?

/// Registers a callback that dismisses any in-flight certificate picker.
public typealias PromptCancellationRegistration = (@escaping () -> Void) -> Void
public typealias PromptCancellationRegistration = @MainActor (@escaping @MainActor () -> Void) -> Void

/// Presents candidates and returns the selected candidate, or `nil` on cancellation.
public typealias CandidatePicker = (
Expand Down Expand Up @@ -69,11 +69,7 @@ public import Foundation
)
}
if let cancelLookup {
registerCancelPrompt {
MainActor.assumeIsolated {
cancelLookup()
}
}
registerCancelPrompt(cancelLookup)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

@MainActor final class BrowserClientCertificatePromptRequest {
typealias Completion = BrowserClientCertificateAuthenticationHandler.Completion
typealias PromptCancellation = () -> Void
typealias PromptCancellation = @MainActor () -> Void
typealias PromptCancellationRegistration = BrowserClientCertificateAuthenticationHandler.PromptCancellationRegistration
typealias PromptCancellationCheck = BrowserClientCertificateAuthenticationHandler.PromptCancellationCheck

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,36 @@ public final class BrowserDesignModeMessageHandler: NSObject, WKScriptMessageHan
let body = message.body as? [String: Any],
let type = body["type"] as? String else { return }
if type == "exit_requested" {
MainActor.assumeIsolated { [onExitRequested] in
onExitRequested()
}
Task { @MainActor [onExitRequested] in onExitRequested() }
return
}
if type == "prompt_reset" {
MainActor.assumeIsolated { [onPromptReset] in
onPromptReset()
}
Task { @MainActor [onPromptReset] in onPromptReset() }
return
}
if type == "interaction_mode_changed", let mode = body["mode"] as? String {
MainActor.assumeIsolated { [onInteractionModeChanged] in
onInteractionModeChanged(mode)
}
Task { @MainActor [onInteractionModeChanged] in onInteractionModeChanged(mode) }
return
}
if type == "annotation_drawing", let id = body["id"] as? String {
MainActor.assumeIsolated { [onAnnotationDrawing] in
onAnnotationDrawing(id)
}
Task { @MainActor [onAnnotationDrawing] in onAnnotationDrawing(id) }
return
}
if type == "annotation_cancelled", let id = body["id"] as? String {
MainActor.assumeIsolated { [onAnnotationCancelled] in
onAnnotationCancelled(id)
}
Task { @MainActor [onAnnotationCancelled] in onAnnotationCancelled(id) }
return
}
if type == "annotation_capture_requested",
let request = body["request"],
JSONSerialization.isValidJSONObject(request),
let data = try? JSONSerialization.data(withJSONObject: request) {
MainActor.assumeIsolated { [onAnnotationCaptureRequested] in
onAnnotationCaptureRequested(data)
}
Task { @MainActor [onAnnotationCaptureRequested] in onAnnotationCaptureRequested(data) }
return
}
guard type == "snapshot",
let snapshot = body["snapshot"],
JSONSerialization.isValidJSONObject(snapshot),
let data = try? JSONSerialization.data(withJSONObject: snapshot) else { return }
MainActor.assumeIsolated { [onSnapshot] in
onSnapshot(data)
}
Task { @MainActor [onSnapshot] in onSnapshot(data) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ public import AppKit
/// web view underneath, which is already loading the restored page. The page
/// snapshot is deliberately silent; a transient restore badge obscures the
/// content and makes a routine background memory operation feel like an alert.
@MainActor
public final class BrowserPageSnapshotOverlayView: NSView {
private let imageView = NSImageView()

public override var isFlipped: Bool { true }
public override var isOpaque: Bool { false }
public nonisolated override var isFlipped: Bool { true }
public nonisolated override var isOpaque: Bool { false }

/// - Parameter snapshot: The page as it looked before the discard.
public init(snapshot: BrowserPageSnapshotImage?) {
Expand Down Expand Up @@ -45,7 +44,7 @@ public final class BrowserPageSnapshotOverlayView: NSView {
/// Whether the overlay carries a page snapshot, not just the badge.
public var showsSnapshot: Bool { imageView.image != nil }

public override func hitTest(_ point: NSPoint) -> NSView? {
public nonisolated override func hitTest(_ point: NSPoint) -> NSView? {
nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ public final class BrowserOffscreenRenderPanel: NSPanel {
/// `isKeyWindow`; WebKitTestRunner's window lies the same way. AppKit's
/// real key window, first responder and keyboard focus are unaffected
/// because the panel still refuses to become key.
public var reportsKeyWindowForAutomation = false
// WebKit can query this flag from a framework callback that does not carry
// Swift's MainActor executor token. The panel remains AppKit-main-thread
// owned; the unsafe annotation only makes that callback boundary explicit.
public nonisolated(unsafe) var reportsKeyWindowForAutomation = false

public override var canBecomeKey: Bool { false }
public override var canBecomeMain: Bool { false }
public override var isKeyWindow: Bool { reportsKeyWindowForAutomation || super.isKeyWindow }
public nonisolated override var canBecomeKey: Bool { false }
public nonisolated override var canBecomeMain: Bool { false }
public nonisolated override var isKeyWindow: Bool { reportsKeyWindowForAutomation || super.isKeyWindow }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public final class BrowserHiddenWebViewDiscardManager {
private var systemSleepObserverCenter: NotificationCenter?
private let policyDefaults: UserDefaults
private var policyState: BrowserHiddenWebViewDiscardPolicy.ResolvedPolicy
private var scheduleGeneration: UInt64 = 0
// Timer work and sleep/wake ingress are serialized by AppKit's main thread.
// Publish invalidation before hopping to MainActor so queued timers cannot win.
nonisolated(unsafe) private var scheduleGeneration: UInt64 = 0

public init(policyDefaults: UserDefaults = .standard) {
self.policyDefaults = policyDefaults
Expand All @@ -42,8 +44,10 @@ public final class BrowserHiddenWebViewDiscardManager {
/// Sleep/wake state used to keep a hidden-webview discard from running in
/// the fragile window right after system wake
/// (https://github.com/manaflow-ai/cmux/issues/5261).
private(set) var isSystemSleeping = false
private(set) var lastSystemWakeAt: Date?
// NSWorkspace notifications use the main queue; actor callers also use that
// thread. Only this synchronous snapshot crosses the framework callback seam.
nonisolated(unsafe) private(set) var isSystemSleeping = false
nonisolated(unsafe) private(set) var lastSystemWakeAt: Date?

public private(set) var isDiscardedForMemory: Bool = false
public private(set) var discardedAt: Date?
Expand Down Expand Up @@ -174,7 +178,7 @@ public final class BrowserHiddenWebViewDiscardManager {
let timer = DispatchSource.makeTimerSource(queue: .main)
timer.schedule(deadline: .now() + remaining)
timer.setEventHandler { [weak self] in
MainActor.assumeIsolated {
Task { @MainActor [weak self] in
guard let self else { return }
guard !self.isSystemSleeping else { return }
guard self.scheduleGeneration == generation else { return }
Expand Down Expand Up @@ -255,30 +259,40 @@ public final class BrowserHiddenWebViewDiscardManager {
guard systemSleepObservers.isEmpty else { return }
systemSleepObserverCenter = center
systemSleepObservers = [
// Synchronous main-actor delivery (no Task hop): a countdown with
// milliseconds of mach time left must see isSystemSleeping before
// its timer can fire.
center.addObserver(
forName: NSWorkspace.willSleepNotification,
object: nil,
queue: .main
) { [weak self] _ in
MainActor.assumeIsolated {
self?.noteSystemWillSleep()
}
self?.receiveSystemSleepTransition(isSleeping: true)
},
center.addObserver(
forName: NSWorkspace.didWakeNotification,
object: nil,
queue: .main
) { [weak self] _ in
MainActor.assumeIsolated {
self?.noteSystemDidWake()
}
self?.receiveSystemSleepTransition(isSleeping: false)
}
]
}

/// Publishes the main-thread notification barrier before deferred timer work.
private nonisolated func receiveSystemSleepTransition(isSleeping: Bool) {
let now = Date()
isSystemSleeping = isSleeping
if !isSleeping { lastSystemWakeAt = now }
scheduleGeneration &+= 1
let generation = scheduleGeneration
Task { @MainActor [weak self] in
guard let self, self.scheduleGeneration == generation else { return }
if isSleeping {
self.noteSystemWillSleep()
} else {
self.noteSystemDidWake(now: now)
}
}
}

public func noteSystemWillSleep() {
isSystemSleeping = true
let hadScheduledDiscard = hasScheduledDiscard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ public final class BrowserOffscreenRenderHost {
/// the pane reflects what the phone shows instead of going blank; click-through
/// because the phone owns interaction. Removed on teardown when the web view
/// returns to the pane.
@MainActor
final class BrowserStreamMacMirrorView: NSView {
private let imageView = NSImageView()

Expand All @@ -351,7 +350,7 @@ final class BrowserStreamMacMirrorView: NSView {
imageView.image = image
}

public override func hitTest(_ point: NSPoint) -> NSView? {
public nonisolated override func hitTest(_ point: NSPoint) -> NSView? {
nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ public import WebKit
/// layout size while preserving the pane's displayed size and AppKit coordinate conversion.
/// Native browsers stay directly attached to their portal container so this extra AppKit layer
/// exists only while an automation viewport is active.
@MainActor
// AppKit and WebKit may enter NSView overrides synchronously from their own
// main-thread stacks (notably RemoteLayerTreeHost while committing a layer
// tree). A main-thread callback does not establish Swift's MainActor executor,
// so the framework-facing override is explicitly `nonisolated` below. NSView
// inherits `@MainActor` from NSResponder in the Swift 6 SDK; omitting that
// modifier still emits an executor-checking Objective-C thunk. All view
// ownership remains on the AppKit main thread.
public final class BrowserViewportHostView: NSView {
public private(set) weak var webView: WKWebView?
public private(set) var appliedLayout: BrowserViewportLayout?

public override var isFlipped: Bool { true }
public override var isOpaque: Bool { false }
public nonisolated override var isFlipped: Bool { true }
public nonisolated override var isOpaque: Bool { false }

public override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
Expand Down Expand Up @@ -214,7 +220,7 @@ public final class BrowserViewportHostView: NSView {
webView.autoresizingMask == webView.cmuxBrowserViewportAutoresizingMask
}

public override func layout() {
public nonisolated override func layout() {
super.layout()
applyRawWebViewGeometryIfSafe()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension CmuxWebView {
/// (`url` is nil when the right-click was not on a link). The backing
/// stored property lives in `CmuxWebView.swift` because extensions cannot
/// add stored properties.
struct ContextMenuCapturedLink {
struct ContextMenuCapturedLink: Sendable {
public let url: URL?
public let uptime: TimeInterval
}
Expand Down Expand Up @@ -130,7 +130,7 @@ extension CmuxWebView {
)
}

fileprivate func noteContextMenuCapturedLink(_ url: URL?) {
fileprivate nonisolated func noteContextMenuCapturedLink(_ url: URL?) {
contextMenuCapturedLink = ContextMenuCapturedLink(
url: url,
uptime: ProcessInfo.processInfo.systemUptime
Expand Down Expand Up @@ -313,14 +313,9 @@ private final class ContextMenuLinkCaptureMessageHandler: NSObject, WKScriptMess
// script already drops synthetic (isTrusted == false) events, so
// every message is a real right-click report.
//
// WebKit delivers script messages on the main thread (same pattern as
// BrowserMediaPlaybackMessageHandler). Apply the capture synchronously
// instead of hopping through a `Task` so it stays ordered with the
// AppKit click lifecycle: a deferred report from the previous click
// must not run after `rightMouseDown` clears the capture and repopulate
// it for the menu the new click opens.
MainActor.assumeIsolated {
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
webView.noteContextMenuCapturedLink(url)
}
// WebKit and AppKit serialize this snapshot on the main thread.
// Publish before returning so menu tracking sees this click's capture,
// without requiring a Swift executor token at the framework boundary.
webView.noteContextMenuCapturedLink(url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ private final class ScriptedDownloadMessageHandler: NSObject, WKScriptMessageHan
let body = message.body as? [String: Any] else {
return
}
MainActor.assumeIsolated {
Task { @MainActor in
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
webView.handleScriptedDownloadMessage(body, isMainFrame: message.frameInfo.isMainFrame)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,22 @@ public final class CmuxWebView: CmuxUndoableWebView {
}
/// Guard against background panes stealing first responder (e.g. page autofocus).
/// BrowserPanelView updates this as pane focus state changes.
public var allowsFirstResponderAcquisition: Bool = true
private var pointerFocusAllowanceDepth: Int = 0
// These flags are owned by the AppKit main thread. They are marked unsafe
// so the synchronous responder entry point can read them without asking
// Swift to hop through an executor that WebKit did not install.
public nonisolated(unsafe) var allowsFirstResponderAcquisition: Bool = true
private nonisolated(unsafe) var pointerFocusAllowanceDepth: Int = 0
private var pasteAsPlainTextTargetAvailable = false
private var lastPasteAsPlainTextPerformKeyEventTimestamp: TimeInterval?
private let diffViewerDocumentState = DiffViewerNavigationDocumentState()
private lazy var diffViewerNavigationKeyRouter: (any CmuxWebViewNavigationKeyRouting)? =
host?.makeDiffViewerNavigationKeyRouter()
private var automationRenderFocusDepth = 0
private nonisolated(unsafe) var automationRenderFocusDepth = 0

public var allowsFirstResponderAcquisitionEffective: Bool {
public nonisolated var allowsFirstResponderAcquisitionEffective: Bool {
allowsFirstResponderAcquisition || pointerFocusAllowanceDepth > 0 || automationRenderFocusDepth > 0
}
public var debugPointerFocusAllowanceDepth: Int { pointerFocusAllowanceDepth }
public nonisolated var debugPointerFocusAllowanceDepth: Int { pointerFocusAllowanceDepth }

/// Uses the host's keyboard-layout-aware Cmd+Z / Cmd+Shift+Z check.
public override func isWebContentUndoRedoCommandEquivalent(_ event: NSEvent) -> Bool {
Expand Down Expand Up @@ -578,15 +581,16 @@ public final class CmuxWebView: CmuxUndoableWebView {
/// render window, so WebKit treats the driven page as focused. The focus
/// policy guards the user's windows and is bypassed only here; no
/// first-responder notification is posted, because the user's focus does
/// not move.
/// not move. AppKit/WebKit can enter the override while making a responder
/// change without Swift's MainActor executor token.
@discardableResult
public func acquireAutomationRenderFocus(in window: NSWindow) -> Bool {
automationRenderFocusDepth += 1
defer { automationRenderFocusDepth -= 1 }
return window.makeFirstResponder(self)
}

public override func becomeFirstResponder() -> Bool {
public nonisolated override func becomeFirstResponder() -> Bool {
if automationRenderFocusDepth > 0 {
return super.becomeFirstResponder()
}
Expand Down Expand Up @@ -1113,7 +1117,9 @@ public final class CmuxWebView: CmuxUndoableWebView {
/// right-click (`url` is nil when the click was not on a link). The type
/// and its lifecycle live in `CmuxWebView+ContextMenuLinkCapture.swift`;
/// only the stored property has to live in the class body.
var contextMenuCapturedLink: ContextMenuCapturedLink?
// WebKit script delivery and AppKit menu tracking both run on the main
// thread; synchronous publication must not require an executor-token check.
nonisolated(unsafe) var contextMenuCapturedLink: ContextMenuCapturedLink?
/// Uptime at which the current context menu opened, used to pair the menu
/// with the contextmenu capture report from the same right-click.
var lastContextMenuOpenUptime: TimeInterval?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public import WebKit
open class CmuxUndoableWebView: WKWebView {
public let webContentUndoManager = UndoManager()

open override var undoManager: UndoManager? { webContentUndoManager }
// WebKit reads the responder's undo manager from framework callbacks; do
// not make that Objective-C getter enter a Swift MainActor check.
open nonisolated override var undoManager: UndoManager? { webContentUndoManager }

/// Whether `event` is the keyboard-layout-aware Cmd+Z or Cmd+Shift+Z
/// chord this view completes. The keyboard layout lookup lives in the
Expand Down
Loading
Loading