Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9b84ba3
Add regression for repaired input event subscription
Jun 26, 2026
ba1a1d2
Replay after repaired input subscription
Jun 26, 2026
8b204d3
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
Jun 26, 2026
7111dad
Refresh Swift file length budget
Jun 26, 2026
d74b973
Add regression for global input repair replay
Jun 26, 2026
6137690
Replay all mounted surfaces after input repair
Jun 26, 2026
217a11a
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
Jun 27, 2026
caca4e9
Add regression for empty-list subscription repair
Jun 27, 2026
6e59027
Repair empty-list subscription refreshes
Jun 27, 2026
0f12da4
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
Jun 27, 2026
1a00bcd
Gate iOS glass APIs by compiler
Jun 27, 2026
7420df5
Gate chat scroll edge APIs by compiler
Jun 27, 2026
61c2972
Fix chat UI older compiler build
Jun 27, 2026
b3e3317
Use window lifecycle for keyboard tap cleanup
Jun 27, 2026
70699ec
Gate chat composer glass container
Jun 27, 2026
deef8e5
Allow composer icon labels in nonisolated closures
Jun 27, 2026
2834052
Allow hardware key commands in static tables
Jun 27, 2026
317bc03
Isolate hardware key command creation
Jun 27, 2026
2aaec53
Make Ghostty surface queue hops sendable
Jun 27, 2026
2f3f01e
Avoid isolated deinit in mobile shell
Jun 27, 2026
b4b68cf
Gate mobile shell glass containers
Jun 27, 2026
52aa765
Avoid sending notification settings to main actor
Jun 27, 2026
5e47ca7
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
austinywang Jun 30, 2026
5746089
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
austinywang Jul 2, 2026
da8bdf3
Add failing test: repaired replay must supersede in-flight cold-attac…
austinywang Jul 2, 2026
01602a0
Supersede in-flight replay when replaying a repaired subscription
austinywang Jul 2, 2026
27661fe
Refresh Swift file length budget
austinywang Jul 2, 2026
56b1775
Restore actor-isolated deinit on Swift 6.2+ toolchains
austinywang Jul 2, 2026
e45854d
Fail fast when TerminalOutputCollector.waitForLineCount undershoots
austinywang Jul 2, 2026
f2911ff
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
austinywang Jul 2, 2026
4cd0fa2
Merge origin/main into issue-5911 (adopt replay-lifecycle refactor + …
austinywang Jul 2, 2026
1da9a30
Match origin/main's ungated isolated deinit in MobileShellComposite
austinywang Jul 2, 2026
1164e3e
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
austinywang Jul 3, 2026
1b90e6b
Avoid repeated workspace scans during repaired replay
austinywang Jul 3, 2026
12419d4
Merge remote-tracking branch 'origin/main' into issue-5911-ios-ci-ren…
austinywang Jul 4, 2026
b59b924
Avoid render-grid resync on pending duplicate input acks
austinywang Jul 4, 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
2 changes: 1 addition & 1 deletion .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
7952 Sources/Panels/BrowserPanelView.swift
7366 cmuxTests/WorkspaceUnitTests.swift
7218 cmuxTests/WorkspaceRemoteConnectionTests.swift
6895 Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite.swift
6921 Packages/iOS/CmuxMobileShell/Sources/CmuxMobileShell/MobileShellComposite.swift
6317 cmuxTests/SessionPersistenceTests.swift
6217 cmuxTests/GhosttyConfigTests.swift
6183 Sources/TabManager.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5744,19 +5744,36 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
}
}

