Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9246564
Add Codex monitor owner lifecycle regression
austinywang May 13, 2026
52a1792
Reduce resumed session UI hot paths
austinywang May 13, 2026
0f3dad3
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 13, 2026
a2cc1d9
Tighten Codex monitor owner PID regression
austinywang May 13, 2026
ba514ae
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 13, 2026
61d6395
Address Codex monitor review feedback
austinywang May 13, 2026
378610d
Bound Codex monitor owner polling
austinywang May 13, 2026
c7a2816
Address Codex monitor cache review
austinywang May 13, 2026
70f3042
Harden Codex monitor regression review cases
austinywang May 13, 2026
4499c00
Run Codex feed hook regression in CI
austinywang May 13, 2026
15f3f16
Shorten Codex feed hook test sockets
austinywang May 13, 2026
522073f
Flush sidebar telemetry before log reads
austinywang May 13, 2026
67f2dfc
Merge remote-tracking branch 'origin/main' into HEAD
austinywang May 13, 2026
bbbf10d
Remove Codex monitor semaphore wait
austinywang May 13, 2026
5aa1090
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 18, 2026
549a0b2
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 18, 2026
a723b8e
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 18, 2026
fdc1f8d
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 19, 2026
be2d840
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 19, 2026
59623d3
merge: sync issue 4101 with main
austinywang May 19, 2026
7bf1669
fix: localize codex owner pid error
austinywang May 19, 2026
a0e8486
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 19, 2026
b7debc8
fix: align codex hook regression expectations
austinywang May 19, 2026
5dd934e
fix: expect codex hook dedupe in regression
austinywang May 19, 2026
84f8e6b
merge: sync main into issue 4101
austinywang May 22, 2026
b70f60c
Stabilize CLI version memory guard
austinywang May 22, 2026
3ee384d
Merge remote-tracking branch 'origin/main' into issue-4101-whole-mach…
austinywang May 22, 2026
1909523
merge: resolve conflicts with main
austinywang Jun 6, 2026
556ebdd
merge: resolve conflicts with main
austinywang Jun 6, 2026
0083a9d
merge: resolve latest main conflicts
austinywang Jun 6, 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
46 changes: 45 additions & 1 deletion CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16641,6 +16641,7 @@ struct CMUXCLI {
private static let codexMonitorRetiredLeaseMaxAgeSeconds: TimeInterval = 2 * 60
private static let codexMonitorOwnerCheckIntervalSeconds: TimeInterval = 60
private static let codexMonitorOwnerCheckTimeoutSeconds: TimeInterval = 1
private static let codexMonitorUnresolvedTranscriptTimeoutSeconds: TimeInterval = 5 * 60

private func codexMonitorLeaseDirectory(env: [String: String]) -> URL {
let statePath = NSString(
Expand Down Expand Up @@ -16789,13 +16790,31 @@ struct CMUXCLI {
return ownerFound ? .alive : .gone
}

private func codexMonitorOwnerProcessIsGone(_ ownerPID: Int?) -> Bool {
guard let ownerPID, ownerPID > 1 else { return false }
if kill(pid_t(ownerPID), 0) == 0 {
return false
}
return errno == ESRCH
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

private func codexMonitorUnresolvedTranscriptTimeout(env: [String: String]) -> TimeInterval {
guard let rawValue = env["CMUX_CODEX_MONITOR_UNRESOLVED_TRANSCRIPT_TIMEOUT_SECONDS"],
let parsed = TimeInterval(rawValue),
parsed > 0 else {
return Self.codexMonitorUnresolvedTranscriptTimeoutSeconds
}
return min(max(parsed, 0.05), Self.codexMonitorUnresolvedTranscriptTimeoutSeconds)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

private func startCodexTranscriptMonitor(
sessionId: String,
turnId: String?,
transcriptPath: String?,
cwd: String?,
workspaceId: String,
surfaceId: String?,
ownerPID: Int?,
leasePath: String?,
env: [String: String],
telemetry: CLISocketSentryTelemetry
Expand All @@ -16810,6 +16829,7 @@ struct CMUXCLI {
"has_turn_id": normalizedHookValue(turnId) != nil,
"has_transcript": normalizedHookValue(transcriptPath) != nil,
"has_surface_id": normalizedHookValue(surfaceId) != nil,
"has_owner_pid": ownerPID != nil,
]
telemetry.breadcrumb("codex-hook.monitor.start", data: monitorTelemetry)

Expand All @@ -16836,6 +16856,9 @@ struct CMUXCLI {
if let cwd, !cwd.isEmpty {
monitorArgs += ["--cwd", cwd]
}
if let ownerPID, ownerPID > 1 {
monitorArgs += ["--owner-pid", String(ownerPID)]
}
if let leasePath, !leasePath.isEmpty {
monitorArgs += ["--lease", leasePath]
}
Expand Down Expand Up @@ -16864,6 +16887,7 @@ struct CMUXCLI {
let turnId = optionValue(commandArgs, name: "--turn")
var transcriptPath = optionValue(commandArgs, name: "--transcript")
let leasePath = optionValue(commandArgs, name: "--lease")
let ownerPID = optionValue(commandArgs, name: "--owner-pid").flatMap(Int.init)

guard !workspaceId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty,
!sessionId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
Expand All @@ -16872,9 +16896,14 @@ struct CMUXCLI {

defer { removeCodexMonitorLease(path: leasePath) }
let deadline = Date().addingTimeInterval(4 * 60 * 60)
let unresolvedTranscriptTimeout = codexMonitorUnresolvedTranscriptTimeout(env: env)
var transcriptMissingSince: Date?
var nextOwnerCheck = Date.distantPast
var publishedUserInputCallIds = Set<String>()
while Date() < deadline {
if codexMonitorOwnerProcessIsGone(ownerPID) {
return
}
if isCodexMonitorLeaseRetired(path: leasePath) {
return
}
Expand All @@ -16889,6 +16918,15 @@ struct CMUXCLI {
if transcriptPath == nil {
transcriptPath = findCodexTranscriptPath(sessionId: sessionId, env: env)
}
if transcriptPath == nil {
let missingSince = transcriptMissingSince ?? now
transcriptMissingSince = missingSince
if now.timeIntervalSince(missingSince) >= unresolvedTranscriptTimeout {
return
}
} else {
transcriptMissingSince = nil
}

if let currentTranscriptPath = transcriptPath {
if let userInput = readCodexTranscriptUserInput(
Expand Down Expand Up @@ -16936,7 +16974,12 @@ struct CMUXCLI {

let remaining = deadline.timeIntervalSinceNow
guard remaining > 0 else { return }
waitForCodexTranscriptChange(path: transcriptPath, leasePath: leasePath, timeout: min(30, remaining))
var waitTimeout = min(30, remaining)
if let transcriptMissingSince {
let unresolvedRemaining = unresolvedTranscriptTimeout - Date().timeIntervalSince(transcriptMissingSince)
Comment thread
austinywang marked this conversation as resolved.
Resolved
waitTimeout = min(waitTimeout, max(0.05, unresolvedRemaining))
}
waitForCodexTranscriptChange(path: transcriptPath, leasePath: leasePath, timeout: waitTimeout)
}
}

Expand Down Expand Up @@ -19072,6 +19115,7 @@ export default function cmuxPiSessionExtension(pi: ExtensionAPI) {
cwd: hookCwd ?? mapped?.cwd,
workspaceId: workspaceId,
surfaceId: surfaceId,
ownerPID: pid,
leasePath: leasePath,
env: env,
telemetry: telemetry
Expand Down
20 changes: 20 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3982,6 +3982,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
var id: UUID { windowId }
}

struct WindowMoveTargetSnapshot: Identifiable, Equatable {
let windowId: UUID
let label: String
let isCurrentWindow: Bool

var id: UUID { windowId }
}

struct WorkspaceMoveTarget: Identifiable {
let windowId: UUID
let workspaceId: UUID
Expand All @@ -3996,6 +4004,18 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}

func windowMoveTargetSnapshots(referenceWindowId: UUID?) -> [WindowMoveTargetSnapshot] {
let orderedSummaries = orderedMainWindowSummaries(referenceWindowId: referenceWindowId)
let labels = windowLabelsById(orderedSummaries: orderedSummaries, referenceWindowId: referenceWindowId)
return orderedSummaries.map { summary in
WindowMoveTargetSnapshot(
windowId: summary.windowId,
label: labels[summary.windowId] ?? "Window",
isCurrentWindow: summary.windowId == referenceWindowId
)
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

func windowMoveTargets(referenceWindowId: UUID?) -> [WindowMoveTarget] {
let orderedSummaries = orderedMainWindowSummaries(referenceWindowId: referenceWindowId)
let labels = windowLabelsById(orderedSummaries: orderedSummaries, referenceWindowId: referenceWindowId)
Expand Down
37 changes: 32 additions & 5 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9104,6 +9104,7 @@ struct VerticalTabsSidebar: View {
@State private var terminalScrollBarVisibilityGeneration: UInt64 = 0
@State private var laidOutWorkspaceRowIds: Set<UUID> = []
@State private var pendingSelectedWorkspaceScrollId: UUID?
@State private var workspaceWindowMoveTargets: [AppDelegate.WindowMoveTargetSnapshot] = []
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
@AppStorage(WorkspacePresentationModeSettings.modeKey)
private var workspacePresentationMode = WorkspacePresentationModeSettings.defaultMode.rawValue
@AppStorage("sidebarMatchTerminalBackground")
Expand Down Expand Up @@ -9181,6 +9182,7 @@ struct VerticalTabsSidebar: View {
let allSelectedRemoteContextMenuTargetsConnecting: Bool
let allSelectedRemoteContextMenuTargetsDisconnected: Bool
let workspaceTerminalScrollBarHiddenById: [UUID: Bool]
let windowMoveTargets: [AppDelegate.WindowMoveTargetSnapshot]

var workspaceIds: [UUID] {
tabs.map(\.id)
Expand Down Expand Up @@ -9221,7 +9223,8 @@ struct VerticalTabsSidebar: View {
selectedRemoteContextMenuWorkspaceIds: selectedRemoteContextMenuWorkspaceIds,
allSelectedRemoteContextMenuTargetsConnecting: allSelectedRemoteContextMenuTargetsConnecting,
allSelectedRemoteContextMenuTargetsDisconnected: allSelectedRemoteContextMenuTargetsDisconnected,
workspaceTerminalScrollBarHiddenById: workspaceTerminalScrollBarHiddenById
workspaceTerminalScrollBarHiddenById: workspaceTerminalScrollBarHiddenById,
windowMoveTargets: workspaceWindowMoveTargets
)

ZStack(alignment: .bottomLeading) {
Expand All @@ -9240,6 +9243,15 @@ struct VerticalTabsSidebar: View {
}
.frame(width: 0, height: 0)
)
.onAppear {
refreshWorkspaceWindowMoveTargets()
}
.onReceive(
NotificationCenter.default.publisher(for: .mainWindowContextsDidChange)
.receive(on: RunLoop.main)
) { _ in
refreshWorkspaceWindowMoveTargets()
}
.onAppear {
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
modifierKeyMonitor.start()
draggedTabId = nil
Expand Down Expand Up @@ -9588,6 +9600,7 @@ struct VerticalTabsSidebar: View {
allRemoteContextMenuTargetsDisconnected: allRemoteContextMenuTargetsDisconnected,
allContextMenuWorkspacesHideTerminalScrollBar: allContextMenuWorkspacesHideTerminalScrollBar,
contextMenuPinState: contextMenuPinState,
workspaceWindowMoveTargets: renderContext.windowMoveTargets,
settings: renderContext.tabItemSettings,
livePresentation: livePresentation,
frozenPresentation: $frozenTabItemPresentation
Expand All @@ -9605,6 +9618,20 @@ struct VerticalTabsSidebar: View {
guard let id else { return "nil" }
return String(id.uuidString.prefix(5))
}

private func refreshWorkspaceWindowMoveTargets() {
guard let app = AppDelegate.shared else {
if !workspaceWindowMoveTargets.isEmpty {
workspaceWindowMoveTargets = []
}
return
}
let referenceWindowId = app.windowId(for: tabManager)
let targets = app.windowMoveTargetSnapshots(referenceWindowId: referenceWindowId)
if workspaceWindowMoveTargets != targets {
workspaceWindowMoveTargets = targets
}
}
}

private struct SidebarWorkspaceRowIdsPreferenceKey: PreferenceKey {
Expand Down Expand Up @@ -12010,6 +12037,7 @@ private struct TabItemView: View, Equatable {
lhs.allRemoteContextMenuTargetsDisconnected == rhs.allRemoteContextMenuTargetsDisconnected &&
lhs.allContextMenuWorkspacesHideTerminalScrollBar == rhs.allContextMenuWorkspacesHideTerminalScrollBar &&
lhs.contextMenuPinState == rhs.contextMenuPinState &&
lhs.workspaceWindowMoveTargets == rhs.workspaceWindowMoveTargets &&
lhs.settings == rhs.settings
}

Expand Down Expand Up @@ -12042,6 +12070,7 @@ private struct TabItemView: View, Equatable {
let allRemoteContextMenuTargetsDisconnected: Bool
let allContextMenuWorkspacesHideTerminalScrollBar: Bool
let contextMenuPinState: WorkspaceActionDispatcher.PinState?
let workspaceWindowMoveTargets: [AppDelegate.WindowMoveTargetSnapshot]
let settings: SidebarTabItemSettingsSnapshot
let livePresentation: SidebarTabItemPresentationSnapshot
@Binding var frozenPresentation: SidebarTabItemPresentationSnapshot?
Expand Down Expand Up @@ -12941,8 +12970,6 @@ private struct TabItemView: View, Equatable {
}
.disabled(targetIds.isEmpty)

let referenceWindowId = AppDelegate.shared?.windowId(for: tabManager)
let windowMoveTargets = AppDelegate.shared?.windowMoveTargets(referenceWindowId: referenceWindowId) ?? []
let moveMenuTitle = targetIds.count > 1
? String(localized: "contextMenu.moveWorkspacesToWindow", defaultValue: "Move Workspaces to Window")
: String(localized: "contextMenu.moveWorkspaceToWindow", defaultValue: "Move Workspace to Window")
Expand All @@ -12952,11 +12979,11 @@ private struct TabItemView: View, Equatable {
}
.disabled(targetIds.isEmpty)

if !windowMoveTargets.isEmpty {
if !workspaceWindowMoveTargets.isEmpty {
Divider()
}

ForEach(windowMoveTargets) { target in
ForEach(workspaceWindowMoveTargets) { target in
Button(target.label) {
moveWorkspaces(targetIds, toWindow: target.windowId)
}
Expand Down
65 changes: 49 additions & 16 deletions Sources/TerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,22 @@ class TerminalController {
return current.value != value || current.label != label
}

nonisolated static func shouldAppendLogEntry(
after last: SidebarLogEntry?,
message: String,
level: SidebarLogLevel,
source: String?,
now: Date
) -> Bool {
guard let last else { return true }
guard last.message == message,
last.level == level,
last.source == source else {
return true
}
return now.timeIntervalSince(last.timestamp) >= 5
}

nonisolated static func shouldReplaceGitBranch(
current: SidebarGitBranchState?,
branch: String,
Expand Down Expand Up @@ -16868,20 +16884,30 @@ class TerminalController {
}
let source = parsed.options["source"]

var result = "OK"
v2MainSync {
guard let tab = resolveTabForReport(args) else {
result = parsed.options["tab"] != nil ? "ERROR: Tab not found" : "ERROR: No tab selected"
let targetResolution = parseSidebarMutationTabTarget(options: parsed.options)
guard let target = targetResolution.target else {
return targetResolution.error ?? "ERROR: No tab selected"
}

scheduleSidebarMutation(target: target) { _, tab in
let now = Date()
guard Self.shouldAppendLogEntry(
after: tab.logEntries.last,
message: message,
level: level,
source: source,
now: now
) else {
return
}
tab.logEntries.append(SidebarLogEntry(message: message, level: level, source: source, timestamp: Date()))
tab.logEntries.append(SidebarLogEntry(message: message, level: level, source: source, timestamp: now))
let configuredLimit = UserDefaults.standard.object(forKey: "sidebarMaxLogEntries") as? Int ?? 50
let limit = max(1, min(500, configuredLimit))
if tab.logEntries.count > limit {
tab.logEntries.removeFirst(tab.logEntries.count - limit)
}
}
return result
return "OK"
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

private func clearLog(_ args: String) -> String {
Expand Down Expand Up @@ -16947,27 +16973,34 @@ class TerminalController {
let clamped = min(1.0, max(0.0, value))
let label = parsed.options["label"]

var result = "OK"
v2MainSync {
guard let tab = resolveTabForReport(args) else {
result = parsed.options["tab"] != nil ? "ERROR: Tab not found" : "ERROR: No tab selected"
let targetResolution = parseSidebarMutationTabTarget(options: parsed.options)
guard let target = targetResolution.target else {
return targetResolution.error ?? "ERROR: No tab selected"
}

scheduleSidebarMutation(target: target) { _, tab in
guard Self.shouldReplaceProgress(current: tab.progress, value: clamped, label: label) else {
return
}
tab.progress = SidebarProgressState(value: clamped, label: label)
}
return result
return "OK"
}

private func clearProgress(_ args: String) -> String {
var result = "OK"
v2MainSync {
guard let tab = resolveTabForReport(args) else {
result = "ERROR: Tab not found"
let parsed = parseOptions(args)
let targetResolution = parseSidebarMutationTabTarget(options: parsed.options)
guard let target = targetResolution.target else {
return targetResolution.error ?? "ERROR: No tab selected"
}

scheduleSidebarMutation(target: target) { _, tab in
guard tab.progress != nil else {
return
}
tab.progress = nil
}
return result
return "OK"
}

private func reportGitBranch(_ args: String) -> String {
Expand Down
Loading
Loading