Repository navigation
Make iOS workspace groups and reconnect dogfood-ready #9326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 91 commits
a863d2e
5852a4e
dcbe222
383a002
c91a69f
6495e8b
79482c7
7a3b692
1cd33d2
5bf4239
98d8202
5a17d72
4562ce9
2923db0
6428040
ba6d8e3
30a6069
c3b4ed8
4a02f7a
e8c1907
70dda5f
75a220c
f389789
6aa95fb
b6b3db6
ad14f05
dbe530f
508e8d4
0132ba3
9dc1c02
8001c38
2b37b81
9dbeec4
399209e
c2005f1
3ee391d
b3066a4
8cb0317
636d54f
9d5b75a
562fc11
8092677
8d45926
7155c52
714ad57
a638f40
a9c921e
5bc4fe4
91310a8
6ac09fb
606957e
c880f54
7f48bca
57927e5
0cea5bb
b72367d
32ede86
8a41cfa
8423af7
9985728
629bfea
da49a26
15b10d3
b5b7088
c83cb78
ab73149
0caabfb
6a68adc
9cfcbf9
3c155c8
5fd3eaa
667af4d
4063190
5d1667b
b326076
2664fdd
039e2ac
59f92c1
1855fac
de00f9d
4325164
1fe95ce
10b1ce3
2243855
d826226
a017382
2c19bf5
7b7e397
de923f3
2ec354e
73ca185
e7e6794
7350bbc
5f9fcab
ea5abcd
d77bd6f
48be6ba
2ed0f88
76cc84e
e51056b
bfb23a4
2625bd5
52257cd
5b152d3
d39e558
a81343c
6e0db4d
d300cba
5507d0d
1894d57
a04d756
1693d2a
ef172b4
080534a
267614e
2f2c14d
92836c4
e2663be
2b55462
e7fcce0
3434b3f
d897d16
2e935d9
b12ed38
ef08fc3
7e142e5
429c29b
373c6ea
e36768c
bc3ece1
6a309a3
3912b3f
0996f82
2065939
9204a9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import Darwin | |
| import Foundation | ||
|
|
||
| private struct EventStreamLimitReached: Error {} | ||
| private struct EventStreamSnapshotCaptured: Error {} | ||
|
|
||
| extension CMUXCLI { | ||
| private struct EventsCommandOptions { | ||
|
|
@@ -12,6 +13,8 @@ extension CMUXCLI { | |
| var categories: [String] = [] | ||
| var reconnect = false | ||
| var limit: Int? | ||
| var timeout: TimeInterval? | ||
| var snapshotOnly = false | ||
| var printAck = true | ||
| var printHeartbeats = true | ||
| } | ||
|
|
@@ -28,15 +31,25 @@ extension CMUXCLI { | |
|
|
||
| var lastSeq = options.afterSeq | ||
| var emittedEvents = 0 | ||
| let deadline = options.timeout.map { Date.now.addingTimeInterval($0) } | ||
|
|
||
| while true { | ||
| if let deadline, Date.now >= deadline { | ||
| throw CLIError(message: "Timed out waiting for a matching event") | ||
| } | ||
| let client = SocketClient(path: socketPath) | ||
| do { | ||
| try client.connect() | ||
| if let deadline { | ||
| try client.connect(deadline: deadline) | ||
| } else { | ||
| try client.connect() | ||
| } | ||
| try authenticateClientIfNeeded( | ||
| client, | ||
| explicitPassword: explicitPassword, | ||
| socketPath: socketPath | ||
| socketPath: socketPath, | ||
| responseTimeout: deadline?.timeIntervalSinceNow, | ||
| deadline: deadline | ||
| ) | ||
|
|
||
| var params: [String: Any] = [ | ||
|
|
@@ -52,7 +65,11 @@ extension CMUXCLI { | |
| params["categories"] = options.categories | ||
| } | ||
|
|
||
| try client.streamV2(method: "events.stream", params: params) { line in | ||
| try client.streamV2( | ||
| method: "events.stream", | ||
| params: params, | ||
| deadline: deadline | ||
| ) { line in | ||
| guard !line.isEmpty else { return } | ||
| let frame = try parseEventStreamFrame(line) | ||
| let type = frame["type"] as? String ?? "" | ||
|
|
@@ -67,15 +84,17 @@ extension CMUXCLI { | |
| eventSequence = nil | ||
| } | ||
|
|
||
| if type == "ack", !options.printAck { | ||
| return | ||
| } | ||
| if type == "heartbeat", !options.printHeartbeats { | ||
| return | ||
| let shouldPrint = | ||
| (type != "ack" || options.printAck) | ||
| && (type != "heartbeat" || options.printHeartbeats) | ||
| if shouldPrint { | ||
| print(line) | ||
| fflush(stdout) | ||
| } | ||
|
|
||
| print(line) | ||
| fflush(stdout) | ||
| if type == "ack", options.snapshotOnly { | ||
| throw EventStreamSnapshotCaptured() | ||
| } | ||
|
|
||
| if let eventSequence { | ||
| if let cursorFile = options.cursorFile { | ||
|
|
@@ -88,15 +107,25 @@ extension CMUXCLI { | |
| } | ||
| } | ||
| } | ||
| } catch is EventStreamSnapshotCaptured { | ||
| client.close() | ||
| return | ||
| } catch is EventStreamLimitReached { | ||
| client.close() | ||
| return | ||
| } catch { | ||
| client.close() | ||
| if let deadline, Date.now >= deadline { | ||
| throw CLIError(message: "Timed out waiting for a matching event") | ||
| } | ||
| guard options.reconnect, isTransientEventStreamError(error) else { | ||
| throw error | ||
| } | ||
| waitBeforeReconnectingEventStream() | ||
| let remaining = deadline?.timeIntervalSinceNow ?? 1 | ||
| guard remaining > 0 else { | ||
| throw CLIError(message: "Timed out waiting for a matching event") | ||
| } | ||
| waitBeforeReconnectingEventStream(maximumDelay: remaining) | ||
| continue | ||
| } | ||
| } | ||
|
|
@@ -133,10 +162,12 @@ extension CMUXCLI { | |
| || description.contains("timed out") | ||
| } | ||
|
|
||
| func waitBeforeReconnectingEventStream() { | ||
| let deadline = Date(timeIntervalSinceNow: 1.0) | ||
| func waitBeforeReconnectingEventStream(maximumDelay: TimeInterval = 1) { | ||
| let delay = min(1, max(0, maximumDelay)) | ||
| guard delay > 0 else { return } | ||
| let deadline = Date(timeIntervalSinceNow: delay) | ||
| var didFire = false | ||
| let timer = Timer(timeInterval: 1.0, repeats: false) { _ in | ||
| let timer = Timer(timeInterval: delay, repeats: false) { _ in | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
rg -n -C 12 \
'waitBeforeReconnectingEventStream|RunLoop\.current\.run|Timer\(timeInterval|ContinuousClock|Task\.sleep|withTaskCancellationHandler' \
--glob '*.swift' .Repository: manaflow-ai/cmux Length of output: 50373 🏁 Script executed: #!/usr/bin/env/bash
set -euo pipefail
# Locate the target file and print only the relevant definition/call sites.
fd -a 'CMUXCLI+Events\.swift' . | sed 's#^\./##'
printf '\n--- target excerpt ---\n'
sed -n '130,220p' CLI/CMUXCLI+Events.swift | nl -ba -v130
printf '\n--- callsites of waitBeforeReconnectingEventStream in Swift ---\n'
rg -n -C 6 "waitBeforeReconnectingEventStream" --glob '*.swift' .
printf '\n--- focused matches ---\n'
rg -n "waitBeforeReconnectingEventStream|RunLoop\.current\.run|Timer\(timeInterval|continuous|continue" CLI/CMUXCLI+Events.swiftRepository: manaflow-ai/cmux Length of output: 218 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' "--- target excerpt ---"
awk 'NR>=130 && NR<=220 { printf "%4d\t%s\n", NR, $0 }' CLI/CMUXCLI+Events.swift
printf '%s\n' "--- callsites of waitBeforeReconnectingEventStream in Swift ---"
grep -RIn -C 6 "waitBeforeReconnectingEventStream" --include='*.swift' .
printf '%s\n' "--- focused matches in target file ---"
grep -n "waitBeforeReconnectingEventStream\|RunLoop\.current\.run\|Timer\(timeInterval\|continuous\|continue" CLI/CMUXCLI+Events.swiftRepository: manaflow-ai/cmux Length of output: 6123 🌐 Web query:
💡 Result: A Swift Timer requires an active run loop to fire [1][2][3]. When a timer is created, it must be added to a run loop (or scheduled automatically via class methods like scheduledTimer) to function [2][3][4]. The run loop is responsible for monitoring the timer and invoking its action when the fire date is reached [1][2]. Regarding the behavior of run loop methods and timer exits: 1. Run Loop Methods and Exits: The run method starts an infinite loop and does not return unless it is stopped or has no input sources or timers attached [5]. However, even if you remove all known timers and input sources, the run loop is not guaranteed to exit immediately, as system frameworks may install and remove additional sources as needed [5][6]. 2. Timers do not cause Run Loop exit: Unlike other input sources that may cause methods like run(mode:before:) to return after processing, timer sources deliver events to their handlers but do not inherently cause the run loop to exit [1]. 3. Method Returns: Methods such as run(mode:before:) return after either a timeout is reached, or an input source is processed [6]. They return true if the loop ran and processed a source or if the timeout was reached; they return false if the run loop could not be started [6]. Because of these behaviors, it is recommended not to rely on the presence or absence of timers as a deterministic way to exit a run loop [5][6]. Instead, you should control the run loop’s lifecycle using an explicit flag or condition check within a custom loop structure, ensuring that you manage the state of the run loop independently of the timer's existence [5]. Citations:
Replace At the retry boundary, the timer run loop blocks the current task and leaves 🤖 Prompt for AI AgentsSources: Coding guidelines, Path instructions |
||
| didFire = true | ||
| } | ||
| RunLoop.current.add(timer, forMode: .default) | ||
|
|
@@ -178,6 +209,16 @@ extension CMUXCLI { | |
| throw CLIError(message: "--limit must be greater than 0") | ||
| } | ||
| options.limit = limit | ||
| case "--timeout": | ||
| let raw = try requireValue() | ||
| guard let timeout = TimeInterval(raw), | ||
| timeout.isFinite, | ||
| timeout > 0 else { | ||
| throw CLIError(message: "--timeout must be greater than 0") | ||
| } | ||
| options.timeout = timeout | ||
| case "--snapshot": | ||
| options.snapshotOnly = true | ||
| case "--no-ack": | ||
| options.printAck = false | ||
| case "--no-heartbeat", "--no-heartbeats": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.