private func refreshTerminalEventSubscription(reason: String) {
private func refreshTerminalEventSubscription(
reason: String,
replaySurfaceIDsIfRepaired: [String] = []
) {
guard let client = remoteClient, connectionState == .connected else { return }
guard runtime?.supportsServerPushEvents ?? true else { return }
guard terminalSubscriptionRefreshTask == nil else { return }
Comment thread
austinywang marked this conversation as resolved.
Resolved
terminalSubscriptionRefreshTask = Task { @MainActor [weak self] in
defer { self?.terminalSubscriptionRefreshTask = nil }
guard let self else { return }
let topics = self.terminalOutputTransport.eventTopics
_ = await self.requestTerminalEventSubscription(
let ack = await self.requestTerminalEventSubscription(
client: client,
reason: reason,
topics: topics
)
guard !Task.isCancelled,
self.remoteClient === client,
self.connectionState == .connected else {
return
}
guard case .subscribed(let alreadySubscribed) = ack,
alreadySubscribed == false,
!replaySurfaceIDsIfRepaired.isEmpty else {
return
}
MobileDebugLog.anchormux("sync.subscribe_repaired reason=\(reason) surfaces=\(replaySurfaceIDsIfRepaired.count)")
self.replayAfterRepairedTerminalEventSubscription(
surfaceIDs: replaySurfaceIDsIfRepaired
)
}
}

Expand Down Expand Up @@ -6066,13 +6083,9 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
// host-side condition), so no listener restart is needed.
MobileDebugLog.anchormux("sync.liveness probe_repaired silentMs=\(Int(silent * 1000))")
mobileShellLog.info("liveness probe reinstalled a lost event subscription, replaying mounted surfaces")
for surfaceID in self.terminalByteContinuationsBySurfaceID.keys {
self.requestTerminalReplay(surfaceID: surfaceID)
}
// The same registration carries `workspace.updated`, so
// workspace create/rename/delete events emitted during the
// gap were missed too; re-fetch the authoritative list.
self.scheduleWorkspaceListRefreshFromEvent()
self.replayAfterRepairedTerminalEventSubscription(
surfaceIDs: Array(self.terminalByteContinuationsBySurfaceID.keys)
)
} else {
MobileDebugLog.anchormux("sync.liveness probe_ok silentMs=\(Int(silent * 1000))")
}
Expand Down Expand Up @@ -6186,7 +6199,10 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
)
} else {
MobileDebugLog.anchormux("sync.input_seq_wait surface=\(surfaceID) local=\(localSeq) remote=\(remoteSeq)")
refreshTerminalEventSubscription(reason: "input_seq_wait")
refreshTerminalEventSubscription(
reason: "input_seq_wait",
replaySurfaceIDsIfRepaired: [surfaceID]
)
Comment thread
austinywang marked this conversation as resolved.
Resolved
}
return
}
Expand All @@ -6205,6 +6221,16 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
)
}

private func replayAfterRepairedTerminalEventSubscription(surfaceIDs: [String]) {
for surfaceID in surfaceIDs where hasTerminalOutputSink(surfaceID: surfaceID) {
requestTerminalReplay(surfaceID: surfaceID)
}
// The same registration carries `workspace.updated`, so workspace
// create/rename/delete events emitted during the gap were missed too;
// re-fetch the authoritative list.
scheduleWorkspaceListRefreshFromEvent()
}
Comment thread
austinywang marked this conversation as resolved.
Resolved

private func markTerminalBytesDelivered(surfaceID: String, endSeq: UInt64) {
let current = deliveredTerminalByteEndSeqBySurfaceID[surfaceID] ?? 0
deliveredTerminalByteEndSeqBySurfaceID[surfaceID] = max(current, endSeq)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ actor LivenessHostRouter {
private var hasActiveSubscription = false
private var heldContinuations: [CheckedContinuation<Void, Never>] = []
private var capabilities = ["events.v1", "terminal.render_grid.v1", "terminal.replay.v1"]
private let terminalInputSeq: UInt64 = 12
private var replayFrames: [(seq: UInt64, text: String)] = []

func record(method: String?, topics: [String]?) {
recorded.append(RecordedRequest(method: method, topics: topics))
Expand All @@ -79,6 +81,10 @@ actor LivenessHostRouter {
self.capabilities = capabilities
}

func setReplayFrames(_ frames: [(seq: UInt64, text: String)]) {
replayFrames = frames
}

/// Hold every `mobile.events.subscribe` response until released.
func setHoldSubscribe(_ hold: Bool) {
holdSubscribe = hold
Expand Down Expand Up @@ -161,8 +167,26 @@ actor LivenessHostRouter {
"topics": ["workspace.updated", "terminal.render_grid"],
"already_subscribed": alreadySubscribed,
])
case "mobile.events.unsubscribe", "mobile.terminal.replay", "mobile.terminal.viewport":
case "terminal.input":
return try? Self.resultFrame(id: id, result: [
"workspace_id": "live-workspace",
"surface_id": "live-terminal",
"queued": false,
"terminal_seq": terminalInputSeq,
])
case "mobile.events.unsubscribe", "mobile.terminal.viewport":
return try? Self.resultFrame(id: id, result: [:])
case "mobile.terminal.replay":
let replayIndex = max(0, count(of: "mobile.terminal.replay") - 1)
guard !replayFrames.isEmpty else {
return try? Self.resultFrame(id: id, result: [:])
}
let frame = replayFrames[min(replayIndex, replayFrames.count - 1)]
return try? Self.replayResultFrame(
id: id,
seq: frame.seq,
text: frame.text
)
default:
return try? Self.errorFrame(id: id, message: "Unexpected method \(method ?? "nil")")
}
Expand Down Expand Up @@ -191,6 +215,24 @@ actor LivenessHostRouter {
]
return try MobileSyncFrameCodec.encodeFrame(JSONSerialization.data(withJSONObject: envelope))
}

private static func replayResultFrame(id: String?, seq: UInt64, text: String) throws -> Data {
let frame = try MobileTerminalRenderGridFrame.fromPlainRows(
surfaceID: "live-terminal",
stateSeq: seq,
columns: 16,
rows: 4,
text: text
)
return try resultFrame(id: id, result: [
"workspace_id": "live-workspace",
"surface_id": "live-terminal",
"seq": NSNumber(value: seq),
"columns": 16,
"rows": 4,
"render_grid": try frame.jsonObject(),
])
}
}

