Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
3b3643b
test: cover retained closed main window cleanup
austinywang Jul 21, 2026
b71813a
fix: finalize closed main window ownership
austinywang Jul 21, 2026
5a6bfc4
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 21, 2026
eec5d64
test: cover recoverable orphan and manager cleanup
austinywang Jul 21, 2026
3acbafd
test: cover retained manager background state
austinywang Jul 21, 2026
1b58a27
fix: preserve transient routes and finalize window managers
austinywang Jul 21, 2026
510e69b
test: cover stale windowless duplicate close
austinywang Jul 21, 2026
ccd7752
test: cover finalized manager startup recovery
austinywang Jul 21, 2026
7cc2fcd
refactor: extract startup workspace recovery
austinywang Jul 21, 2026
2e59d41
test: isolate windowless duplicate fallback
austinywang Jul 21, 2026
99da9b4
fix: validate recoverable window lifecycle ownership
austinywang Jul 22, 2026
e6613d2
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 22, 2026
3f649b5
test: import terminal registry protocol
austinywang Jul 22, 2026
41e4595
fix: block late workspace acquisition after window close
austinywang Jul 22, 2026
367728d
test: cover hidden window lifecycle retirement
austinywang Jul 22, 2026
7ed4a4f
fix: complete hidden window lifecycle teardown
austinywang Jul 22, 2026
b7a7cf0
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 22, 2026
6570c04
test: cover lifecycle ownership mutation boundaries
austinywang Jul 22, 2026
0e74a01
fix: preserve finalized window ownership boundaries
austinywang Jul 22, 2026
1cb581d
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 22, 2026
68a082b
Fix current-main agent liveness test fixture
austinywang Jul 22, 2026
04c0733
test: reject focus of committed main windows
austinywang Jul 22, 2026
2d2085e
Prevent committed windows from being focused
austinywang Jul 22, 2026
81a5ec6
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 23, 2026
7f95b08
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 23, 2026
d101702
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 23, 2026
fe0ca65
Test rejected window and registry teardown edge cases
austinywang Jul 23, 2026
6db3c64
Finalize rejected windows and coalesce route cleanup
austinywang Jul 23, 2026
6336791
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
austinywang Jul 23, 2026
b55ee85
Preserve deinit registry retirement
austinywang Jul 23, 2026
d54ec0f
test: cover finalized window and weak registry cleanup
austinywang Jul 23, 2026
77fc1dd
fix: harden finalized workspace and surface ownership
austinywang Jul 23, 2026
f58902f
fix: preserve bounded registry cleanup
austinywang Jul 23, 2026
90afc0d
test: cover retained controller and bounded weak eviction
austinywang Jul 23, 2026
3f0b37d
fix: bound weak eviction and preserve window release
austinywang Jul 23, 2026
279b774
test: cover complete bulk git probe reset
austinywang Jul 23, 2026
b64d807
fix: make teardown cleanup reentrancy-safe
austinywang Jul 23, 2026
fd6fb2b
docs: explain registry lock safety
austinywang Jul 23, 2026
115788a
test: import workspace fixture value modules
Jul 23, 2026
d40615f
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Jul 23, 2026
c7a12f6
test: name bulk reset coverage precisely
Jul 23, 2026
c0eaa30
test: cover finalized intruder and invisible route isolation
Jul 23, 2026
240204f
fix: isolate exact window and visible mutation routes
Jul 23, 2026
7dcd763
test: cover browser-only routes and retired surfaces
Jul 23, 2026
bdceaa1
fix: preserve lifecycle-owned window routes
Jul 23, 2026
7d0d532
test: cover retired direct split creators
Jul 23, 2026
43af6e1
fix: reject retired workspace split creators
Jul 23, 2026
fcb96d6
test: cover stale-key exact window close
Jul 23, 2026
773c129
test: compare retired workspace layout snapshots
Jul 23, 2026
0f7e310
fix: close stale owners and roll back orphan worktrees
Jul 23, 2026
2d74f38
test: cover exact close routing and route history
Jul 23, 2026
c28880b
test: isolate final close routing regressions
Jul 23, 2026
c19f9a5
test: avoid AppKit teardown in close regressions
Jul 23, 2026
182bd74
test: make duplicate close routing deterministic
Jul 23, 2026
facd2f3
fix: finalize exact recoverable window closes
Jul 23, 2026
a606ef3
test: retain rejected duplicate windows
Jul 23, 2026
c51ac9b
test: cover recoverable route persistence and pruning
Jul 23, 2026
c68a447
fix: persist and prune recoverable window routes
Jul 23, 2026
04d95cf
test: reject stale window ownership and unsafe rollback
Jul 23, 2026
fdd3927
fix: reject stale owners and unsafe rollback
Jul 23, 2026
2d1e7a2
test: reject foreign windowless context owners
Jul 23, 2026
dd2aea0
fix: preserve registered window ID ownership
Jul 23, 2026
31edc98
test: reject main window manager aliasing
Jul 23, 2026
16006b2
fix: reject main window manager aliases
Jul 23, 2026
cb07059
test: protect key-window context ownership
Jul 23, 2026
e064a8e
fix: guard main window context reindexing
Jul 23, 2026
dfc9b35
test: preserve locked worktree rollback state
Jul 23, 2026
1bb4fc3
fix: make worktree rollback artifact-safe
Jul 23, 2026
5c544d3
test: reject stale main window identity authority
Jul 23, 2026
dd49ef3
fix: require exact main window identity authority
Jul 23, 2026
2f5051d
test: retire orphaned launch bootstrap manager
Jul 23, 2026
75e5cf9
fix: retire orphaned launch bootstrap manager
Jul 23, 2026
1a00c17
Merge origin/main into issue-8349-ghost-window-contexts
Jul 23, 2026
2813c4d
Merge origin/main into issue-8349-ghost-window-contexts
Jul 24, 2026
9bcbe7a
test: cover mobile create reservation after window close
Jul 24, 2026
d175973
fix: preserve mobile create retries after window close
Jul 24, 2026
edb983b
Merge origin/main into issue-8349-ghost-window-contexts
Jul 24, 2026
8d32977
fix: import workspace shell activity state
Jul 24, 2026
880229c
fix: make Dock snapshot inference explicit
Jul 24, 2026
f5efc00
fix: return resume approval policy explicitly
Jul 24, 2026
98fe00a
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 28, 2026
5684917
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Jul 28, 2026
2f71fd1
test: cover fresh manager after committed close
Jul 28, 2026
f908a56
fix: retire managers rejected by committed windows
Jul 28, 2026
9912934
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 28, 2026
eb0a594
test: cover review lifecycle races
Jul 28, 2026
372d2e5
fix: close review lifecycle gaps
Jul 28, 2026
49e10d4
test: cover retained workspace surface factories
Jul 28, 2026
99403ef
test: cover lazy Dock creation after retirement
Jul 28, 2026
6eaa2a2
fix: permanently retire retained workspace factories
Jul 28, 2026
4496a75
test: cover retained window Dock after close
Jul 28, 2026
652ef43
fix: retire window Dock on teardown
Jul 28, 2026
b63bfbd
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 28, 2026
1d7427e
test: cover retired feature flag observer
Jul 28, 2026
dafe5e7
fix: guard retirement and rollback races
Jul 28, 2026
8d2f43b
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 28, 2026
d11cb11
test: cover full idempotency rollback
Jul 28, 2026
0d4921e
fix: restore evicted idempotency tombstones
Jul 28, 2026
76f2a91
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 28, 2026
5661ae1
test: cover symlinked worktree rollback
Jul 28, 2026
8bf3856
fix: compare worktree filesystem identity
Jul 28, 2026
d2c5c73
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 28, 2026
d750af0
test: cover windowless close and nested rollback
Jul 29, 2026
72a2f52
fix: preserve windowless close and rollback ownership
Jul 29, 2026
ee419e7
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Jul 29, 2026
529f022
fix: guard merged UI test workspace setup
Jul 29, 2026
c8b3954
fix: guard merged remote fork workspace creation
Jul 29, 2026
962e033
fix: reconcile remote tmux route lifecycle test
Jul 29, 2026
513e429
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Jul 29, 2026
5fc8336
test: cover windowless route quit confirmation
Jul 29, 2026
6956c17
fix: include windowless routes in quit safety
Jul 29, 2026
786d5ca
Merge origin/main into issue-8349-ghost-window-contexts
Jul 30, 2026
e5e1f4e
Add regression coverage for stale main-window close callback
Jul 30, 2026
647e190
Route main-window close termination by sender identity
Jul 30, 2026
a926fa5
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
Jul 30, 2026
732a1c8
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Jul 30, 2026
a19a261
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 1, 2026
8cbe53e
Fix workspace creation after main merge
Aug 1, 2026
121e579
Fix restore argument canonicalization build
Aug 1, 2026
777512b
Fix shortcut tests after workspace lifecycle merge
Aug 1, 2026
4106370
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 1, 2026
2461383
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 7, 2026
d016a62
fix: close final window lifecycle review gaps
Aug 7, 2026
22f5788
test: unwrap retained Dock fixture
Aug 7, 2026
6dd7c97
test: model notification surface preflight
Aug 7, 2026
e3bb216
fix: address final window lifecycle review findings
Aug 7, 2026
0659cb9
fix: type window Dock snapshot explicitly
Aug 7, 2026
19d7aed
fix: return sanitized worktree rollback error
Aug 7, 2026
4bffdd6
test: cover abandoned recoverable Dock owner
Aug 7, 2026
1bdfc18
fix: retire recoverable Dock with weak owner
Aug 7, 2026
695c9b4
test: import workspace creation value modules
Aug 7, 2026
3f65a54
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 7, 2026
4276304
test: fix browser-only Dock lifecycle fixture
Aug 7, 2026
017fc3c
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 7, 2026
ce5e9f9
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 8, 2026
91e0b8b
test: cover final window lifecycle review gaps
Aug 9, 2026
89e2c19
test: stabilize inherited CI lifecycle fixtures
Aug 9, 2026
4806cce
fix: preserve exact routing and rollback chronology
Aug 9, 2026
b7ada49
test: cover rollback backup mutation race
Aug 9, 2026
8444393
fix: retain raced worktree rollback artifacts
Aug 25, 2026
4f44373
Merge remote-tracking branch 'origin/main' into issue-8349-ghost-wind…
Aug 25, 2026
c05791a
test: cover reusable workspace dock teardown
Aug 25, 2026
48ecc12
fix: keep workspace Dock reusable during panel teardown
Aug 25, 2026
3742caa
fix: close late workspace lifecycle routes
Aug 25, 2026
b89ccc2
fix: fence retired Dock ingress and remote owners
Aug 25, 2026
5dd1417
fix: preserve recoverable owner adoption boundaries
Aug 25, 2026
7f15f35
fix: detach remote mirrors during workspace retirement
Aug 25, 2026
82922b1
fix: retain workspace creation compatibility
Aug 25, 2026
4210af2
fix: fence rollback against replacement worktrees
Aug 25, 2026
396b207
fix: validate recoverable workspace ownership
Aug 25, 2026
fcc9061
fix: clean up failed extension worktrees
Aug 25, 2026
1d2eee8
fix: close windowless recoverable owners
Aug 25, 2026
9bb62d2
fix: allow windowless noninteractive closes
Aug 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ extension TerminalSurface {
#endif
}

/// Explicitly free the Ghostty runtime surface. Idempotent — safe to call
/// before deinit; deinit will skip the free if already torn down.
/// Explicitly retire this model and free its Ghostty runtime surface.
/// Idempotent — safe to call before deinit; deinit will skip the work if
/// already torn down.
@MainActor
public func teardownSurface() {
recordTeardownRequest(reason: "surface.teardown")
markPortalLifecycleClosed(reason: "teardown")
retireSurfaceRegistryRegistrationIfNeeded()
Comment thread
austinywang marked this conversation as resolved.
Resolved
Comment thread
austinywang marked this conversation as resolved.
Resolved
backgroundSurfaceStartSource = .normal
cancelClaudeCommandShimInstallLifecycle()
closeHeadlessStartupWindowIfNeeded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ public final class TerminalSurface: Identifiable, ObservableObject {
/// state unless the workspace focus path requests it.
var desiredFocusState: Bool = false

/// Whether this model still owns its logical surface-registry entry.
/// Weak registry membership is cleared before `deinit`, so the model keeps
/// this one-shot ownership bit to distinguish deinit-only cleanup from a
/// later deinit following explicit teardown.
private var ownsSurfaceRegistryRegistration = false

/// Bumped after every completed runtime clipboard read.
public internal(set) var clipboardReadGeneration = 0
#if DEBUG
Expand Down Expand Up @@ -517,6 +523,7 @@ public final class TerminalSurface: Identifiable, ObservableObject {
self.paneHost = views.paneHost
preparePaneHost(self.paneHost)
registry.register(self)
ownsSurfaceRegistryRegistration = true
self.paneHost.attachSurface(self)

let inheritedCommand = configTemplate?.command?.trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down Expand Up @@ -571,10 +578,17 @@ public final class TerminalSurface: Identifiable, ObservableObject {
registry.updateFocusPlacement(id: id, placement)
}

/// Retires logical registry ownership once across explicit teardown and deinit.
func retireSurfaceRegistryRegistrationIfNeeded() {
guard ownsSurfaceRegistryRegistration else { return }
ownsSurfaceRegistryRegistration = false
registry.unregister(self)
}

deinit {
claudeCommandShimInstallTask?.cancel()
claudeCommandShimCompletionTask?.cancel()
registry.unregister(self)
retireSurfaceRegistryRegistrationIfNeeded()
markPortalLifecycleClosed(reason: "deinit")
// Mirror closeHeadlessStartupWindowIfNeeded: deinit is nonisolated, so
// the NSWindow teardown hops to the main actor through the same kind of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ import Testing
/// native free to the runtime teardown coordinator.
@MainActor
@Suite(.serialized) struct TerminalSurfaceTeardownCallbackLifetimeTests {
@Test func explicitTeardownRetiresLogicalRegistryOwnershipExactlyOnce() throws {
let registry = TerminalSurfaceRegistry()
var surface: TerminalSurface? = makeSurface(registry: registry)
let surfaceId = try #require(surface?.id)
let registeredGeneration = registry.topologyGeneration
#expect(registry.surface(id: surfaceId) != nil)

surface?.teardownSurface()
let teardownGeneration = registry.topologyGeneration
#expect(registry.surface(id: surfaceId) == nil)
#expect(teardownGeneration > registeredGeneration)

surface?.teardownSurface()
#expect(registry.topologyGeneration == teardownGeneration)

surface = nil
#expect(registry.topologyGeneration == teardownGeneration)
}

@Test func deinitOnlyTeardownStillRetiresRegistryOwnership() throws {
let registry = TerminalSurfaceRegistry()
var surface: TerminalSurface? = makeSurface(registry: registry)
let surfaceId = try #require(surface?.id)
let registeredGeneration = registry.topologyGeneration

surface = nil

#expect(registry.surface(id: surfaceId) == nil)
#expect(registry.topologyGeneration > registeredGeneration)
}

@Test func teardownSurfaceKeepsTeeLeaseUntilNativeFree() async {
let recorder = TeardownOrderRecorder()
let surface = makeSurface()
Expand Down Expand Up @@ -138,15 +169,17 @@ import Testing
#expect(recorder.events == [.nativeFree, .teeLeaseRelease])
}

private func makeSurface() -> TerminalSurface {
private func makeSurface(
registry: any TerminalSurfaceRegistering = FakeSurfaceRegistry()
) -> TerminalSurface {
let nativeView = FakeTerminalSurfaceNativeView(frame: NSRect(x: 0, y: 0, width: 800, height: 600))
let paneHost = FakeTerminalSurfacePaneHost(surfaceView: nativeView)
return TerminalSurface(
tabId: UUID(),
context: GHOSTTY_SURFACE_CONTEXT_SPLIT,
configTemplate: nil,
dependencies: TerminalSurfaceRuntimeDependencies(
registry: FakeSurfaceRegistry(),
registry: registry,
engine: FakeTerminalEngine(),
viewProvider: FakeTerminalSurfaceViewProvider(surfaceView: nativeView, paneHost: paneHost),
spawnPolicy: FakeSpawnPolicyProvider(),
Expand Down
10 changes: 10 additions & 0 deletions Sources/App/MainWindowVisibilityController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ final class MainWindowVisibilityController {
}

private var dependencies: Dependencies
private let committedClosedWindows = NSHashTable<NSWindow>.weakObjects()
var appHiddenWindowRestoreTargets: [NSWindow] = []
var dismissedWindowRestoreTargets: [NSWindow] = []
var pendingApplicationActivationKeyRestoreTarget: NSWindow?
Expand All @@ -130,6 +131,15 @@ final class MainWindowVisibilityController {
self.dependencies = dependencies
}

func commitClose(_ window: NSWindow) {
committedClosedWindows.add(window)
discardClosedWindow(window)
}

func hasCommittedClose(for window: NSWindow) -> Bool {
committedClosedWindows.contains(window)
}

@discardableResult
func focus(
_ window: NSWindow,
Expand Down
4 changes: 4 additions & 0 deletions Sources/AppDelegate+NonInteractiveWindowClose.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ extension AppDelegate {
func closeMainWindowWithoutInteractiveVeto(_ window: NSWindow) {
WebViewInspectorTeardown.closeAllInspectors(in: window)
window.close()
// AppKit does not post another will-close notification for a retained
// NSWindow that is already closed. Commit explicitly so socket/API
// close requests also clean up any context left by a missed signal.
commitMainWindowClose(window)
}
}
24 changes: 16 additions & 8 deletions Sources/AppDelegate+RecoverableMainWindowRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ extension AppDelegate {
let before = mainWindowRouteLedger.routesByWindowId.count
mainWindowRouteLedger.routesByWindowId = mainWindowRouteLedger.routesByWindowId.filter { _, route in
guard let manager = route.tabManager else { return false }
guard let window = liveRecoverableMainWindow(windowId: route.windowId, cachedWindow: route.window) else { return false }
route.window = window
if let window = liveRecoverableMainWindow(windowId: route.windowId, cachedWindow: route.window) {
route.window = window
}
return tabManagerHasRegisteredTerminalSurface(manager)
}
let after = mainWindowRouteLedger.routesByWindowId.count
Expand All @@ -133,12 +134,11 @@ extension AppDelegate {
}

func rememberRecoverableMainWindowRoute(windowId: UUID, tabManager: TabManager, window: NSWindow?) {
guard let window = liveRecoverableMainWindow(windowId: windowId, cachedWindow: window) else { return }
guard tabManagerHasRegisteredTerminalSurface(tabManager) else { return }
mainWindowRouteLedger.routesByWindowId[windowId] = RecoverableMainWindowRoute(
windowId: windowId,
tabManager: tabManager,
window: window,
window: liveRecoverableMainWindow(windowId: windowId, cachedWindow: window),
order: mainWindowRouteLedger.issueOrder()
)
#if DEBUG
Expand All @@ -147,8 +147,13 @@ extension AppDelegate {
}

func recoverableMainWindowRoute(windowId: UUID) -> RecoverableMainWindowRoute? {
guard recoverableMainWindowRouteSnapshot(windowId: windowId) != nil else { return nil }
return mainWindowRouteLedger.routesByWindowId[windowId]
// Keep the weak manager route alive while SwiftUI/AppKit replaces its
// NSWindow. Snapshot-based listing/focus APIs still require a live
// window, so this internal route cannot surface a ghost window.
guard let route = mainWindowRouteLedger.routesByWindowId[windowId],
let manager = route.tabManager,
tabManagerHasRegisteredTerminalSurface(manager) else { return nil }
return route
}

func recoverableMainWindowRoutes() -> [RecoverableMainWindowRoute] {
Expand Down Expand Up @@ -193,14 +198,17 @@ extension AppDelegate {
if let context = mainWindowContexts.values.first(where: { $0.windowId == windowId }) {
return context.tabManager
}
return recoverableMainWindowRouteSnapshot(windowId: windowId)?.tabManager
return recoverableMainWindowRoute(windowId: windowId)?.tabManager
}

func windowId(for tabManager: TabManager) -> UUID? {
if let windowId = mainWindowContexts.values.first(where: { $0.tabManager === tabManager })?.windowId {
return windowId
}
return recoverableMainWindowRouteSnapshots().first(where: { $0.tabManager === tabManager })?.windowId
guard tabManagerHasRegisteredTerminalSurface(tabManager) else { return nil }
return sortedRecoverableMainWindowRoutes()
.first(where: { $0.tabManager === tabManager })?
.windowId
}

func mainWindowContainingWorkspace(_ workspaceId: UUID) -> NSWindow? {
Expand Down
Loading
Loading