Skip to content
Closed
Show file tree
Hide file tree
Changes from 23 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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ jobs:
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_contract_help.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_layout_focus_contract.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_socket_operation_deadline.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_codex_feed_hooks.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_omo_openagent_plugin_migration.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_socket_autodiscovery.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_claude_hook_clear_running_status.py
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ jobs:
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_contract_help.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_layout_focus_contract.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_socket_operation_deadline.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_codex_feed_hooks.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_omo_openagent_plugin_migration.py
CMUX_CLI_BIN="$CLI_BIN" python3 tests/test_cli_socket_autodiscovery.py
python3 tests/test_claude_wrapper_hooks.py
Expand Down
114 changes: 107 additions & 7 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,28 @@ struct CMUXCLI {
private static let vmCreateResponseTimeoutSeconds: TimeInterval = 16 * 60
private static let vmAttachResponseTimeoutSeconds: TimeInterval = 16 * 60

private final class CodexTranscriptChangeWaiter: @unchecked Sendable {
private let condition = NSCondition()
private var didObserveChange = false

func signal() {
condition.lock()
didObserveChange = true
condition.signal()
condition.unlock()
}

func wait(until deadline: Date) {
condition.lock()
while !didObserveChange, Date() < deadline {
if !condition.wait(until: deadline) {
break
}
}
condition.unlock()
}
}

private func captureSocketTransportError(telemetry: CLISocketSentryTelemetry, stage: String, error: Error, client: SocketClient) {
if client.hasUnfinishedOperationTelemetry() {
telemetry.captureError(stage: stage, error: error, data: client.operationTelemetryContext())
Expand Down Expand Up @@ -18938,6 +18960,8 @@ struct CMUXCLI {
private static let codexMonitorRetiredLeaseMaxAgeSeconds: TimeInterval = 2 * 60
private static let codexMonitorOwnerCheckIntervalSeconds: TimeInterval = 60
private static let codexMonitorOwnerCheckTimeoutSeconds: TimeInterval = 1
private static let codexMonitorOwnerProcessPollIntervalSeconds: TimeInterval = 1
private static let codexMonitorUnresolvedTranscriptTimeoutSeconds: TimeInterval = 5 * 60

private func codexMonitorLeaseDirectory(env: [String: String]) -> URL {
let statePath = NSString(
Expand Down Expand Up @@ -19098,13 +19122,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
}

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 max(parsed, 0.05)
}

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 @@ -19114,11 +19156,20 @@ struct CMUXCLI {
return
}

let validOwnerPID = ownerPID.flatMap { $0 > 1 ? $0 : nil }
if ownerPID != nil, validOwnerPID == nil {
telemetry.breadcrumb(
"codex-hook.monitor.invalid-owner-pid",
data: ["owner_pid": ownerPID ?? -1]
)
}

let monitorTelemetry: [String: Any] = [
"has_lease": normalizedHookValue(leasePath) != nil,
"has_turn_id": normalizedHookValue(turnId) != nil,
"has_transcript": normalizedHookValue(transcriptPath) != nil,
"has_surface_id": normalizedHookValue(surfaceId) != nil,
"has_owner_pid": validOwnerPID != nil,
]
telemetry.breadcrumb("codex-hook.monitor.start", data: monitorTelemetry)

Expand All @@ -19145,6 +19196,9 @@ struct CMUXCLI {
if let cwd, !cwd.isEmpty {
monitorArgs += ["--cwd", cwd]
}
if let ownerPID = validOwnerPID {
monitorArgs += ["--owner-pid", String(ownerPID)]
}
if let leasePath, !leasePath.isEmpty {
monitorArgs += ["--lease", leasePath]
}
Expand All @@ -19161,7 +19215,11 @@ struct CMUXCLI {
}
}

private func runCodexTranscriptMonitor(commandArgs: [String], client: SocketClient) throws {
private func runCodexTranscriptMonitor(
commandArgs: [String],
client: SocketClient,
telemetry: CLISocketSentryTelemetry
) throws {
let env = ProcessInfo.processInfo.environment
let workspaceId = optionValue(commandArgs, name: "--workspace") ?? env["CMUX_WORKSPACE_ID"] ?? ""
let surfaceId = optionValue(commandArgs, name: "--surface") ?? env["CMUX_SURFACE_ID"]
Expand All @@ -19173,6 +19231,24 @@ struct CMUXCLI {
let turnId = optionValue(commandArgs, name: "--turn")
var transcriptPath = optionValue(commandArgs, name: "--transcript")
let leasePath = optionValue(commandArgs, name: "--lease")
let ownerPID: Int?
if let rawOwnerPID = optionValue(commandArgs, name: "--owner-pid") {
guard let parsedOwnerPID = Int(rawOwnerPID), parsedOwnerPID > 1 else {
telemetry.breadcrumb(
"codex-hook.monitor.invalid-owner-pid",
data: ["raw": rawOwnerPID]
)
throw CLIError(
message: String(
localized: "cli.error.codexMonitorInvalidOwnerPID",
defaultValue: "hooks codex monitor: --owner-pid must be an integer greater than 1"
)
)
}
ownerPID = parsedOwnerPID
} else {
ownerPID = nil
}

guard !workspaceId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty,
!sessionId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
Expand All @@ -19181,9 +19257,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 @@ -19198,6 +19279,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 @@ -19245,7 +19335,15 @@ 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)
waitTimeout = min(waitTimeout, max(0.05, unresolvedRemaining))
}
if ownerPID != nil {
waitTimeout = min(waitTimeout, Self.codexMonitorOwnerProcessPollIntervalSeconds)
}
waitForCodexTranscriptChange(path: transcriptPath, leasePath: leasePath, timeout: waitTimeout)
}
}

Expand Down Expand Up @@ -19291,7 +19389,8 @@ struct CMUXCLI {
private func waitForCodexTranscriptChange(path: String?, leasePath: String?, timeout: TimeInterval) {
guard timeout > 0 else { return }

let semaphore = DispatchSemaphore(value: 0)
let waiter = CodexTranscriptChangeWaiter()
let deadline = Date().addingTimeInterval(timeout)
var sources: [DispatchSourceFileSystemObject] = []

func addFileSource(path: String?, eventMask: DispatchSource.FileSystemEvent) {
Expand All @@ -19305,7 +19404,7 @@ struct CMUXCLI {
queue: DispatchQueue.global(qos: .utility)
)
source.setEventHandler {
semaphore.signal()
waiter.signal()
}
source.setCancelHandler {
close(fd)
Expand All @@ -19318,11 +19417,11 @@ struct CMUXCLI {
addFileSource(path: leasePath, eventMask: [.write, .delete, .rename])

guard !sources.isEmpty else {
_ = DispatchSemaphore(value: 0).wait(timeout: .now() + timeout)
waiter.wait(until: deadline)
return
}

_ = semaphore.wait(timeout: .now() + timeout)
waiter.wait(until: deadline)
sources.forEach { $0.cancel() }
}

Expand Down Expand Up @@ -22298,7 +22397,7 @@ export default function cmuxPiSessionExtension(pi: ExtensionAPI) {
telemetry.breadcrumb("\(def.name)-hook.\(subcommand)")

if def.name == "codex", subcommand == "monitor" {
try runCodexTranscriptMonitor(commandArgs: hookArgs, client: client)
try runCodexTranscriptMonitor(commandArgs: hookArgs, client: client, telemetry: telemetry)
return
}

Expand Down Expand Up @@ -22665,6 +22764,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
1 change: 1 addition & 0 deletions Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"sourceLanguage": "en",
"version": "1.0",
Comment thread
austinywang marked this conversation as resolved.
Resolved
"strings": {
"cli.error.codexMonitorInvalidOwnerPID": { "extractionState": "manual", "localizations": { "ar": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: يجب أن تكون --owner-pid عددًا صحيحًا أكبر من 1" } }, "bs": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid mora biti cijeli broj veći od 1" } }, "da": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid skal være et heltal større end 1" } }, "de": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid muss eine ganze Zahl größer als 1 sein" } }, "en": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid must be an integer greater than 1" } }, "es": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid debe ser un entero mayor que 1" } }, "fr": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid doit être un entier supérieur à 1" } }, "it": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid deve essere un numero intero maggiore di 1" } }, "ja": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid には 1 より大きい整数を指定してください" } }, "ko": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid는 1보다 큰 정수여야 합니다" } }, "nb": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid må være et heltall større enn 1" } }, "pl": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid musi być liczbą całkowitą większą niż 1" } }, "pt-BR": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid deve ser um inteiro maior que 1" } }, "ru": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid должен быть целым числом больше 1" } }, "th": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid ต้องเป็นจำนวนเต็มที่มากกว่า 1" } }, "tr": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid 1'den büyük bir tam sayı olmalıdır" } }, "uk": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid має бути цілим числом більше 1" } }, "zh-Hans": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid 必须是大于 1 的整数" } }, "zh-Hant": { "stringUnit": { "state": "translated", "value": "hooks codex monitor: --owner-pid 必須是大於 1 的整數" } } } },
"cli.hooks.error.configDirectoryIsFile": { "extractionState": "manual", "localizations": { "en": { "stringUnit": { "state": "translated", "value": "cmux could not create the hooks directory: a file exists at %@; remove or rename the conflicting file and re-run `cmux hooks setup`" } }, "ja": { "stringUnit": { "state": "translated", "value": "cmux は hooks ディレクトリを作成できませんでした: %@ にファイルがあります。競合するファイルを削除または名前変更してから `cmux hooks setup` を再実行してください" } } } },
"cli.error.dismissNotificationSelector": { "extractionState": "manual", "localizations": { "en": { "stringUnit": { "state": "translated", "value": "dismiss-notification requires exactly one of --id or --all-read" } }, "ja": { "stringUnit": { "state": "translated", "value": "dismiss-notification には --id または --all-read のどちらか一方だけを指定してください" } } } },
"cli.error.markNotificationReadSelector": { "extractionState": "manual", "localizations": { "en": { "stringUnit": { "state": "translated", "value": "mark-notification-read requires exactly one selector: --id, --workspace, or --all" } }, "ja": { "stringUnit": { "state": "translated", "value": "mark-notification-read には --id、--workspace、--all のいずれか一つだけを指定してください" } } } },
Expand Down
55 changes: 55 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent

