Skip to content
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
a863d2e
test(ios): cover workspace group row actions
azooz2003-bit Jul 29, 2026
5852a4e
fix(ios): restore workspace group row actions
azooz2003-bit Jul 29, 2026
dcbe222
Merge remote-tracking branch 'origin/main' into feat-ios-workspace-gr…
azooz2003-bit Jul 29, 2026
383a002
test(ios): cover group destructive confirmations
azooz2003-bit Jul 29, 2026
c91a69f
test(ios): cover group read-state action refresh
azooz2003-bit Jul 30, 2026
6495e8b
fix(ios): refresh group native action state
azooz2003-bit Jul 30, 2026
79482c7
Merge remote-tracking branch 'origin/main' into feat-ios-workspace-gr…
azooz2003-bit Jul 30, 2026
7a3b692
test(ios): cover group native action inputs
azooz2003-bit Jul 30, 2026
1cd33d2
fix(ios): refresh group native action inputs
azooz2003-bit Jul 30, 2026
5bf4239
test(ios): cover group swipe completion and rename alert
azooz2003-bit Jul 30, 2026
98d8202
fix(ios): restore workspace preview compilation
azooz2003-bit Jul 30, 2026
5a17d72
test(ios): target visible group rename fixture
azooz2003-bit Jul 30, 2026
4562ce9
fix(ios): preserve group swipe completion and compact rename
azooz2003-bit Jul 30, 2026
2923db0
test(ios): exercise group action presentation lifecycles
azooz2003-bit Jul 30, 2026
6428040
test(ios): preserve workspace actions on group menus
azooz2003-bit Jul 30, 2026
ba6d8e3
fix(ios): preserve workspace actions on group menus
azooz2003-bit Jul 30, 2026
30a6069
test(ios): exercise full group read swipe
azooz2003-bit Jul 30, 2026
c3b4ed8
test(ios): isolate native group menu assertions
azooz2003-bit Jul 30, 2026
4a02f7a
test(ios): cover preserved group actions
azooz2003-bit Jul 30, 2026
e8c1907
test(ios): keep preview fixture state owned
azooz2003-bit Jul 30, 2026
70dda5f
test(ios): cover preserved group create actions
azooz2003-bit Jul 30, 2026
75a220c
fix(ios): preserve group creation entrypoints
azooz2003-bit Jul 30, 2026
f389789
fix(ios): make destructive group requests atomic
azooz2003-bit Jul 30, 2026
6aa95fb
test(ios): cover configured group icons
azooz2003-bit Jul 30, 2026
b6b3db6
fix(ios): sync effective group icons
azooz2003-bit Jul 30, 2026
ad14f05
test(ios): target live group row swipe
azooz2003-bit Jul 30, 2026
dbe530f
test(ios): disambiguate group workspace rename
azooz2003-bit Jul 31, 2026
508e8d4
fix(ios): disambiguate group workspace rename
azooz2003-bit Jul 31, 2026
0132ba3
test: cover disconnected iOS dogfood launch
azooz2003-bit Jul 31, 2026
9dc1c02
fix: require connected iOS dogfood launches
azooz2003-bit Jul 31, 2026
8001c38
fix: make mobile readiness event driven
azooz2003-bit Jul 31, 2026
2b37b81
Add failing iroh wake reconnect regressions
azooz2003-bit Jul 31, 2026
9dbeec4
Guarantee bounded foreground reconnect
azooz2003-bit Jul 31, 2026
399209e
fix: harden mobile readiness lifecycle
azooz2003-bit Jul 31, 2026
c2005f1
perf: buffer deadline event reads
azooz2003-bit Jul 31, 2026
3ee391d
Merge remote-tracking branch 'origin/main' into feat-reconnect-guarantee
azooz2003-bit Jul 31, 2026
b3066a4
Add failing test: session snapshot mid-revalidation must classify tra…
azooz2003-bit Jul 31, 2026
8cb0317
Classify transient token misses as connectivity, not authorization fa…
azooz2003-bit Jul 31, 2026
636d54f
Apply the same transient-token classification to the Mac host runtime
azooz2003-bit Jul 31, 2026
9d5b75a
Add failing wake-auth transport regressions
azooz2003-bit Jul 31, 2026
562fc11
Survive wake-time broker auth rejections without endpoint teardown
azooz2003-bit Jul 31, 2026
8092677
Handle route-gated diagnostics in iOS settings
azooz2003-bit Jul 31, 2026
8d45926
test: remove source-shape admission assertion
azooz2003-bit Jul 31, 2026
7155c52
test(iroh): cover cached registration recovery
azooz2003-bit Jul 31, 2026
714ad57
fix(iroh): recover cached host registration
azooz2003-bit Jul 31, 2026
a638f40
test connection readiness failures
azooz2003-bit Jul 31, 2026
a9c921e
test: cover cached host binding publication
azooz2003-bit Jul 31, 2026
5bc4fe4
fix: publish cached mobile host binding
azooz2003-bit Jul 31, 2026
91310a8
iOS: replace disconnect chrome with Mail-style status line under the …
azooz2003-bit Jul 31, 2026
6ac09fb
Harden mobile connection readiness
azooz2003-bit Jul 31, 2026
606957e
Keep subscription readiness separate from recovery
azooz2003-bit Jul 31, 2026
c880f54
Model delayed subscription acknowledgements
azooz2003-bit Jul 31, 2026
7f48bca
test: cover usable mobile session readiness
azooz2003-bit Jul 31, 2026
57927e5
Merge remote-tracking branch 'origin/main' into fix-ios-dogfood-conne…
azooz2003-bit Jul 31, 2026
0cea5bb
Merge PR 9252 iOS dogfood connection readiness
azooz2003-bit Jul 31, 2026
b72367d
Merge PR 9256 reconnect guarantee
azooz2003-bit Jul 31, 2026
32ede86
Merge PR 9259 iOS token hydration
azooz2003-bit Jul 31, 2026
8a41cfa
Merge PR 9263 iroh wake auth
azooz2003-bit Jul 31, 2026
8423af7
Merge PR 9276 reconnect status UX
azooz2003-bit Jul 31, 2026
9985728
Merge PR 9277 connection supervisor
azooz2003-bit Jul 31, 2026
629bfea
Merge PR 9252 usable mobile session readiness tests
azooz2003-bit Jul 31, 2026
da49a26
fix: require usable mobile connection readiness
azooz2003-bit Jul 31, 2026
15b10d3
Merge latest iOS dogfood readiness implementation
azooz2003-bit Jul 31, 2026
b5b7088
test: fail closed across broker auth cancellation
azooz2003-bit Jul 31, 2026
c83cb78
Merge origin/main into feat-ios-workspace-group-actions
azooz2003-bit Jul 31, 2026
ab73149
test: cover complete iOS dogfood readiness
azooz2003-bit Jul 31, 2026
0caabfb
Merge origin/main before iOS readiness implementation
azooz2003-bit Jul 31, 2026
6a68adc
test: fail closed when Mac pairing setup is unavailable
azooz2003-bit Jul 31, 2026
9cfcbf9
fix: make iOS dev reload dogfood ready
azooz2003-bit Jul 31, 2026
3c155c8
test: require ensure-mac to self-heal exact tag
azooz2003-bit Jul 31, 2026
5fd3eaa
fix: let ensure-mac relaunch its exact tag
azooz2003-bit Jul 31, 2026
667af4d
Merge remote-tracking branch 'refs/remotes/origin/main' into feat-ios…
azooz2003-bit Jul 31, 2026
4063190
fix(ios): keep list probe state coordinator-owned
azooz2003-bit Jul 31, 2026
5d1667b
Merge commit '6a68adcc26c9dab353fc49d03bf3ed1b605e12df' into feat-ios…
azooz2003-bit Jul 31, 2026
b326076
Merge commit '714ad573141812344ab35e4c45f4f52c6aeda5dd' into feat-ios…
azooz2003-bit Jul 31, 2026
2664fdd
Merge commit '406319049969275f1d8ec0be3e4123fd8ea886a6' into feat-ios…
azooz2003-bit Jul 31, 2026
039e2ac
Merge commit '667af4dae8' into feat-ios-group-actions-dogfood
azooz2003-bit Jul 31, 2026
59f92c1
test(ios): pass active listener to recovery validation
azooz2003-bit Jul 31, 2026
1855fac
test: cover unsigned simulator identity evidence
azooz2003-bit Jul 31, 2026
de00f9d
fix: trust seeded identity in unsigned simulator
azooz2003-bit Jul 31, 2026
4325164
test: disambiguate group rename alert save
azooz2003-bit Jul 31, 2026
1fe95ce
test: expose expired-ticket group rename failure
azooz2003-bit Jul 31, 2026
10b1ce3
Authorize mac-scoped workspace mutations by Stack account, not ticket…
Jul 21, 2026
2243855
test(ios): cover recovery transport drain
azooz2003-bit Aug 1, 2026
d826226
fix(ios): drain stale route before recovery
azooz2003-bit Aug 1, 2026
a017382
test: expose process-local readiness clock
azooz2003-bit Aug 1, 2026
2c19bf5
fix: use system monotonic readiness clock
azooz2003-bit Aug 1, 2026
7b7e397
test(ios): expose scoped-ticket group rename gap
azooz2003-bit Aug 1, 2026
de923f3
fix(ios): preserve account-authorized group actions
azooz2003-bit Aug 1, 2026
2ec354e
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 1, 2026
73ca185
test(ios): keep group menus group scoped
azooz2003-bit Aug 1, 2026
e7e6794
fix(ios): keep workspace group menus group scoped
azooz2003-bit Aug 1, 2026
7350bbc
fix(ios): pass readiness clock after main merge
azooz2003-bit Aug 1, 2026
5f9fcab
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 1, 2026
ea5abcd
test(ios): close group action review gaps
azooz2003-bit Aug 1, 2026
d77bd6f
Fix missing return in restoreCLIArgument (main compile break)
azooz2003-bit Aug 1, 2026
48be6ba
fix(ios): redact workspace mutation failure diagnostics
azooz2003-bit Aug 1, 2026
2ed0f88
fix(ios): stop presenting gated connect attempts as timeouts
azooz2003-bit Aug 1, 2026
76cc84e
fix(ios): add missing statusLine keys to MobileShellUI catalog
azooz2003-bit Aug 1, 2026
e51056b
fix(cli): monotonic events timeout budget, deterministic reconnect wait
azooz2003-bit Aug 1, 2026
bfb23a4
fix(ios): drop stale swiped-row identity on structural refresh
azooz2003-bit Aug 1, 2026
2625bd5
test(ios): align drop fixture with connection chrome
azooz2003-bit Aug 1, 2026
52257cd
fix: return validated restore argument
azooz2003-bit Aug 1, 2026
5b152d3
Merge remote-tracking branch 'origin/feat-ios-group-actions-dogfood' …
azooz2003-bit Aug 1, 2026
d39e558
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 1, 2026
a81343c
test(ios): port drop tests to the status-line WorkspaceListTable API
azooz2003-bit Aug 1, 2026
6e0db4d
Merge remote-tracking branch 'origin/feat-ios-group-actions-dogfood'
azooz2003-bit Aug 1, 2026
d300cba
test(ios): drop superseded relayPolicyRetrySchedule test
azooz2003-bit Aug 1, 2026
5507d0d
test(ios): drop superseded relay schedule assertion
azooz2003-bit Aug 1, 2026
1894d57
Merge remote-tracking branch 'origin/feat-ios-group-actions-dogfood' …
azooz2003-bit Aug 1, 2026
a04d756
test(ios): identify inherited group menu actions
azooz2003-bit Aug 1, 2026
1693d2a
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 1, 2026
ef172b4
test(ios): lock group menu action order
azooz2003-bit Aug 1, 2026
080534a
test(iroh): expose truncated registration discovery
azooz2003-bit Aug 1, 2026
267614e
fix(iroh): distrust truncated registration discovery
azooz2003-bit Aug 1, 2026
2f2c14d
test(connectivity): expose truncated sync snapshots
azooz2003-bit Aug 1, 2026
92836c4
fix(connectivity): prove complete sync snapshots
azooz2003-bit Aug 1, 2026
e2663be
test(connectivity): expose discovery revision races
azooz2003-bit Aug 1, 2026
2b55462
fix(connectivity): snapshot routes atomically
azooz2003-bit Aug 1, 2026
e7fcce0
test(ios): expose discovery blocking saved reconnect
azooz2003-bit Aug 1, 2026
3434b3f
fix(ios): prioritize saved routes during recovery
azooz2003-bit Aug 1, 2026
d897d16
test(connectivity): expose endpoint recovery race
azooz2003-bit Aug 1, 2026
2e935d9
fix(connectivity): await endpoint recovery before dialing
azooz2003-bit Aug 1, 2026
b12ed38
fix(connectivity): fail closed on offline auth fallback
azooz2003-bit Aug 2, 2026
ef08fc3
Harden mobile group actions and reconnect readiness
azooz2003-bit Aug 2, 2026
7e142e5
Include mobile debug registry source
azooz2003-bit Aug 2, 2026
429c29b
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 2, 2026
373c6ea
Fix group rename alert target lifetime
azooz2003-bit Aug 2, 2026
e36768c
Address workspace merge policy findings
azooz2003-bit Aug 3, 2026
bc3ece1
Scope reconnect policy to owning view
azooz2003-bit Aug 3, 2026
6a309a3
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 3, 2026
3912b3f
Fix SSH retry test diagnostic compilation
azooz2003-bit Aug 3, 2026
0996f82
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 3, 2026
2065939
Align host refresh tests with auth recovery
azooz2003-bit Aug 3, 2026
9204a9b
Merge remote-tracking branch 'origin/main' into feat-ios-group-action…
azooz2003-bit Aug 3, 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
69 changes: 55 additions & 14 deletions CLI/CMUXCLI+Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Darwin
import Foundation

