fix(swift-ios): reconcile silent selected-thread streams #10763
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 14 commits into
t3code/rebuild-mobile-app-swift fromrefs/pull/10763/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/swift-ios/App/NativeFeatureClient.swift line 676Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -461,3 +654,6 @@461654 }462655463656 func setEnvironmentEnabled(id: String, enabled: Bool) async throws {657+ if !enabled {658+ shellConnectionIDsByEnvironmentID[id] = nil659+ aggregateRefreshWorkers.removeValue(forKey: id)?.task.cancel()apps/swift-ios/App/NativeFeatureClient.swift line 314Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -222,16 +295,13 @@222295 let environments = try await runtime.environments()296+ guard bootstrapID == foregroundBootstrapID else { throw CancellationError() }223297 guard let activeClient = try await runtime.activeClient() else {224- await clearActiveEnvironment()298+ await clearActiveEnvironment(disconnectClient: false)225299 let snapshot = disconnectedSnapshot(environments: environments)226300 latestSnapshot = snapshot227301 return snapshot228302 }229- // The runtime actor can change its active selection at any suspension230- // point. Derive both values from one client so the snapshot cannot pair231- // one environment with another environment's connection.303+ guard bootstrapID == foregroundBootstrapID else { throw CancellationError() }232304 let environment = activeClient.environment233-234305 await adoptEnvironment(environment, client: activeClient)235- let generation = environmentGeneration236- let loads = await loadEnvironmentShells(environments.filter(\.isEnabled))237- guard isCurrentSession(client: activeClient, generation: generation) else {306+ guard bootstrapID == foregroundBootstrapID,307+ isCurrentSession(client: activeClient, generation: environmentGeneration) else {
- apps/swift-ios/Features/Root/FeatureRootModel.swift line 1756OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1738,3 +1752,5 @@17381752 }1739175317401754 private func addingPendingMessages(to incoming: FeatureThreadDetail) -> FeatureThreadDetail {1755+ let existing = Set(incoming.messages.map(\.id))1756+ serverMessageIDs[incoming.thread.id] = existing
- @@ -4057,6 +4492,15 @@4057- continue4058- }4059- let passiveIDs = Set(passiveEnvironments.map(\.id))4060- failureBackoffs = failureBackoffs.reduce(into: [:]) { result, entry in4061- guard passiveIDs.contains(entry.key) else { return }4062- result[entry.key] = max(.zero, entry.value - elapsedInterval)4492+ guard owns(environment) else { return }4493+ state.isLive = false4494+ // A read begun before the stream lost completeness cannot4495+ // repair that gap, even if the socket identity is unchanged.4496+ state.authorityRevision &+= 14497+ markStreamPaused(environment)4498+ state.requestRepair()4499+ do { try await streamRetrySleep(environment.id, failureInterval) } catch { return }4500+ }4501+ }4502+4503+ func markStreamPaused(_ environment: Environment) {4504+ guard let owner, owns(environment) else { return }4505+ owner.shellConnectionIDsByEnvironmentID[environment.id] = nil4506+ owner.environmentConnectionStates[environment.id] = .reconnecting@@ -3982,8 +4241,5 @@39824241 case .unrelated:39834242 continue39844243 }3985- if let shell = self.latestShell {3986- await self.emitSnapshot(3987- shell, client: activeClient, expectedGeneration: generation3988- )3989- }4244+ // A failed catalog read skips this publish; later events still apply.4245+ guard let environments = try? await self.runtime.environments() else { continue }@@ -5290,0 +6089,21 @@6089+ rawThread.latestTurn?.completedAt == completed.completedAt,6090+ rawThread.messages.contains(where: {6091+ $0.role == "assistant" && $0.turnId == completed.turnId && !$0.streaming6092+ }),6093+ !rawThread.messages.contains(where: {6094+ $0.role == "assistant" && $0.turnId == completed.turnId && $0.streaming6095+ }) {6096+ flushDetailPublish(route)6097+ return6098+ }6099+6100+ // Equal-cursor completion may flush final content, but only a newer6101+ // shell can prove that detail is missing and require HTTP repair.6102+ guard sequence > (activeThreadSequence ?? .min) else { return }6103+6104+ // Keep rendered partial text while requiring a snapshot that includes6105+ // the shell's completion. Later detail events advance this same floor.6106+ flushDetailPublish(route)6107+ activeRawThread = nil6108+ activeThreadSequence = sequence6109+ scheduleDetailRefresh(threadID: threadID, client: route.client, force: true)
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed