Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
66d9739
Add per-pane runaway-memory guardrail (#6313)
austinywang Jun 17, 2026
67601ca
Merge remote-tracking branch 'origin/main' into fix-6313-pane-mem-gua…
austinywang Jun 17, 2026
a544a46
Refresh Swift file length budget for guardrail additions
austinywang Jun 17, 2026
806d24d
Defer hosted-inspector side-dock promotion out of the layout pass
austinywang Jun 17, 2026
e53067d
Merge remote-tracking branch 'origin/main' into issue-6150
austinywang Jun 17, 2026
51da1aa
Merge origin/main into issue-6150
austinywang Jun 18, 2026
4106b8a
fix: address guardrail review feedback
austinywang Jun 18, 2026
69b6384
fix: harden pane memory guardrail behavior
austinywang Jun 18, 2026
c58915a
fix: bind guardrail kill actions
austinywang Jun 18, 2026
db3b849
fix: add ghostty process info test stubs
austinywang Jun 18, 2026
15f4acc
fix: use cached expanded guardrail samples
austinywang Jun 18, 2026
47a2515
fix: harden guardrail kill safety
austinywang Jun 18, 2026
34663a8
fix: revalidate guardrail kill escalation
austinywang Jun 18, 2026
27ab69a
fix: sample guardrail panes without live surfaces
austinywang Jun 18, 2026
15dda24
merge: resolve conflicts with main
austinywang Jun 18, 2026
b3cfba2
fix: preserve adaptive dock on deferred promotion
austinywang Jun 19, 2026
ab07b3c
fix: index memory guardrail settings search
austinywang Jun 19, 2026
2e9eb68
fix: cancel stale guardrail kill tasks
austinywang Jun 19, 2026
b6380ce
fix: satisfy guardrail policy gates
austinywang Jun 19, 2026
873d6b0
Merge remote-tracking branch 'origin/main' into issue-6150
austinywang Jun 19, 2026
e791236
fix: align guardrail settings decoding
austinywang Jun 19, 2026
af3d3de
fix: preserve db client test mock exports
austinywang Jun 19, 2026
6c46704
fix: scan live pane guardrail managers
austinywang Jun 19, 2026
8746145
fix: scope guardrail banner to owning window
austinywang Jun 19, 2026
fb72ae8
Merge remote-tracking branch 'origin/main' into issue-6150
austinywang Jun 19, 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
14 changes: 7 additions & 7 deletions .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# Format: max_lines<TAB>relative path
# Reduce counts as files shrink. CI fails if tracked files exceed this budget.
34475 CLI/cmux.swift
17602 Sources/AppDelegate.swift
15933 Sources/ContentView.swift
17645 Sources/AppDelegate.swift
15955 Sources/ContentView.swift
14104 Sources/TerminalController.swift
12658 Sources/Workspace.swift
12115 cmuxTests/AppDelegateShortcutRoutingTests.swift
11833 Sources/GhosttyTerminalView.swift
11413 Sources/Panels/BrowserPanel.swift
9331 cmuxTests/CLINotifyProcessIntegrationRegressionTests.swift
7953 Sources/Panels/BrowserPanelView.swift
7988 Sources/Panels/BrowserPanelView.swift
7356 cmuxTests/WorkspaceUnitTests.swift
7221 cmuxTests/WorkspaceRemoteConnectionTests.swift
6317 cmuxTests/SessionPersistenceTests.swift
Expand All @@ -21,7 +21,7 @@
5925 cmuxTests/TerminalAndGhosttyTests.swift
5566 Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite.swift
5526 cmuxTests/BrowserConfigTests.swift
4516 Sources/cmuxApp.swift
4478 Sources/cmuxApp.swift
4467 Sources/Panels/FilePreviewPanel.swift
4401 cmuxTests/BrowserPanelTests.swift
4225 Sources/BrowserWindowPortal.swift
Expand All @@ -42,8 +42,8 @@
2395 Sources/Mobile/MobileHostService.swift
2355 Sources/FileExplorerView.swift
2328 cmuxTests/CJKIMEInputTests.swift
2257 Sources/TerminalNotificationStore.swift
2257 Sources/TerminalWindowPortal.swift
2242 Sources/TerminalNotificationStore.swift
2117 cmuxTests/CmuxConfigTests.swift
2092 cmuxTests/ShortcutAndCommandPaletteTests.swift
2082 Sources/SessionPersistence.swift
Expand All @@ -68,8 +68,8 @@
1384 cmuxTests/KeyboardShortcutSettingsFileStoreStartupTests.swift
1380 cmuxUITests/MenuKeyEquivalentRoutingUITests.swift
1373 cmuxTests/AppDelegateIssue2907RoutingTests.swift
1366 Sources/Feed/FeedButtonStyleDebugWindowController.swift
1362 Sources/CMUXInstalledExtensionSidebarHostView.swift
1360 Sources/Feed/FeedButtonStyleDebugWindowController.swift
1292 Packages/macOS/CmuxTerminalCore/Sources/CmuxTerminalCore/Config/GhosttyConfig.swift
1285 cmuxUITests/SidebarHelpMenuUITests.swift
1276 cmuxTests/MobileHostAuthorizationTests.swift
Expand Down Expand Up @@ -175,7 +175,7 @@
580 cmuxTests/CLIHookNoResponseTests.swift
578 cmuxUITests/FeedSidebarUITests.swift
577 cmuxTests/AppearanceSettingsTests.swift
574 Sources/Feed/FeedTextEditorDebugWindowController.swift
571 Sources/Feed/FeedTextEditorDebugWindowController.swift
568 Packages/Shared/CMUXMobileCore/Sources/CMUXMobileCore/MobileTerminalRenderGrid.swift
567 Packages/macOS/CmuxTerminalCore/Sources/CmuxTerminalCore/ConfigDiscovery/GhosttyConfigDiscovery.swift
566 Packages/macOS/CMUXAgentLaunch/Sources/CMUXAgentLaunch/AgentLaunchSanitizer.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,23 @@ public struct TerminalCatalogSection: SettingCatalogSection {
defaultValue: []
)

/// Whether the per-pane runaway-memory guardrail is active. When on, cmux
/// polls each pane's process-tree memory and warns (badge + dismissible
/// banner with a kill action) when one crosses the threshold, before the OS
/// can OOM-suspend the whole app. On by default.
public let runawayMemoryGuardrailEnabled = DefaultsKey<Bool>(
id: "terminal.runawayMemoryGuardrail.enabled",
defaultValue: true,
userDefaultsKey: "terminal.runawayMemoryGuardrail.enabled"
)

/// Process-tree resident-memory threshold, in gigabytes, at which a pane is
/// flagged as a runaway. Default 8 GB.
public let runawayMemoryGuardrailThresholdGB = DefaultsKey<Double>(
id: "terminal.runawayMemoryGuardrail.thresholdGB",
defaultValue: 8,
userDefaultsKey: "terminal.runawayMemoryGuardrail.thresholdGB"
)

public init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public struct TerminalSection: View {
@State private var rendererReclaim: DefaultsValueModel<Bool>
@State private var rendererIdleSeconds: DefaultsValueModel<Double>
@State private var rendererMaxWarm: DefaultsValueModel<Int>
@State private var memGuardrailEnabled: DefaultsValueModel<Bool>
@State private var memGuardrailThresholdGB: DefaultsValueModel<Double>

public init(
defaultsStore: UserDefaultsSettingsStore,
Expand All @@ -43,6 +45,8 @@ public struct TerminalSection: View {
_rendererReclaim = State(initialValue: DefaultsValueModel(store: defaultsStore, key: catalog.terminal.rendererRealizationEnabled))
_rendererIdleSeconds = State(initialValue: DefaultsValueModel(store: defaultsStore, key: catalog.terminal.rendererRealizationIdleSeconds))
_rendererMaxWarm = State(initialValue: DefaultsValueModel(store: defaultsStore, key: catalog.terminal.rendererRealizationMaxWarmRenderers))
_memGuardrailEnabled = State(initialValue: DefaultsValueModel(store: defaultsStore, key: catalog.terminal.runawayMemoryGuardrailEnabled))
_memGuardrailThresholdGB = State(initialValue: DefaultsValueModel(store: defaultsStore, key: catalog.terminal.runawayMemoryGuardrailThresholdGB))
}

public var body: some View {
Expand All @@ -65,6 +69,8 @@ public struct TerminalSection: View {
rendererReclaim,
rendererIdleSeconds,
rendererMaxWarm,
memGuardrailEnabled,
memGuardrailThresholdGB,
]
models.forEach { $0.startObserving() }
}
Expand Down Expand Up @@ -275,6 +281,35 @@ public struct TerminalSection: View {
)
.accessibilityIdentifier("SettingsTerminalRendererRealizationMaxWarmStepper")
}
SettingsCardDivider()
SettingsCardRow(
configurationReview: .settingsOnly,
String(localized: "settings.terminal.memoryGuardrail", defaultValue: "Runaway Memory Guardrail"),
subtitle: memGuardrailEnabled.current
? String(localized: "settings.terminal.memoryGuardrail.subtitleOn", defaultValue: "cmux warns you with a badge and a banner when one pane's process tree uses too much memory, so a single leak can't crash the whole app.")
: String(localized: "settings.terminal.memoryGuardrail.subtitleOff", defaultValue: "No warning is shown when a pane's process tree grows large. A leaking process can OOM-suspend the entire app.")
) {
Toggle("", isOn: Binding(get: { memGuardrailEnabled.current }, set: { memGuardrailEnabled.set($0) }))
.labelsHidden()
.controlSize(.small)
.accessibilityIdentifier("SettingsTerminalMemoryGuardrailToggle")
}
SettingsCardDivider()
SettingsCardRow(
configurationReview: .settingsOnly,
String(localized: "settings.terminal.memoryGuardrail.threshold", defaultValue: "Memory Warning Threshold (GB)"),
subtitle: String(localized: "settings.terminal.memoryGuardrail.threshold.subtitle", defaultValue: "A pane is flagged once its combined process-tree memory crosses this many gigabytes."),
controlWidth: 120
) {
Stepper(
"\(Int(memGuardrailThresholdGB.current))",
value: Binding(get: { memGuardrailThresholdGB.current }, set: { memGuardrailThresholdGB.set($0) }),
in: 1...256,
step: 1
)
.disabled(!memGuardrailEnabled.current)
.accessibilityIdentifier("SettingsTerminalMemoryGuardrailThresholdStepper")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public import Foundation
public import GhosttyKit

// MARK: - Foreground process / controlling-tty introspection

extension TerminalSurface {
/// The foreground process id reported by libghostty for this surface's PTY,
/// or `nil` when there is no live runtime surface. Used by the per-pane
/// runaway-memory guardrail to name the foreground command in its warning.
@MainActor
public func foregroundProcessID() -> Int? {
guard let surface = liveSurfaceForGhosttyAccess(reason: "memGuard.foregroundPID") else {
return nil
}
let pid = ghostty_surface_foreground_pid(surface)
return pid > 0 ? Int(pid) : nil
}

/// The controlling TTY device name (e.g. `/dev/ttys003`) for this surface's
/// PTY, or `nil` when there is no live runtime surface or the runtime has no
/// tty yet. Every process in the pane (shell + descendants + background jobs)
/// shares this controlling tty, so it is the attribution key the guardrail
/// sums process-tree memory by.
@MainActor
public func controllingTTYName() -> String? {
guard let surface = liveSurfaceForGhosttyAccess(reason: "memGuard.ttyName") else {
return nil
}
let exported = ghostty_surface_tty_name(surface)
defer { ghostty_string_free(exported) }
guard let ptr = exported.ptr, exported.len > 0 else { return nil }
let data = Data(bytes: ptr, count: Int(exported.len))
guard let decoded = String(data: data, encoding: .utf8) else { return nil }
let name = decoded.trimmingCharacters(in: .whitespacesAndNewlines)
return name.isEmpty ? nil : name
}
}
Loading
Loading