fix(swift-ios): stabilize new task environment defaults
This commit is contained in:
9 files changed
+174
-25
No files matched your search
@@ -23,6 +23,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
private let fallbackPollingInitialDelay: Duration
|
||||
private let fallbackPollingInterval: Duration
|
||||
private let aggregateRefreshInterval: Duration
|
||||
private let environmentShellTimeoutInterval: TimeInterval
|
||||
private let aggregateEnvironmentLoader: @Sendable (EnvironmentRuntime) async throws -> [Environment]
|
||||
private let stream: AsyncStream<FeatureEvent>
|
||||
private let continuation: AsyncStream<FeatureEvent>.Continuation
|
||||
@@ -90,6 +91,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
fallbackPollingInitialDelay: Duration = .seconds(3),
|
||||
fallbackPollingInterval: Duration = .seconds(2),
|
||||
aggregateRefreshInterval: Duration = .seconds(20),
|
||||
environmentShellTimeoutInterval: TimeInterval = 6,
|
||||
aggregateEnvironmentLoader: @escaping @Sendable (EnvironmentRuntime) async throws -> [Environment] = {
|
||||
try await $0.environments()
|
||||
}
|
||||
@@ -117,6 +119,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
self.fallbackPollingInitialDelay = fallbackPollingInitialDelay
|
||||
self.fallbackPollingInterval = fallbackPollingInterval
|
||||
self.aggregateRefreshInterval = aggregateRefreshInterval
|
||||
self.environmentShellTimeoutInterval = environmentShellTimeoutInterval
|
||||
self.aggregateEnvironmentLoader = aggregateEnvironmentLoader
|
||||
let pair = AsyncStream<FeatureEvent>.makeStream()
|
||||
stream = pair.stream
|
||||
@@ -2522,6 +2525,7 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
) async -> [EnvironmentShellLoad] {
|
||||
let activeEnvironmentID = activeEnvironment?.id
|
||||
let environmentsWithCachedConfig = Set(serverConfigsByEnvironmentID.keys)
|
||||
let shellTimeoutInterval = environmentShellTimeoutInterval
|
||||
let runtime = runtime
|
||||
var clients: [(environment: Environment, client: T3Client)] = []
|
||||
clients.reserveCapacity(environments.count)
|
||||
@@ -2534,7 +2538,9 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
return await withTaskGroup(of: EnvironmentShellLoad.self) { group in
|
||||
for pair in clients {
|
||||
group.addTask {
|
||||
let shell = try? await pair.client.shellSnapshot()
|
||||
let shell = try? await pair.client.shellSnapshot(
|
||||
timeoutInterval: shellTimeoutInterval
|
||||
)
|
||||
guard shell != nil else {
|
||||
return EnvironmentShellLoad(
|
||||
environment: pair.environment,
|
||||
|
||||
@@ -125,13 +125,17 @@ public actor EnvironmentAPI {
|
||||
)
|
||||
}
|
||||
|
||||
public func shellSnapshot(for environment: Environment) async throws
|
||||
public func shellSnapshot(
|
||||
for environment: Environment,
|
||||
timeoutInterval: TimeInterval? = nil
|
||||
) async throws
|
||||
-> OrchestrationShellSnapshot
|
||||
{
|
||||
try await authorized(
|
||||
environment: environment,
|
||||
path: "/api/orchestration/shell",
|
||||
method: "GET",
|
||||
timeoutInterval: timeoutInterval,
|
||||
as: OrchestrationShellSnapshot.self
|
||||
)
|
||||
}
|
||||
@@ -229,6 +233,7 @@ public actor EnvironmentAPI {
|
||||
path: String,
|
||||
method: String,
|
||||
body: Data? = nil,
|
||||
timeoutInterval: TimeInterval? = nil,
|
||||
as type: Result.Type
|
||||
) async throws -> Result {
|
||||
guard let credential = try await credentials.credential(for: environment.id) else {
|
||||
@@ -246,6 +251,9 @@ public actor EnvironmentAPI {
|
||||
method: method,
|
||||
body: body
|
||||
)
|
||||
if let timeoutInterval {
|
||||
request.timeoutInterval = timeoutInterval
|
||||
}
|
||||
request.setValue(
|
||||
"Bearer \(credential.accessToken)",
|
||||
forHTTPHeaderField: "Authorization"
|
||||
@@ -272,7 +280,7 @@ public actor EnvironmentAPI {
|
||||
using: managedAuthorization
|
||||
)
|
||||
}
|
||||
let request = try await managedAuthorization.authorize(
|
||||
var request = try await managedAuthorization.authorize(
|
||||
makeRequest(
|
||||
environment: environment,
|
||||
path: path,
|
||||
@@ -282,6 +290,9 @@ public actor EnvironmentAPI {
|
||||
environment: environment,
|
||||
credential: current
|
||||
)
|
||||
if let timeoutInterval {
|
||||
request.timeoutInterval = timeoutInterval
|
||||
}
|
||||
do {
|
||||
return try await send(request, as: type)
|
||||
} catch let error as HTTPError where error.isRejectedAuthorization {
|
||||
@@ -298,7 +309,7 @@ public actor EnvironmentAPI {
|
||||
using: managedAuthorization
|
||||
)
|
||||
}
|
||||
let retry = try await managedAuthorization.authorize(
|
||||
var retry = try await managedAuthorization.authorize(
|
||||
makeRequest(
|
||||
environment: environment,
|
||||
path: path,
|
||||
@@ -308,6 +319,9 @@ public actor EnvironmentAPI {
|
||||
environment: environment,
|
||||
credential: current
|
||||
)
|
||||
if let timeoutInterval {
|
||||
retry.timeoutInterval = timeoutInterval
|
||||
}
|
||||
return try await send(retry, as: type)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,13 @@ public actor T3Client {
|
||||
await rpc.isConnected()
|
||||
}
|
||||
|
||||
public func shellSnapshot() async throws -> OrchestrationShellSnapshot {
|
||||
try await api.shellSnapshot(for: environment)
|
||||
public func shellSnapshot(
|
||||
timeoutInterval: TimeInterval? = nil
|
||||
) async throws -> OrchestrationShellSnapshot {
|
||||
try await api.shellSnapshot(
|
||||
for: environment,
|
||||
timeoutInterval: timeoutInterval
|
||||
)
|
||||
}
|
||||
|
||||
public func readModel() async throws -> OrchestrationReadModel {
|
||||
|
||||
@@ -77,9 +77,9 @@ enum FeatureRootPresentation {
|
||||
isManagingConnections: Bool
|
||||
) -> Bool {
|
||||
snapshot.connection.state != .disconnected
|
||||
|| !snapshot.environments.isEmpty
|
||||
|| !snapshot.projects.isEmpty
|
||||
|| !snapshot.threads.isEmpty
|
||||
|| (isManagingConnections && !snapshot.environments.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,14 +145,20 @@ enum DailyUXCreationContext {
|
||||
for project: FeatureProject?,
|
||||
in snapshot: FeatureSnapshot
|
||||
) -> FeatureSelection? {
|
||||
if let projectDefault = project?.defaultSelection {
|
||||
return projectDefault
|
||||
}
|
||||
return DailyUXModelOptions.initialSelection(
|
||||
projectDefault: nil,
|
||||
appDefault: snapshot.settings.defaultSelection,
|
||||
providers: providers(for: project, in: snapshot)
|
||||
)
|
||||
let providers = providers(for: project, in: snapshot)
|
||||
return DailyUXModelOptions.validated(snapshot.settings.defaultSelection, in: providers)
|
||||
?? DailyUXModelOptions.validated(project?.defaultSelection, in: providers)
|
||||
?? DailyUXModelOptions.preferredSelection(in: providers)
|
||||
}
|
||||
|
||||
static func selection(
|
||||
carrying preferredSelection: FeatureSelection?,
|
||||
to project: FeatureProject?,
|
||||
in snapshot: FeatureSnapshot
|
||||
) -> FeatureSelection? {
|
||||
let providers = providers(for: project, in: snapshot)
|
||||
return DailyUXModelOptions.validated(preferredSelection, in: providers)
|
||||
?? initialSelection(for: project, in: snapshot)
|
||||
}
|
||||
|
||||
static func environmentPreferences(
|
||||
|
||||
@@ -13,6 +13,8 @@ public struct NewThreadView: View {
|
||||
@State private var prompt = ""
|
||||
@State private var selection: FeatureSelection?
|
||||
@State private var selectionIsExplicit = false
|
||||
@State private var preferredSelection: FeatureSelection?
|
||||
@State private var recentProjectByEnvironment: [String: String] = [:]
|
||||
@State private var attachments: [FeatureDraftAttachment] = []
|
||||
@State private var workspaceMode: FeatureWorkspaceMode = .local
|
||||
@State private var workspaceSelectionIsExplicit = false
|
||||
@@ -190,13 +192,36 @@ public struct NewThreadView: View {
|
||||
.multilineTextAlignment(.center)
|
||||
.frame(maxWidth: .infinity)
|
||||
.overlay(alignment: .bottom) {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "server.rack")
|
||||
.font(.system(size: 11, weight: .medium))
|
||||
Text("on \(environmentName)")
|
||||
Menu {
|
||||
ForEach(creationEnvironments) { environment in
|
||||
Button {
|
||||
selectEnvironment(environment.id)
|
||||
} label: {
|
||||
if environment.id == selectedProject?.environmentID {
|
||||
Label(environment.name, systemImage: "checkmark")
|
||||
} else {
|
||||
Text(environment.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "server.rack")
|
||||
.font(.system(size: 11, weight: .medium))
|
||||
Text("on \(environmentName)")
|
||||
if creationEnvironments.count > 1 {
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.system(size: 8, weight: .bold))
|
||||
}
|
||||
}
|
||||
.font(T3Typography.supporting)
|
||||
.foregroundStyle(T3Colors.textTertiary)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.font(T3Typography.supporting)
|
||||
.foregroundStyle(T3Colors.textTertiary)
|
||||
.buttonStyle(.plain)
|
||||
.disabled(isSubmitting || creationEnvironments.count < 2)
|
||||
.accessibilityLabel("Computer")
|
||||
.accessibilityValue(environmentName)
|
||||
.offset(y: 31)
|
||||
}
|
||||
.accessibilityElement(children: .contain)
|
||||
@@ -338,6 +363,11 @@ public struct NewThreadView: View {
|
||||
creationProjects.map(\.id)
|
||||
}
|
||||
|
||||
private var creationEnvironments: [FeatureEnvironment] {
|
||||
let environmentIDs = Set(creationProjects.map(\.environmentID))
|
||||
return model.snapshot.environments.filter { environmentIDs.contains($0.id) }
|
||||
}
|
||||
|
||||
private var environmentName: String {
|
||||
if let environmentID = selectedProject?.environmentID,
|
||||
let environment = model.snapshot.environments.first(where: { $0.id == environmentID }) {
|
||||
@@ -369,6 +399,7 @@ public struct NewThreadView: View {
|
||||
set: { value in
|
||||
selectionIsExplicit = true
|
||||
selection = value
|
||||
preferredSelection = value
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -506,6 +537,15 @@ public struct NewThreadView: View {
|
||||
prepareProjectIfNeeded(id)
|
||||
}
|
||||
|
||||
private func selectEnvironment(_ id: String) {
|
||||
guard selectedProject?.environmentID != id else { return }
|
||||
let project = recentProjectByEnvironment[id].flatMap { recentID in
|
||||
creationProjects.first { $0.id == recentID && $0.environmentID == id }
|
||||
} ?? creationProjects.first { $0.environmentID == id }
|
||||
guard let project else { return }
|
||||
selectProject(project.id)
|
||||
}
|
||||
|
||||
private func selectInitialProject(_ id: String) {
|
||||
projectID = id
|
||||
prepareProjectIfNeeded(id)
|
||||
@@ -514,6 +554,10 @@ public struct NewThreadView: View {
|
||||
private func prepareProjectIfNeeded(_ id: String) {
|
||||
guard draftRestoreContext?.projectID != id else { return }
|
||||
|
||||
if selectionIsExplicit, let selection {
|
||||
preferredSelection = selection
|
||||
}
|
||||
|
||||
restoredDraftProjectID = nil
|
||||
draftSaveTask?.cancel()
|
||||
draftSaveTask = nil
|
||||
@@ -534,13 +578,21 @@ public struct NewThreadView: View {
|
||||
return
|
||||
}
|
||||
|
||||
recentProjectByEnvironment[project.environmentID] = project.id
|
||||
|
||||
let providers = ProviderModelCatalogNormalizer.normalized(
|
||||
DailyUXCreationContext.providers(for: project, in: model.snapshot)
|
||||
)
|
||||
let carriedSelection = DailyUXModelOptions.validated(preferredSelection, in: providers)
|
||||
selection = ProviderModelSelectionResolver.materialized(
|
||||
DailyUXCreationContext.initialSelection(for: project, in: model.snapshot),
|
||||
DailyUXCreationContext.selection(
|
||||
carrying: preferredSelection,
|
||||
to: project,
|
||||
in: model.snapshot
|
||||
),
|
||||
in: providers
|
||||
)
|
||||
selectionIsExplicit = carriedSelection != nil
|
||||
let preferences = DailyUXCreationContext.environmentPreferences(
|
||||
for: project,
|
||||
in: model.snapshot
|
||||
@@ -636,8 +688,12 @@ public struct NewThreadView: View {
|
||||
)
|
||||
prompt = restored.text
|
||||
attachments = restored.attachments
|
||||
selection = restored.selection
|
||||
selection = DailyUXModelOptions.validated(restored.selection, in: creationProviders)
|
||||
?? initialSelection
|
||||
selectionIsExplicit = liveSelectionIsExplicit || saved?.selection != nil
|
||||
if selectionIsExplicit, let selection {
|
||||
preferredSelection = selection
|
||||
}
|
||||
if let workspace = restored.workspace {
|
||||
workspaceMode = workspace.mode
|
||||
selectedBranch = workspace.branch.map {
|
||||
|
||||
@@ -54,6 +54,31 @@ final class TransportReliabilityTests: XCTestCase {
|
||||
XCTAssertEqual(request.value(forHTTPHeaderField: "Accept-Encoding"), "gzip")
|
||||
}
|
||||
|
||||
func testShellSnapshotAppliesBoundedStartupTimeout() async throws {
|
||||
let environment = Environment(
|
||||
id: "environment-1",
|
||||
label: "Studio",
|
||||
httpBaseURL: URL(string: "https://studio.example")!,
|
||||
webSocketBaseURL: URL(string: "wss://studio.example")!
|
||||
)
|
||||
let credentials = InMemoryCredentialStore(
|
||||
credentials: [
|
||||
environment.id: EnvironmentCredential(accessToken: "access-token"),
|
||||
]
|
||||
)
|
||||
let transport = RecordingHTTPTransport { request in
|
||||
let body = #"{"snapshotSequence":0,"projects":[],"threads":[],"updatedAt":"2026-08-05T12:00:00.000Z"}"#
|
||||
return (Data(body.utf8), transportResponse(request))
|
||||
}
|
||||
let api = EnvironmentAPI(transport: transport, credentials: credentials)
|
||||
|
||||
_ = try await api.shellSnapshot(for: environment, timeoutInterval: 6)
|
||||
|
||||
let requests = await transport.requests
|
||||
let request = try XCTUnwrap(requests.first)
|
||||
XCTAssertEqual(request.timeoutInterval, 6)
|
||||
}
|
||||
|
||||
func testWebSocketHandshakeOffersPerMessageDeflate() {
|
||||
let url = URL(string: "wss://studio.example/ws?wsTicket=secret")!
|
||||
let compressed = WebSocketHandshakeRequest.make(url: url)
|
||||
|
||||
@@ -226,6 +226,43 @@ struct DailyUXNewTaskTests {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
func appDefaultWinsAndExplicitModelCarriesAcrossCompatibleProjects() throws {
|
||||
let appDefault = FeatureSelection(providerID: "codex", modelID: "gpt-5.6-sol")
|
||||
let explicit = FeatureSelection(providerID: "codex", modelID: "gpt-5.6-luna")
|
||||
let project = FeatureProject(
|
||||
id: "project",
|
||||
environmentID: "studio",
|
||||
name: "Project",
|
||||
path: "/project",
|
||||
defaultSelection: .init(providerID: "codex", modelID: "gpt-5.6-terra")
|
||||
)
|
||||
let snapshot = FeatureSnapshot(
|
||||
projects: [project],
|
||||
providers: [
|
||||
.init(
|
||||
id: "codex",
|
||||
name: "Codex",
|
||||
models: [
|
||||
.init(id: "gpt-5.6-luna", name: "Luna"),
|
||||
.init(id: "gpt-5.6-terra", name: "Terra"),
|
||||
.init(id: "gpt-5.6-sol", name: "Sol"),
|
||||
]
|
||||
),
|
||||
],
|
||||
settings: .init(defaultSelection: appDefault)
|
||||
)
|
||||
|
||||
#expect(DailyUXCreationContext.initialSelection(for: project, in: snapshot) == appDefault)
|
||||
#expect(
|
||||
DailyUXCreationContext.selection(
|
||||
carrying: explicit,
|
||||
to: project,
|
||||
in: snapshot
|
||||
) == explicit
|
||||
)
|
||||
}
|
||||
|
||||
@Test @MainActor
|
||||
func imageProcessorDownsamplesUploadAndBuildsSmallThumbnail() throws {
|
||||
let source = UIGraphicsImageRenderer(size: CGSize(width: 2_400, height: 1_200))
|
||||
|
||||
@@ -6,7 +6,7 @@ import Testing
|
||||
@Suite("Feature root model")
|
||||
struct FeatureRootModelTests {
|
||||
@Test
|
||||
func connectionManagementStaysMountedForDisconnectedSavedServers() {
|
||||
func savedServersKeepWorkspaceNavigationAvailableWhileDisconnected() {
|
||||
let savedEnvironment = FeatureEnvironment(
|
||||
id: "offline-demo",
|
||||
name: "Offline demo",
|
||||
@@ -25,7 +25,7 @@ struct FeatureRootModelTests {
|
||||
)
|
||||
)
|
||||
#expect(
|
||||
!FeatureRootPresentation.showsWorkspace(
|
||||
FeatureRootPresentation.showsWorkspace(
|
||||
snapshot: snapshot,
|
||||
isManagingConnections: false
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user