Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1d094c8
test: cover remote SSH resume bindings
Jul 19, 2026
cd31bb2
feat: add remote-aware SSH resume bindings
Jul 19, 2026
50e2370
fix: authenticate remote resume relay provenance
Jul 19, 2026
aa7e0cc
fix: compile relay provenance authentication
Jul 19, 2026
35ab5de
fix: address remote resume review findings
Jul 19, 2026
dd629a6
refactor: satisfy remote resume file policy
Jul 19, 2026
7a19f20
test: cover legacy remote resume migration
Jul 19, 2026
0f6324d
fix: migrate legacy remote resume bindings
Jul 19, 2026
536f17a
test: cover workspace-id-free legacy resume
Jul 19, 2026
81f5f5f
fix: recover legacy remote workspace identity
Jul 19, 2026
1bb3105
test: remove unused remote resume helper inputs
Jul 19, 2026
9e6e880
test: cover resume with unsupported remote shell
Jul 19, 2026
c2ecafc
test: import remote configuration module
Jul 19, 2026
f9ad1a6
test: disambiguate resume command decoding
Jul 19, 2026
a5e338a
fix: resume before unsupported remote shells
Jul 19, 2026
ca90da2
test: cover escaped remote resume method
Jul 19, 2026
8b95fa2
fix: preserve unsupported remote login shells
Jul 19, 2026
38585b7
fix: classify relayed resume methods structurally
Jul 19, 2026
004d8de
test: remove unnecessary remote resume throws
Jul 19, 2026
83b67ee
Merge remote-tracking branch 'origin/main' into issue-7989-remote-res…
Jul 19, 2026
91fa5f7
Merge remote-tracking branch 'origin/main' into issue-7989-remote-res…
Jul 20, 2026
6bddf9d
Merge remote-tracking branch 'origin/main' into issue-7989-remote-res…
Jul 20, 2026
5af83f7
fix: integrate remote resume bootstrap API
Jul 20, 2026
1b9603c
test: fix merged remote transport coverage
Jul 20, 2026
4c6f88c
test: fix remote prompt diagnostics
Jul 20, 2026
3888079
fix: run resume before unsupported remote shells
Jul 20, 2026
4e6fc46
Merge origin/main into issue-7989-remote-resume-bindings
Jul 20, 2026
6bd4b32
Expand remote resume verification coverage
Jul 21, 2026
fefcb08
Fix remote resume verifier assertions
Jul 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ extension ControlCommandCoordinator {
}

