Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9fedf00
test: reproduce Cloud Codex title rename drift
austinywang Sep 13, 2026
d2f6b9c
test: keep Cloud title regression within file budget and compare fields
austinywang Sep 13, 2026
ea21681
Merge remote-tracking branch 'origin/main' into issue-12499-cloud-ren…
austinywang Sep 13, 2026
9cfcb0c
test: reproduce daemon automatic rename precedence and stale result f…
austinywang Sep 13, 2026
977bf92
fix: restore dropped Cloud terminal I/O entrypoints
austinywang Sep 13, 2026
1e1d319
fix: persist Cloud rename authority and reconcile names from accepted…
austinywang Sep 13, 2026
6d701a7
test: assert shared Cloud names wait for daemon acknowledgement
austinywang Sep 13, 2026
91f4431
fix: restore Cloud binding and Bonsplit API compatibility
austinywang Sep 13, 2026
797c695
fix: preserve callback ordering and same-text user name ownership
austinywang Sep 13, 2026
094c28c
fix: unify legacy Cloud name submission and validate automatic callbacks
austinywang Sep 13, 2026
2b96179
fix: complete additive name authority migrations independently
austinywang Sep 13, 2026
499a486
fix: keep Cloud rename failure presentation scoped to its window
austinywang Sep 13, 2026
86492ff
test: align terminal link fixture with the current Cloud routing prot…
austinywang Sep 13, 2026
c575424
fix: reject blank Cloud workspace names before changing bindings
austinywang Sep 13, 2026
1b486e6
test: use Bonsplit tab identities in the terminal link fixture
austinywang Sep 13, 2026
f2368a8
test: import Bonsplit in the terminal link fixture
austinywang Sep 13, 2026
ab4f32d
fix: validate rename metadata and localize Cloud failure feedback
austinywang Sep 13, 2026
1e8568e
test: apply hosted rustfmt output to rename validation coverage
austinywang Sep 13, 2026
7e39f72
test: reproduce Cloud name metadata breaking strict SDK decoders
austinywang Sep 13, 2026
79a2fe1
fix: carry Cloud name authority through the compatible snapshot exten…
austinywang Sep 13, 2026
a87a98a
test: simplify Cloud fixtures and align hosted formatter output
austinywang Sep 13, 2026
00848b7
fix: centralize public tab snapshots across Cloud response and journa…
austinywang Sep 13, 2026
dedb920
Merge origin/main and deduplicate Cloud compatibility repairs
austinywang Sep 13, 2026
145b903
fix: keep Cloud workspace summaries anchored to accepted resources
austinywang Sep 13, 2026
91d537b
test: align Cloud provider fixtures with authoritative identities
austinywang Sep 13, 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
16 changes: 13 additions & 3 deletions CLI/CMUXCLI+AutoNamingGenericHooks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension CMUXCLI {
}
guard let probe = try? client.sendV2(
method: "workspace.set_auto_title",
params: ["probe": true, "workspace_id": workspaceId]
params: ["probe": true, "workspace_id": workspaceId, "panel_id": surfaceId]
), probe["enabled"] as? Bool == true else {
telemetry.breadcrumb("\(def.name)-hook.auto-name.disabled")
return
Expand Down Expand Up @@ -122,6 +122,7 @@ extension CMUXCLI {
messages: sourceResult.messages,
lineCount: sourceResult.lineCount,
sessionStore: sessionStore,
cloudNameContext: probe["cloud_name_context"],
client: client,
missingOverride: resolution.missingOverride,
telemetryKey: "\(def.name)-hook.auto-name",
Expand Down Expand Up @@ -150,6 +151,7 @@ extension CMUXCLI {
lines: [String],
lineCount: Int,
sessionStore: ClaudeHookSessionStore,
cloudNameContext: Any? = nil,
client: SocketClient,
missingOverride: String?,
telemetryKey: String,
Expand All @@ -163,6 +165,7 @@ extension CMUXCLI {
surfaceId: surfaceId,
lineCount: lineCount,
sessionStore: sessionStore,
cloudNameContext: cloudNameContext,
client: client,
missingOverride: missingOverride,
telemetryKey: telemetryKey,
Expand All @@ -178,6 +181,7 @@ extension CMUXCLI {
messages: [AutoNamingTranscriptMessage],
lineCount: Int,
sessionStore: ClaudeHookSessionStore,
cloudNameContext: Any? = nil,
client: SocketClient,
missingOverride: String?,
telemetryKey: String,
Expand All @@ -191,6 +195,7 @@ extension CMUXCLI {
surfaceId: surfaceId,
lineCount: lineCount,
sessionStore: sessionStore,
cloudNameContext: cloudNameContext,
client: client,
missingOverride: missingOverride,
telemetryKey: telemetryKey,
Expand All @@ -205,6 +210,7 @@ extension CMUXCLI {
surfaceId: String,
lineCount: Int,
sessionStore: ClaudeHookSessionStore,
cloudNameContext: Any? = nil,
client: SocketClient,
missingOverride: String?,
telemetryKey: String,
Expand Down Expand Up @@ -244,6 +250,7 @@ extension CMUXCLI {
workspaceId: workspaceId,
surfaceId: surfaceId,
previousTitle: outcome.lastTitle,
cloudNameContext: cloudNameContext,
client: client,
telemetryKey: telemetryKey,
telemetry: telemetry
Expand All @@ -260,6 +267,7 @@ extension CMUXCLI {
workspaceId: String,
surfaceId: String,
previousTitle: String?,
cloudNameContext: Any? = nil,
client: SocketClient,
telemetryKey: String,
telemetry: CLISocketSentryTelemetry
Expand All @@ -268,12 +276,14 @@ extension CMUXCLI {
"workspace_id": workspaceId,
"panel_id": surfaceId,
"panel_only_if_multiple": true,
"title": title
"title": title,
"cloud_name_context": cloudNameContext ?? NSNull()
]) else {
telemetry.breadcrumb("\(telemetryKey).socket-failed")
return nil
}
if payload["workspace_applied"] as? Bool == true {
if payload["workspace_applied"] as? Bool == true
|| (cloudNameContext is [String: Any] && payload["panel_applied"] as? Bool == true) {
telemetry.breadcrumb("\(telemetryKey).applied")
return title
}
Expand Down
6 changes: 4 additions & 2 deletions CLI/CMUXCLI+AutoNamingHooks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension CMUXCLI {
let env = ProcessInfo.processInfo.environment
guard let probe = try? client.sendV2(
method: "workspace.set_auto_title",
params: ["probe": true, "workspace_id": workspaceId]
params: ["probe": true, "workspace_id": workspaceId, "panel_id": surfaceId]
), probe["enabled"] as? Bool == true else {
telemetry.breadcrumb("claude-hook.auto-name.disabled")
return
Expand Down Expand Up @@ -96,6 +96,7 @@ extension CMUXCLI {
workspaceId: workspaceId,
surfaceId: surfaceId,
previousTitle: outcome.lastTitle,
cloudNameContext: probe["cloud_name_context"],
client: client,
telemetryKey: "claude-hook.auto-name",
telemetry: telemetry
Expand Down Expand Up @@ -178,7 +179,7 @@ extension CMUXCLI {
}
guard let probe = try? client.sendV2(
method: "workspace.set_auto_title",
params: ["probe": true, "workspace_id": workspaceId]
params: ["probe": true, "workspace_id": workspaceId, "panel_id": surfaceId]
), probe["enabled"] as? Bool == true else {
telemetry.breadcrumb("codex-hook.auto-name.disabled")
return
Expand Down Expand Up @@ -210,6 +211,7 @@ extension CMUXCLI {
lines: lines,
lineCount: textFileGrowthMetric(path: transcriptPath, fallbackLineCount: lines.count),
sessionStore: sessionStore,
cloudNameContext: probe["cloud_name_context"],
client: client,
missingOverride: resolution.missingOverride,
telemetryKey: "codex-hook.auto-name",
Expand Down
7 changes: 6 additions & 1 deletion CLI/CMUXCLI+CodexFireAndForgetHooks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ extension CMUXCLI {
telemetry.breadcrumb("codex-hook.native-title-sync.invalid-target")
return
}
// Capture the Cloud name revision before reading Codex's database.
let probe = try? client.sendV2(method: "surface.sync_codex_native_title", params: [
"probe": true, "workspace_id": workspaceId, "panel_id": surfaceId
])
let titleStore = CodexNativeTitleStore(
codexHome: normalizedHookValue(environment["CODEX_HOME"])
)
Expand All @@ -109,7 +113,8 @@ extension CMUXCLI {
_ = try client.sendV2(method: "surface.sync_codex_native_title", params: [
"workspace_id": workspaceId,
"panel_id": surfaceId,
"title": title
"title": title,
"cloud_name_context": probe?["cloud_name_context"] ?? NSNull()
])
telemetry.breadcrumb("codex-hook.native-title-sync.sent")
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Cloud/CloudTreeNodeActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ struct CloudTreeNodeActions {
title: String(format: String(localized: "cloudTree.renameTerminal.title", defaultValue: "Rename \u{201C}%@\u{201D}"), current),
current: current,
allowsClear: true
), name != current else { return }
) else { return }
let operationLabel = name.isEmpty
? String(format: String(localized: "cloudTree.operation.clearTerminal", defaultValue: "Clearing %@\u{2026}"), current)
: String(format: String(localized: "cloudTree.operation.renameTerminal", defaultValue: "Renaming %@\u{2026}"), current)
Expand Down
13 changes: 13 additions & 0 deletions Sources/Cloud/CloudTuiCommandLine+AgentNaming.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

extension CloudTuiCommandLine {
/// The daemon rejects a stale callback or a callback that would replace a user name.
static func agentRenameArguments(
socketPath: String, context: CloudAgentNameContext, name: String
) -> [String] {
renameTabArguments(socketPath: socketPath, tabID: context.projection.remoteTabID ?? "", name: name)
+ ["--workspace", context.projection.remoteWorkspaceID ?? "",
"--source", "auto", "--expected-generation", context.generation,
"--expected-name-revision", String(context.nameRevision)]
}
}
36 changes: 36 additions & 0 deletions Sources/Surfaces/CloudAgentNameContext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Foundation

/// A callback's read precondition, captured before an agent computes its title.
/// Names never identify a resource: the full projection and daemon generation do.
struct CloudAgentNameContext: Hashable, Codable, Sendable {
let projection: SurfaceProjection
let generation: String
let nameRevision: UInt64

init?(projection: SurfaceProjection, state: CloudVMState) {
guard let tabID = projection.remoteTabID,
let tab = state.lookupIndex.tab(id: tabID),
tab.contentKind == "terminal", tab.contentID == projection.resource.key,
let pane = state.lookupIndex.pane(id: tab.paneID),
let screen = state.lookupIndex.screen(id: pane.screenID),
screen.workspaceID == projection.remoteWorkspaceID,
let authority = tab.nameAuthority,
tab.name == nil || authority.source == .auto,
let cursor = state.cursor else { return nil }
self.projection = projection
generation = cursor.generation
nameRevision = authority.revision
}

init?(wire: Any?) {
guard let wire, JSONSerialization.isValidJSONObject(wire),
let bytes = try? JSONSerialization.data(withJSONObject: wire),
let value = try? JSONDecoder().decode(Self.self, from: bytes) else { return nil }
self = value
}

var wire: [String: Any]? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return (try? JSONSerialization.jsonObject(with: data)) as? [String: Any]
}
}
16 changes: 16 additions & 0 deletions Sources/Surfaces/CloudTabNameAuthority.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

/// The daemon persists provenance separately from display text. Legacy named
/// tabs are user-owned; a daemon without revision metadata cannot admit auto names.
struct CloudTabNameAuthority: Hashable, Codable, Sendable {
let source: CloudTabNameSource
let revision: UInt64

init?(snapshot: [String: Any]) {
guard let raw = snapshot["name_source"] as? String,
let source = CloudTabNameSource(rawValue: raw),
let revision = CloudWireNumber.unsigned(snapshot["name_revision"]) else { return nil }
self.source = source
self.revision = revision
}
}
5 changes: 5 additions & 0 deletions Sources/Surfaces/CloudTabNameSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// The durable writer whose name currently overrides the process title.
enum CloudTabNameSource: String, Codable, Sendable {
case user
case auto
}
14 changes: 14 additions & 0 deletions Sources/Surfaces/CloudVMTabState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

/// One accepted daemon tab, including the durable owner and revision of its name.
struct CloudVMTabState: Hashable, Codable, Sendable {
var id: String
var paneID: String
var name: String?
var index: Int
var focused: Bool
var contentKind: String
var contentID: String
var nameAuthority: CloudTabNameAuthority? = nil
}

Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ extension CloudWorkspaceRenameService {
guard let currentBinding = workspace.cloudVMBinding,
let id = currentBinding.remoteWorkspaceID,
let remote = state.lookupIndex.workspace(id: id) else { continue }
let key = CloudRenameCoordinator.Key.workspace(machine: machine, id: id)
if let pending = catalog.cloudRenameCoordinator.pendingName(for: key), pending != remote.name { continue }
if workspace.effectiveCustomTitleSource == .user { continue }
// Pending user edits are protected above. Confirmed names belong
// to the daemon; a generated prefix must not become a local alias.
if workspace.customTitle == remote.name, workspace.effectiveCustomTitleSource == .user { continue }
// Submission returns before local title setters run. Pending names
// are request metadata, not accepted UI values; both projections
// keep rendering this graph until the daemon acknowledges a write.
guard workspace.customTitle != remote.name || workspace.effectiveCustomTitleSource != .remote else { continue }
let manager = workspace.owningTabManager ?? environment.tabManager(workspace.id)
_ = manager?.setCustomTitle(tabId: workspace.id, title: remote.name, source: .remote,
Expand All @@ -93,9 +92,8 @@ extension CloudWorkspaceRenameService {
}
guard let tabID = remoteTabID(for: projection, resource: resource),
let tab = state.lookupIndex.tab(id: tabID) else { continue }
let key = CloudRenameCoordinator.Key.tab(machine: machine, id: tabID)
if let pending = catalog.cloudRenameCoordinator.pendingName(for: key), pending != (tab.name ?? "") { continue }
if workspace.panelCustomTitleSources[projection.panelID] == .user { continue }
if workspace.panelCustomTitles[projection.panelID] == tab.name,
workspace.panelCustomTitleSources[projection.panelID] == .user { continue }
guard workspace.panelCustomTitles[projection.panelID] != tab.name
|| (tab.name != nil && workspace.panelCustomTitleSources[projection.panelID] != .remote) else { continue }
_ = workspace.setPanelCustomTitle(panelId: projection.panelID, title: tab.name, source: .remote,
Expand Down
16 changes: 3 additions & 13 deletions Sources/Surfaces/CmuxTuiSnapshotParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,7 @@ struct CmuxTuiSnapshotParser: Sendable {
)
}
let tabs = ((snapshot["tabs"] as? [[String: Any]]) ?? []).enumerated().compactMap { index, raw -> CloudVMTabState? in
guard let id = nonEmptyString(raw["id"]), let paneID = nonEmptyString(raw["pane_id"]) else { return nil }
guard let contentKind = nonEmptyString(raw["content_kind"]), let contentID = nonEmptyString(raw["content_id"]) else { return nil }
let name = nonEmptyString(raw["name"])
return CloudVMTabState(
id: id,
paneID: paneID,
name: name,
index: integer(raw["index"]) ?? index,
focused: raw["focused"] as? Bool ?? false,
contentKind: contentKind,
contentID: contentID
)
tabState(from: raw, fallbackIndex: index)
}
// The public daemon schema puts the relationship on `tabs[].pane_id`.
// `panes[].tab_ids` is not part of that schema, so reading it would make
Expand Down Expand Up @@ -979,7 +968,8 @@ struct CmuxTuiSnapshotParser: Sendable {
index: integer(value["index"]) ?? fallbackIndex,
focused: value["focused"] as? Bool ?? false,
contentKind: contentKind,
contentID: contentID
contentID: contentID,
nameAuthority: CloudTabNameAuthority(snapshot: value)
)
}

Expand Down
30 changes: 30 additions & 0 deletions Sources/Surfaces/CmuxTuiSurfaceProvider+AgentNaming.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

extension CmuxTuiSurfaceProvider: SurfaceAgentNaming {
/// Automatic names use the revision captured before the agent computed them.
/// Refresh supplies current topology, but never upgrades that name precondition.
func renameAgentTab(context: CloudAgentNameContext, name: String) async throws {
let lifecycle = currentLifecycleGeneration
guard context.projection.resource.machine == machine,
await refreshCurrentGraph(force: true),
let state = cloudState,
CloudAgentNameContext(projection: context.projection, state: state) == context,
let cursor = state.cursor, let tabID = context.projection.remoteTabID else {
throw CancellationError()
}
let connected = try await links.connected(machineID: machineID)
guard isCurrentLifecycleGeneration(lifecycle), isRegisteredInCatalog(),
let link = await links.link(machineID: machineID) else { throw CancellationError() }
try Task.checkCancellation()
let data = try await link.run(arguments: CloudTuiCommandLine.agentRenameArguments(
socketPath: connected.socketPath, context: context, name: name
))
guard isCurrentLifecycleGeneration(lifecycle), isRegisteredInCatalog(),
let object = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
throw CancellationError()
}
let receipt = try validatedReceipt(CmuxTuiSnapshotParser.mutationCursor(fromResult: object), against: cursor)
recordPendingRemoteRename(tabID: tabID, name: name, receipt: receipt)
_ = await refreshCurrentGraph(force: true)
}
}
40 changes: 40 additions & 0 deletions Sources/Surfaces/CmuxTuiSurfaceProvider+TerminalIO.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
import Foundation

extension CmuxTuiSurfaceProvider {
/// Type `text` into the remote terminal exactly as given (no newline appended).
func sendText(terminalID: String, text: String) async throws {
let connected = try await links.connected(machineID: machineID)
guard let link = await links.link(machineID: machineID) else { throw ProviderError.machineAsleep(machineID) }
_ = try await link.run(arguments: CloudTuiCommandLine.writeArguments(socketPath: connected.socketPath, terminalID: terminalID, text: text))
}

/// Press named keys (`enter`, `ctrl+c`, …) in the remote terminal, in order.
func sendKeys(terminalID: String, keys: [String]) async throws {
let connected = try await links.connected(machineID: machineID)
guard let link = await links.link(machineID: machineID) else { throw ProviderError.machineAsleep(machineID) }
_ = try await link.run(arguments: CloudTuiCommandLine.keysArguments(socketPath: connected.socketPath, terminalID: terminalID, keys: keys))
}

/// The remote terminal's visible screen, as the daemon reports it
/// (`cols`, `rows`, `cursor_row`, `cursor_col`, `cursor_visible`, `text`).
func readScreen(terminalID: String) async throws -> [String: Any] {
let connected = try await links.connected(machineID: machineID)
guard let link = await links.link(machineID: machineID) else { throw ProviderError.machineAsleep(machineID) }
let data = try await link.run(arguments: CloudTuiCommandLine.screenReadArguments(socketPath: connected.socketPath, terminalID: terminalID))
return (try JSONSerialization.jsonObject(with: data) as? [String: Any]) ?? [:]
}

/// Block until the screen matches `pattern` (or the daemon-side timeout elapses):
/// `{matched, text}`. The link call itself is given headroom beyond the timeout.
func waitForScreen(terminalID: String, pattern: String, timeoutMs: Int?) async throws -> [String: Any] {
let connected = try await links.connected(machineID: machineID)
guard let link = await links.link(machineID: machineID) else { throw ProviderError.machineAsleep(machineID) }
// Non-positive requests mean the daemon default, so the link headroom is computed
// from the same value the daemon will use; huge requests are clamped so the
// Duration math cannot overflow.
let effectiveMs = Self.clampedWaitTimeoutMs(timeoutMs)
let linkTimeout = Duration.milliseconds(effectiveMs + 5_000)
let data = try await link.run(
arguments: CloudTuiCommandLine.screenWaitArguments(socketPath: connected.socketPath, terminalID: terminalID, pattern: pattern, timeoutMs: effectiveMs),
timeout: linkTimeout
)
return (try JSONSerialization.jsonObject(with: data) as? [String: Any]) ?? [:]
}

nonisolated static let defaultWaitTimeoutMs = 30_000
nonisolated static let maxWaitTimeoutMs = 3_600_000

Expand Down
Loading
Loading