Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
841e029
test: cover stale surface restore routing
austinywang Aug 1, 2026
a224fb4
Prefer live terminal routing for restore
austinywang Aug 1, 2026
97a6408
test: reject ambiguous restore TTY routing
austinywang Aug 1, 2026
fec1cb0
Reject ambiguous TTY restore routing
austinywang Aug 1, 2026
a738eb3
test: cover live restore target resolution
austinywang Aug 1, 2026
0f1a9f3
Resolve restore target from live process
austinywang Aug 1, 2026
789a189
test: cover authoritative restore routing failure
austinywang Aug 1, 2026
381670c
Fail closed on missing live restore target
austinywang Aug 1, 2026
29eb9e6
test: cover restored TTY registration race
austinywang Aug 1, 2026
be1b8bd
Wait for fresh restore TTY registration
austinywang Aug 1, 2026
feaecd9
Merge remote-tracking branch 'origin/main' into issue-9380-pi-restore…
austinywang Aug 1, 2026
49af68c
test: scope relay restore TTY routing
austinywang Aug 1, 2026
98dd645
test: constrain relay TTY resolution
austinywang Aug 1, 2026
56549f0
test: preserve relay restore workspace aliases
austinywang Aug 1, 2026
c274960
Scope relay restore to authenticated terminal
austinywang Aug 1, 2026
30d5bce
test: cover live and Dock TTY routing
austinywang Aug 1, 2026
d3b6294
fix: complete live TTY restore routing
austinywang Aug 1, 2026
5db7390
test: cover ended and cached TTY routing
austinywang Aug 1, 2026
c32a53f
fix: retire stale TTY lifecycle evidence
austinywang Aug 1, 2026
32e5136
Merge remote-tracking branch 'origin/main' into issue-9380-pi-restore…
austinywang Aug 1, 2026
d2759b3
test: cover fail-closed restore and reconnect routing
austinywang Aug 1, 2026
0a9d221
fix: make restore routing readiness authoritative
austinywang Aug 1, 2026
2c625bd
test: cover transferred and persistent TTY routing
austinywang Aug 1, 2026
413d5a4
fix: preserve live TTY proof across bridge retries
austinywang Aug 1, 2026
942469d
test: cover relay restore after new workspace move
austinywang Aug 1, 2026
ca95cc4
fix: preserve relay routing across workspace moves
austinywang Aug 1, 2026
6654fa1
test: cover relay ownership after surface moves
austinywang Aug 1, 2026
d129200
fix: keep relay provenance scoped through moves
austinywang Aug 1, 2026
13f3b1e
test: cover stale relay TTY lifecycle
austinywang Aug 1, 2026
b1d61ad
fix: retire relay TTY provenance on terminal end
austinywang Aug 1, 2026
f85da04
test: cover durable relay identity after moves
austinywang Aug 1, 2026
0149481
fix: keep relay identity durable across moves
austinywang Aug 1, 2026
d78041b
test: cover authoritative TTY trust boundaries
austinywang Aug 1, 2026
c482c7a
fix: bind TTY reports to terminal runtime
austinywang Aug 1, 2026
1dd6ab0
test: cover Grok restore routing
austinywang Aug 1, 2026
48157de
test: cover relay TTY readiness gaps
austinywang Aug 1, 2026
e693ac2
fix: wait for relay TTY readiness
austinywang Aug 1, 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
11 changes: 9 additions & 2 deletions CLI/CMUXCLI+ClaudeHookWorkspaceRouting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ extension CMUXCLI {
client: SocketClient,
includeAmbientTTY: Bool = true
) -> CallerTerminalBinding? {
guard let ttyName = resolveCallerTTYName(includeAmbientTTY: includeAmbientTTY),
let payload = try? client.sendV2(method: "debug.terminals") else {
guard let ttyName = resolveCallerTTYName(includeAmbientTTY: includeAmbientTTY) else {
return nil
}
return uniqueCallerTerminalBindingByTTY(ttyName: ttyName, client: client)
}

func uniqueCallerTerminalBindingByTTY(
ttyName: String,
client: SocketClient
) -> CallerTerminalBinding? {
guard let payload = try? client.sendV2(method: "debug.terminals") else { return nil }
let terminals = payload["terminals"] as? [[String: Any]] ?? []
var matched: [CallerTerminalBinding] = []
for terminal in terminals {
Expand Down
86 changes: 72 additions & 14 deletions CLI/CMUXCLI+Restore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,12 @@ extension CMUXCLI {
}
params["surface_id"] = surfaceID
} else if selector.usesCurrentSurface,
let surfaceID = processEnvironment["CMUX_SURFACE_ID"],
!surfaceID.isEmpty {
params["surface_id"] = surfaceID
} else if selector.usesCurrentSurface,
let ttyName = resolveCallerTTYName(),
let caller = resolveTerminalBinding(
ttyName: ttyName,
let surfaceID = try currentRestoreSurfaceID(
client: client
) {
params["surface_id"] = caller.surfaceId
params["surface_id"] = surfaceID
} else {
throw CLIError(
message: String(
localized: "cli.restore.error.currentSurfaceUnknown",
defaultValue: "restore: the current cmux surface could not be identified. Retry from this terminal or pass --surface <id|ref>."
)
)
throw currentRestoreSurfaceUnknownError()
}

let payload = try client.sendV2(method: "surface.resume.get", params: params)
Expand Down Expand Up @@ -190,6 +179,75 @@ extension CMUXCLI {
)
}

private func currentRestoreSurfaceID(
client: SocketClient
) throws -> String? {
// The remote relay and the local CLI do not share a PID namespace.
guard !client.isRelayBacked else {
return legacyRestoreSurfaceID(client: client)
}

let resolution = AgentProcessBindingResolution.controllingTTY.rawValue
do {
let payload = try client.sendV2(
method: "agent.resolve_delivery_target",
params: [
"pid": Int(ProcessInfo.processInfo.processIdentifier),
"pid_resolution": resolution,
]
)
guard payload["source"] as? String == "pid",
payload["pid_resolution"] as? String == resolution,
let workspaceID = normalizedHandleValue(payload["workspace_id"] as? String),
isUUID(workspaceID),
let surfaceID = normalizedHandleValue(payload["surface_id"] as? String),
isUUID(surfaceID) else {
throw currentRestoreSurfaceUnknownError()
}
return surfaceID
} catch let error as CLIError {
switch error.v2Code {
case "not_found":
client.close()
throw currentRestoreSurfaceUnknownError()
case "method_not_found", "unrecognized_method":
// These protocol replies were consumed in full, so the socket
// remains synchronized for the legacy discovery request.
return legacyRestoreSurfaceID(client: client)
default:
client.close()
throw error
}
} catch {
client.close()
throw error
}
}

private func legacyRestoreSurfaceID(client: SocketClient) -> String? {
// Prefer the live descriptors. Generic TTY variables can be inherited
// across nested shells, so only dedicated cmux hints are a fallback.
let ttyName = resolveCallerDescriptorTTYName()
?? resolveCallerTTYName(includeAmbientTTY: false)
guard let ttyName,
let binding = uniqueCallerTerminalBindingByTTY(
ttyName: ttyName,
client: client
) else {
return nil
}
return binding.surfaceId
}

private func currentRestoreSurfaceUnknownError() -> CLIError {
CLIError(
message: String(
localized: "cli.restore.error.currentSurfaceUnknown",
defaultValue: "restore: the current cmux surface could not be identified. Retry from this terminal or pass --surface <id|ref>."
)
)
}

private func restoreSelector(_ arguments: [String]) throws -> RestoreSelector {
if arguments.first == "--surface" {
if arguments.count == 1 {
Expand Down
Loading