private struct EventStreamLimitReached: Error {}
private struct EventStreamSnapshotCaptured: Error {}

extension CMUXCLI {
private struct EventsCommandOptions {
Expand All @@ -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
}
Expand All @@ -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
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
)

var params: [String: Any] = [
Expand All @@ -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 ?? ""
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.swift

Repository: 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.swift

Repository: manaflow-ai/cmux

Length of output: 6123


🌐 Web query:

Swift Timer fire date may not run run loop run method exit documentation

💡 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 RunLoop.current.run(...) with a cancellation-aware async wait.

At the retry boundary, the timer run loop blocks the current task and leaves didFire as the only exit. Add Task.checkCancellation()/withTaskCancellationHandler or an explicit completion signal, and avoid relying on the timer callback to unblock the retry loop.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CLI/CMUXCLI`+Events.swift around lines 165 - 170, Update
waitBeforeReconnectingEventStream to replace the RunLoop.current.run timer wait
with a cancellation-aware async delay or explicit completion signal. Ensure task
cancellation exits the retry wait promptly via Task.checkCancellation or
withTaskCancellationHandler, rather than relying solely on the didFire timer
callback.

Sources: Coding guidelines, Path instructions

didFire = true
}
RunLoop.current.add(timer, forMode: .default)
Expand Down Expand Up @@ -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":
Expand Down
90 changes: 75 additions & 15 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ final class SocketClient {

private let path: String
private(set) var socketFD: Int32 = -1
private var streamReadBuffer = Data()
private var lastConfiguredReceiveTimeout: TimeInterval?
private var lastOperationTelemetry: CLISocketOperationTelemetry.State?
private static let defaultResponseTimeoutSeconds: TimeInterval = 15.0
Expand Down Expand Up @@ -1967,6 +1968,7 @@ final class SocketClient {
Darwin.close(socketFD)
socketFD = -1
}
streamReadBuffer.removeAll(keepingCapacity: true)
lastConfiguredReceiveTimeout = nil
}

Expand Down Expand Up @@ -2951,6 +2953,7 @@ final class SocketClient {
func streamV2(
method: String,
params: [String: Any] = [:],
deadline: Date? = nil,
onLine: (String) throws -> Void
) throws {
guard socketFD >= 0 else { throw CLIError(message: "Not connected") }
Expand All @@ -2968,42 +2971,97 @@ final class SocketClient {
try writeAll(
Data((capabilityWrappedCommand(requestLine) + "\n").utf8),
timeoutMessage: "Stream request timed out",
failureMessage: "Failed to write stream request"
failureMessage: "Failed to write stream request",
deadline: deadline
)

while true {
let line = try readStreamLine()
let line = try readStreamLine(deadline: deadline)
try onLine(line)
}
}

private func readStreamLine(maxBytes: Int = 4 * 1024 * 1024) throws -> String {
var data = Data()
try configureReceiveTimeout(45)
while data.count < maxBytes {
var byte: UInt8 = 0
let count = Darwin.read(socketFD, &byte, 1)
private func readStreamLine(
maxBytes: Int = 4 * 1024 * 1024,
deadline: Date? = nil
) throws -> String {
if deadline == nil {
try configureReceiveTimeout(45)
}
while true {
if let newlineIndex = streamReadBuffer.firstIndex(of: 0x0A) {
let lineByteCount = streamReadBuffer.distance(
from: streamReadBuffer.startIndex,
to: newlineIndex
)
guard lineByteCount < maxBytes else {
throw CLIError(message: "Event stream frame exceeded \(maxBytes) bytes")
}
let lineData = streamReadBuffer[..<newlineIndex]
guard let line = String(data: Data(lineData), encoding: .utf8) else {
throw CLIError(message: "Invalid UTF-8 event stream frame")
}
streamReadBuffer.removeSubrange(...newlineIndex)
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
return line.trimmingCharacters(in: .whitespacesAndNewlines)
}
guard streamReadBuffer.count < maxBytes else {
throw CLIError(message: "Event stream frame exceeded \(maxBytes) bytes")
}
if let deadline {
try waitForReadableStream(deadline: deadline)
}
var chunk = [UInt8](repeating: 0, count: 8 * 1_024)
let count = chunk.withUnsafeMutableBytes { bytes in
Darwin.read(socketFD, bytes.baseAddress, bytes.count)
}
if count < 0 {
if errno == EINTR {
continue
}
if errno == EAGAIN || errno == EWOULDBLOCK {
if let deadline {
guard deadline.timeIntervalSinceNow > 0 else {
throw CLIError(message: "Event stream deadline exceeded")
}
continue
}
throw CLIError(message: "Timed out waiting for event stream frame")
}
throw CLIError(message: "Event stream socket read error")
}
if count == 0 {
throw CLIError(message: "Event stream closed")
}
if byte == 0x0A {
guard let line = String(data: data, encoding: .utf8) else {
throw CLIError(message: "Invalid UTF-8 event stream frame")
}
return line.trimmingCharacters(in: .whitespacesAndNewlines)
streamReadBuffer.append(contentsOf: chunk.prefix(count))
}
}

private func waitForReadableStream(deadline: Date) throws {
while true {
let remaining = deadline.timeIntervalSinceNow
guard remaining > 0 else {
throw CLIError(message: "Event stream deadline exceeded")
}
var descriptor = pollfd(fd: socketFD, events: Int16(POLLIN), revents: 0)
let timeoutMilliseconds = min(
max(Int(ceil(remaining * 1_000)), 0),
Int(Int32.max)
)
let ready = Darwin.poll(
&descriptor,
1,
Int32(timeoutMilliseconds)
)
if ready > 0 {
return
}
if ready == 0 {
throw CLIError(message: "Event stream deadline exceeded")
}
if errno != EINTR {
throw CLIError(message: "Event stream socket read error")
}
data.append(byte)
}
throw CLIError(message: "Event stream frame exceeded \(maxBytes) bytes")
}
}

Expand Down Expand Up @@ -15520,6 +15578,8 @@ struct CMUXCLI {
--category <name> Filter by category, repeatable
--reconnect Reconnect forever and resume from the last received sequence
--limit <n> Exit after printing n event frames
--timeout <seconds> Exit unsuccessfully if no matching event arrives before the deadline
--snapshot Print the subscription snapshot and exit
--no-ack Do not print the subscription ack frame
--no-heartbeat Do not print heartbeat frames

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ public struct DiagnosticReport: Sendable, Codable, Equatable {
}

/// The latest event that marks a failed connection/lifecycle milestone.
/// A `cancelled` outcome is an abandoned attempt, not a failure: callers
/// cancel dials on supersession and teardown, so surfacing one here would
/// report routine churn as the connection's latest problem.
public var lastFailureEvent: DiagnosticEvent? {
events.last(where: { event in
event.code.isDiagnosticFailure
|| event.diagnosticFailureKind.map { $0 != .none } == true
if let kind = event.diagnosticFailureKind {
return kind != .none && kind != .cancelled
}
return event.code.isDiagnosticFailure
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public enum DiagnosticFailureKind: Int, Sendable, Codable, CaseIterable {
/// event queue overflowed while the transport stopped draining (for
/// example the peer's network path died mid-write).
case sendQueueOverflow = 24
/// The connect-attempt registry refused a dial because the route was held
/// by an in-flight or recently abandoned dial, or hard-gated after
/// repeated abandoned attempts. Distinguishes gate refusals from genuine
/// dial timeouts in exports.
case routeGated = 25
case unknown = 255

/// Reduces a typed or system error to the bounded diagnostic vocabulary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public struct GroupSyncRecord: MobileSyncRecord {
public let isCollapsed: Bool
/// Whether the group is pinned on the Mac.
public let isPinned: Bool
/// SF Symbol rendered by the corresponding group row on the Mac.
public let iconSymbol: String?
/// The anchor workspace that owns this group.
public let anchorWorkspaceID: String
/// Position in the Mac's presented section order.
Expand All @@ -219,13 +221,15 @@ public struct GroupSyncRecord: MobileSyncRecord {
name: String,
isCollapsed: Bool,
isPinned: Bool,
iconSymbol: String? = nil,
anchorWorkspaceID: String,
sortIndex: Int
) {
self.id = id
self.name = name
self.isCollapsed = isCollapsed
self.isPinned = isPinned
self.iconSymbol = iconSymbol
self.anchorWorkspaceID = anchorWorkspaceID
self.sortIndex = sortIndex
}
Expand All @@ -235,6 +239,7 @@ public struct GroupSyncRecord: MobileSyncRecord {
case name
case isCollapsed = "is_collapsed"
case isPinned = "is_pinned"
case iconSymbol = "icon_symbol"
case anchorWorkspaceID = "anchor_workspace_id"
case sortIndex = "sort_index"
}
Expand Down
Loading