let source = publicResumeSource(params)
let remoteWorkspaceID = uuid(params, "_cmux_remote_workspace_id")
if hasNonNull(params, "_cmux_remote_workspace_id"), remoteWorkspaceID == nil {
return .err(
code: "invalid_params",
message: String(
localized: "socket.surfaceSplitOff.error.invalidWorkspaceId",
defaultValue: "Missing or invalid workspace_id"
),
data: nil
)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
let inputs = ControlSurfaceResumeSetInputs(
name: optionalTrimmedRawString(params, "name"),
kind: optionalTrimmedRawString(params, "kind"),
Expand All @@ -55,7 +66,8 @@ extension ControlCommandCoordinator {
?? optionalTrimmedRawString(params, "checkpointId"),
source: source,
environment: stringMap(params, "environment"),
autoResume: source == "agent-hook" ? (bool(params, "auto_resume") ?? false) : false
autoResume: source == "agent-hook" ? (bool(params, "auto_resume") ?? false) : false,
remoteWorkspaceID: remoteWorkspaceID
)
return surfaceResumeResult(
context?.controlSurfaceResumeSet(
Expand Down Expand Up @@ -160,6 +172,10 @@ extension ControlCommandCoordinator {
"auto_resume": .bool(binding.autoResume),
"approval_policy": orNull(binding.approvalPolicyRawValue),
"approval_record_id": orNull(binding.approvalRecordID),
"execution_location": .string(binding.executionLocationRawValue),
"remote_workspace_id": orNull(binding.remoteWorkspaceID?.uuidString),
"remote_surface_id": orNull(binding.remoteSurfaceID?.uuidString),
"remote_pty_session_id": orNull(binding.remotePTYSessionID),
"updated_at": .double(binding.updatedAt),
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public struct ControlSurfaceResumeBinding: Sendable, Equatable {
public let approvalPolicyRawValue: String?
/// The approval record identifier, if any.
public let approvalRecordID: String?
/// Where the saved command is allowed to execute (`local` or `remote_ssh`).
public let executionLocationRawValue: String
/// The owning remote workspace for a remote binding.
public let remoteWorkspaceID: UUID?
/// The owning remote surface for a remote binding.
public let remoteSurfaceID: UUID?
/// The persistent remote PTY session for a remote binding.
public let remotePTYSessionID: String?
/// The last-updated timestamp (seconds since the epoch).
public let updatedAt: Double

Expand All @@ -47,6 +55,10 @@ public struct ControlSurfaceResumeBinding: Sendable, Equatable {
/// - autoResume: Whether automatic resume is allowed.
/// - approvalPolicyRawValue: The approval policy's raw value.
/// - approvalRecordID: The approval record identifier.
/// - executionLocationRawValue: Where the command is allowed to execute.
/// - remoteWorkspaceID: The owning remote workspace.
/// - remoteSurfaceID: The owning remote surface.
/// - remotePTYSessionID: The persistent remote PTY session.
/// - updatedAt: The last-updated timestamp.
public init(
name: String?,
Expand All @@ -59,6 +71,10 @@ public struct ControlSurfaceResumeBinding: Sendable, Equatable {
autoResume: Bool,
approvalPolicyRawValue: String?,
approvalRecordID: String?,
executionLocationRawValue: String,
remoteWorkspaceID: UUID?,
remoteSurfaceID: UUID?,
remotePTYSessionID: String?,
updatedAt: Double
) {
self.name = name
Expand All @@ -71,6 +87,10 @@ public struct ControlSurfaceResumeBinding: Sendable, Equatable {
self.autoResume = autoResume
self.approvalPolicyRawValue = approvalPolicyRawValue
self.approvalRecordID = approvalRecordID
self.executionLocationRawValue = executionLocationRawValue
self.remoteWorkspaceID = remoteWorkspaceID
self.remoteSurfaceID = remoteSurfaceID
self.remotePTYSessionID = remotePTYSessionID
self.updatedAt = updatedAt
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
internal import Foundation
public import Foundation

/// The pre-parsed inputs for `surface.resume.set`, lifted from the legacy
/// `v2SurfaceResumeSet` body's param parsing.
Expand All @@ -25,6 +25,9 @@ public struct ControlSurfaceResumeSetInputs: Sendable, Equatable {
/// Whether automatic resume is requested (already gated: `true` only for the
/// `agent-hook` source with `auto_resume == true`).
public let autoResume: Bool
/// The authenticated relay's owning remote workspace, when the request
/// entered through an SSH workspace relay.
public let remoteWorkspaceID: UUID?

/// Creates resume-set inputs.
///
Expand All @@ -37,6 +40,7 @@ public struct ControlSurfaceResumeSetInputs: Sendable, Equatable {
/// - source: The (already-mapped) binding source.
/// - environment: The environment overrides.
/// - autoResume: Whether automatic resume is requested.
/// - remoteWorkspaceID: The authenticated relay's owning workspace.
public init(
name: String?,
kind: String?,
Expand All @@ -45,7 +49,8 @@ public struct ControlSurfaceResumeSetInputs: Sendable, Equatable {
checkpointID: String?,
source: String?,
environment: [String: String]?,
autoResume: Bool
autoResume: Bool,
remoteWorkspaceID: UUID?
) {
self.name = name
self.kind = kind
Expand All @@ -55,5 +60,6 @@ public struct ControlSurfaceResumeSetInputs: Sendable, Equatable {
self.source = source
self.environment = environment
self.autoResume = autoResume
self.remoteWorkspaceID = remoteWorkspaceID
}
}
51 changes: 46 additions & 5 deletions Sources/RemoteInteractiveShellBootstrapBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ enum RemoteInteractiveShellBootstrapBuilder {
terminfoSource: String? = nil,
bundledZshIntegration: String? = nil,
bundledBashIntegration: String? = nil,
bundledFishIntegration: String? = nil
bundledFishIntegration: String? = nil,
initialCommand: String? = nil
) -> String {
let shellStateDir = shellStateDirForRemoteRelayPort(remoteRelayPort)
let commonShellExportLines = commonShellLines(
Expand Down Expand Up @@ -85,7 +86,7 @@ enum RemoteInteractiveShellBootstrapBuilder {
outerLines += [
" export CMUX_REAL_ZDOTDIR=\"${ZDOTDIR:-$HOME}\"",
" export ZDOTDIR=\"$cmux_shell_dir\"",
" exec \"$CMUX_LOGIN_SHELL\" -il",
loginShellLaunchLine(kind: .zsh, initialCommand: initialCommand),
" ;;",
" bash)",
" cat > \"$cmux_shell_dir/.bashrc\" <<'CMUXBASHRC'",
Expand All @@ -106,28 +107,68 @@ enum RemoteInteractiveShellBootstrapBuilder {
]
outerLines.append(contentsOf: relayWarmupLines.map { " " + $0 })
outerLines += [
" exec \"$CMUX_LOGIN_SHELL\" --rcfile \"$cmux_shell_dir/.bashrc\" -i",
loginShellLaunchLine(kind: .bash, initialCommand: initialCommand),
" ;;",
" fish)",
]
outerLines.append(contentsOf: relayWarmupLines.map { " " + $0 })
outerLines += [
" export CMUX_FISH_INTEGRATION_FILE=\"$cmux_shell_dir/fish/config.fish\"",
" export CMUX_FISH_USER_CONFIG_ALREADY_LOADED=1",
" exec \"$CMUX_LOGIN_SHELL\" -il --init-command 'source \"$CMUX_FISH_INTEGRATION_FILE\"'",
loginShellLaunchLine(kind: .fish, initialCommand: initialCommand),
" ;;",
" *)",
]
outerLines.append(contentsOf: relayWarmupLines)
outerLines += [
"exec \"$CMUX_LOGIN_SHELL\" -i",
loginShellLaunchLine(kind: .other, initialCommand: initialCommand),
";;",
"esac",
]

return outerLines.joined(separator: "\n")
}

private enum LoginShellKind {
case zsh
case bash
case fish
case other
}

private static func loginShellLaunchLine(
kind: LoginShellKind,
initialCommand: String?
) -> String {
let normalizedCommand = initialCommand?.trimmingCharacters(in: .whitespacesAndNewlines)
let resumeInvocation = normalizedCommand.flatMap { command in
command.isEmpty ? nil : "/bin/sh -c \(shellQuote(command))"
}
switch (kind, resumeInvocation) {
case (.zsh, .none):
return " exec \"$CMUX_LOGIN_SHELL\" -il"
case (.zsh, .some(let resumeInvocation)):
let command = resumeInvocation + "\nexec \"$CMUX_LOGIN_SHELL\" -il"
return " exec \"$CMUX_LOGIN_SHELL\" -ilc \(shellQuote(command))"
case (.bash, .none):
return " exec \"$CMUX_LOGIN_SHELL\" --rcfile \"$cmux_shell_dir/.bashrc\" -i"
case (.bash, .some(let resumeInvocation)):
let command = resumeInvocation +
"\nexec \"$CMUX_LOGIN_SHELL\" --rcfile \"$CMUX_SHELL_INTEGRATION_DIR/.bashrc\" -i"
return " exec \"$CMUX_LOGIN_SHELL\" --rcfile \"$cmux_shell_dir/.bashrc\" -ic \(shellQuote(command))"
case (.fish, .none):
return " exec \"$CMUX_LOGIN_SHELL\" -il --init-command 'source \"$CMUX_FISH_INTEGRATION_FILE\"'"
case (.fish, .some(let resumeInvocation)):
let command = "source \"$CMUX_FISH_INTEGRATION_FILE\"; \(resumeInvocation)"
return " exec \"$CMUX_LOGIN_SHELL\" -il --init-command \(shellQuote(command))"
case (.other, .none):
return "exec \"$CMUX_LOGIN_SHELL\" -i"
case (.other, .some(let resumeInvocation)):
let command = resumeInvocation + "\nexec \"$CMUX_LOGIN_SHELL\" -i"
return "exec \"$CMUX_LOGIN_SHELL\" -ic \(shellQuote(command))"
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

static func shellFeatures(
environment: [String: String] = ProcessInfo.processInfo.environment
) -> String {
Expand Down
8 changes: 6 additions & 2 deletions Sources/SSHPTYAttachStartupCommandBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ enum SSHPTYAttachStartupCommandBuilder {
return "/bin/sh -c \(shellQuote(lines.joined(separator: "\n")))"
}

static func restoredRemoteShellCommand(relayPort: Int) -> String {
static func restoredRemoteShellCommand(
relayPort: Int,
initialCommand: String? = nil
) -> String {
RemoteInteractiveShellBootstrapBuilder.script(
remoteRelayPort: relayPort,
shellFeatures: RemoteInteractiveShellBootstrapBuilder.shellFeatures(),
bundledZshIntegration: RemoteInteractiveShellBootstrapBuilder.bundledShellIntegrationScript(named: "cmux-zsh-integration.zsh"),
bundledBashIntegration: RemoteInteractiveShellBootstrapBuilder.bundledShellIntegrationScript(named: "cmux-bash-integration.bash"),
bundledFishIntegration: RemoteInteractiveShellBootstrapBuilder.bundledShellIntegrationScript(named: "fish/config.fish")
bundledFishIntegration: RemoteInteractiveShellBootstrapBuilder.bundledShellIntegrationScript(named: "fish/config.fish"),
initialCommand: initialCommand
)
}

Expand Down
20 changes: 8 additions & 12 deletions Sources/SessionPersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,9 @@ enum SurfaceResumeApprovalPolicy: String, Codable, CaseIterable, Sendable {

struct SurfaceResumeBindingSnapshot: Codable, Equatable, Sendable {
private enum CodingKeys: String, CodingKey {
case name
case kind
case command
case cwd
case checkpointId
case source
case environment
case autoResume
case approvalPolicy
case approvalRecordId
case updatedAt
case name, kind, command, cwd, checkpointId, source
case environment, autoResume, approvalPolicy, approvalRecordId
case launchFlavor, updatedAt
}

var name: String?
Expand All @@ -282,6 +274,7 @@ struct SurfaceResumeBindingSnapshot: Codable, Equatable, Sendable {
var autoResume: Bool?
var approvalPolicy: SurfaceResumeApprovalPolicy?
var approvalRecordId: String?
var launchFlavor: SurfaceResumeLaunchFlavor
var updatedAt: TimeInterval

init(
Expand All @@ -295,6 +288,7 @@ struct SurfaceResumeBindingSnapshot: Codable, Equatable, Sendable {
autoResume: Bool? = nil,
approvalPolicy: SurfaceResumeApprovalPolicy? = nil,
approvalRecordId: String? = nil,
launchFlavor: SurfaceResumeLaunchFlavor = .local,
updatedAt: TimeInterval = Date().timeIntervalSince1970
) {
let normalizedCwd = Self.normalized(cwd)
Expand All @@ -314,6 +308,7 @@ struct SurfaceResumeBindingSnapshot: Codable, Equatable, Sendable {
self.autoResume = autoResume
self.approvalPolicy = approvalPolicy
self.approvalRecordId = Self.normalized(approvalRecordId)
self.launchFlavor = launchFlavor
self.updatedAt = updatedAt
}

Expand All @@ -330,6 +325,7 @@ struct SurfaceResumeBindingSnapshot: Codable, Equatable, Sendable {
autoResume: try container.decodeIfPresent(Bool.self, forKey: .autoResume),
approvalPolicy: try container.decodeIfPresent(SurfaceResumeApprovalPolicy.self, forKey: .approvalPolicy),
approvalRecordId: try container.decodeIfPresent(String.self, forKey: .approvalRecordId),
launchFlavor: try container.decodeIfPresent(SurfaceResumeLaunchFlavor.self, forKey: .launchFlavor) ?? .local,
updatedAt: try container.decodeIfPresent(TimeInterval.self, forKey: .updatedAt)
?? Date().timeIntervalSince1970
)
Expand Down Expand Up @@ -374,10 +370,10 @@ struct SurfaceResumeBindingSnapshot: Codable, Equatable, Sendable {
autoResume: autoResume,
approvalPolicy: approvalPolicy,
approvalRecordId: approvalRecordId,
launchFlavor: launchFlavor,
updatedAt: updatedAt
)
}

static let maxInlineStartupInputBytes = SessionRestorableAgentSnapshot.maxInlineStartupInputBytes

var startupInput: String? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SessionRemoteWorkspaceSnapshot+Restore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension SessionRemoteWorkspaceSnapshot {
? Self.restoreRelayTokenHex()
: nil
let restoredRemoteShellCommand = preservePTYSession
? normalizedRelayPort.map(SSHPTYAttachStartupCommandBuilder.restoredRemoteShellCommand(relayPort:))
? normalizedRelayPort.map { SSHPTYAttachStartupCommandBuilder.restoredRemoteShellCommand(relayPort: $0) }
: nil
return WorkspaceRemoteConfiguration(
transport: transport,
Expand Down
49 changes: 49 additions & 0 deletions Sources/SurfaceResumeBindingSnapshot+Remote.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Foundation

extension SurfaceResumeBindingSnapshot {
func registeredForPersistentSSH(_ context: SurfaceResumeRemoteContext) -> SurfaceResumeBindingSnapshot {
replacingLaunchFlavor(.persistentSSH(context))
}

func retargetingRemoteOwner(
expectedWorkspaceID: UUID,
expectedSurfaceID: UUID,
workspaceID: UUID,
surfaceID: UUID,
persistentPTYSessionID: String?
) -> SurfaceResumeBindingSnapshot {
guard case .persistentSSH(let context) = launchFlavor,
let persistentPTYSessionID,
context.matches(
workspaceID: expectedWorkspaceID,
surfaceID: expectedSurfaceID,
persistentPTYSessionID: persistentPTYSessionID
) else {
return self
}
return replacingLaunchFlavor(.persistentSSH(context.retargeted(
workspaceID: workspaceID,
surfaceID: surfaceID,
persistentPTYSessionID: persistentPTYSessionID
)))
}

private func replacingLaunchFlavor(
_ launchFlavor: SurfaceResumeLaunchFlavor
) -> SurfaceResumeBindingSnapshot {
SurfaceResumeBindingSnapshot(
name: name,
kind: kind,
command: command,
cwd: cwd,
checkpointId: checkpointId,
source: source,
environment: environment,
autoResume: autoResume,
approvalPolicy: approvalPolicy,
approvalRecordId: approvalRecordId,
launchFlavor: launchFlavor,
updatedAt: updatedAt
)
}
}
Loading