/// Holds the live transport instance so the test can push unsolicited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,45 @@ import Testing
collector.unmount()
}

/// If terminal input reports the Mac has advanced past the last rendered
/// frame, render-grid mode first waits for the live event stream instead of
/// immediately replaying. When the re-subscribe ack says the host-side
/// registration had been absent, that wait cannot succeed for the already
/// emitted input frame; the mounted surface needs an explicit catch-up replay.
@MainActor
@Test func inputSeqWaitRepairingLostSubscriptionReplaysMountedSurface() async throws {
let clock = TestClock()
let router = LivenessHostRouter()
let box = TransportBox()
await router.setReplayFrames([
(seq: 4, text: "old"),
(seq: 12, text: "repaired-input"),
])
let store = try await makeConnectedStore(router: router, box: box, clock: clock)

let sawSubscribe = try await pollUntil { await router.count(of: "mobile.events.subscribe") >= 1 }
#expect(sawSubscribe, "listener must establish the push subscription")

let collector = OutputCollector()
collector.mount(store: store, surfaceID: "live-terminal")
let sawMountReplay = try await pollUntil { await router.count(of: "mobile.terminal.replay") >= 1 }
#expect(sawMountReplay, "mounting a sink arms the cold-attach replay")
let deliveredInitialReplay = try await pollUntil { collector.lines.contains { $0.contains("old") } }
#expect(deliveredInitialReplay, "the mount replay establishes the local rendered sequence")

await router.dropSubscription()
await store.submitTerminalRawInput(Data("x".utf8), surfaceID: "live-terminal")

let replayedAfterRepair = try await pollUntil { await router.count(of: "mobile.terminal.replay") >= 2 }
#expect(
replayedAfterRepair,
"input_seq_wait must replay the mounted surface when its re-subscribe repaired a lost host registration"
)
let deliveredRepairReplay = try await pollUntil { collector.lines.contains { $0.contains("repaired-input") } }
#expect(deliveredRepairReplay)
collector.unmount()
}

/// The watchdog's original purpose (the ~85s silent-death hang) must keep
/// working: silence past the threshold plus a host that stops answering the
/// probe must still tear down and re-subscribe.
Expand Down
35 changes: 29 additions & 6 deletions ios/cmuxPackage/Tests/cmuxFeatureTests/cmuxFeatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import UIKit
final class TerminalOutputCollector {
private(set) var lines: [String] = []
private var task: Task<Void, Never>?
private var lineCountWaiters: [(count: Int, continuation: CheckedContinuation<Void, Never>)] = []

/// Begin consuming the surface's output stream into ``lines``.
func mount(store: CMUXMobileShellStore, surfaceID: String) {
Expand All @@ -33,14 +34,41 @@ final class TerminalOutputCollector {
surfaceID: surfaceID,
streamToken: chunk.streamToken
)
self.resumeLineCountWaiters()
}
}
}

/// Wait until at least ``count`` output chunks have been collected.
func waitForLineCount(_ count: Int) async {
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
guard lines.count < count else { return }
await withCheckedContinuation { continuation in
lineCountWaiters.append((count, continuation))
}
}

/// Stop consuming the stream, unregistering the surface from the store.
func unmount() {
task?.cancel()
task = nil
let waiters = lineCountWaiters
lineCountWaiters = []
for waiter in waiters {
waiter.continuation.resume()
}
}

private func resumeLineCountWaiters() {
guard !lineCountWaiters.isEmpty else { return }
var remaining: [(count: Int, continuation: CheckedContinuation<Void, Never>)] = []
for waiter in lineCountWaiters {
if lines.count >= waiter.count {
waiter.continuation.resume()
} else {
remaining.append(waiter)
}
}
lineCountWaiters = remaining
}
}

Expand Down Expand Up @@ -2458,12 +2486,7 @@ final class TerminalOutputCollector {

await store.submitTerminalRawInput(Data("y".utf8), surfaceID: "live-terminal")
_ = try await waitForRequestCount("mobile.terminal.replay", count: 2, router: router)
// The request-count wait only proves the second replay REQUEST was sent;
// its response still flows back through the transport asynchronously.
// Poll for delivery like the sibling tests do, then assert content.
for _ in 0..<200 where collector.lines.count < 2 {
try await Task.sleep(nanoseconds: 1_000_000)
}
await collector.waitForLineCount(2)

let oldGridText = try terminalRenderGridReplacementText(seq: 4, text: "old")
let currentGridText = try terminalRenderGridReplacementText(seq: 12, text: "current")
Expand Down
Loading