var mainWindowContexts: [ObjectIdentifier: MainWindowContext] = [:]
private var mainWindowControllers: [MainWindowController] = []
private var windowMoveTargetSnapshotCache: [WindowMoveTargetSnapshotCacheKey: WindowMoveTargetSnapshotCacheEntry] = [:]

/// Tracks the cascade point for new windows, matching Ghostty's upstream algorithm.
/// Reset to `.zero` so the first window seeds the point from its own position.
Expand Down Expand Up @@ -3951,6 +3952,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
#endif

private func notifyMainWindowContextsDidChange() {
windowMoveTargetSnapshotCache.removeAll()
NotificationCenter.default.post(name: .mainWindowContextsDidChange, object: self)
}

Expand Down Expand Up @@ -4104,6 +4106,23 @@ 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 }
}

private struct WindowMoveTargetSnapshotCacheKey: Hashable {
let referenceWindowId: UUID?
}

private struct WindowMoveTargetSnapshotCacheEntry {
let orderingFingerprint: String
let snapshots: [WindowMoveTargetSnapshot]
}

struct WorkspaceMoveTarget: Identifiable {
let windowId: UUID
let workspaceId: UUID
Expand All @@ -4118,6 +4137,30 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}

func windowMoveTargetSnapshots(referenceWindowId: UUID?) -> [WindowMoveTargetSnapshot] {
let orderedSummaries = orderedMainWindowSummaries(referenceWindowId: referenceWindowId)
let cacheKey = WindowMoveTargetSnapshotCacheKey(referenceWindowId: referenceWindowId)
let fingerprint = windowMoveTargetOrderingFingerprint(orderedSummaries)
if let cached = windowMoveTargetSnapshotCache[cacheKey],
cached.orderingFingerprint == fingerprint {
return cached.snapshots
}

let labels = windowLabelsById(orderedSummaries: orderedSummaries, referenceWindowId: referenceWindowId)
let snapshots = orderedSummaries.map { summary in
WindowMoveTargetSnapshot(
windowId: summary.windowId,
label: labels[summary.windowId] ?? "Window",
isCurrentWindow: summary.windowId == referenceWindowId
)
}
windowMoveTargetSnapshotCache[cacheKey] = WindowMoveTargetSnapshotCacheEntry(
orderingFingerprint: fingerprint,
snapshots: snapshots
)
return snapshots
}
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 Expand Up @@ -5163,6 +5206,18 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}

private func windowMoveTargetOrderingFingerprint(_ summaries: [MainWindowSummary]) -> String {
summaries.map { summary in
[
summary.windowId.uuidString,
summary.isKeyWindow ? "key" : "not-key",
summary.isVisible ? "visible" : "hidden",
String(summary.workspaceCount),
summary.selectedWorkspaceId?.uuidString ?? "none",
].joined(separator: ":")
}.joined(separator: "|")
}

private func windowLabelsById(orderedSummaries: [MainWindowSummary], referenceWindowId: UUID?) -> [UUID: String] {
var labels: [UUID: String] = [:]
for (index, summary) in orderedSummaries.enumerated() {
Expand Down
Loading
Loading