fix(swift-ios): hydrate live environments independently #10761
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 12 commits into
t3code/rebuild-mobile-app-swift fromrefs/pull/10761/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/Features/Root/FeatureRootModel.swift line 156Resolvedby saphid(GitHub profile, opens in a new tab)@@ -135,3 +135,4 @@135135136136 func applicationDidEnterBackground(at date: Date = .now) {137137 backgroundedAt = date138+ client.suspendForBackground()apps/swift-ios/App/NativeFeatureClient.swift lines 5620 to 5627Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -4609,17 +5098,4 @@4609- guard shell.snapshotSequence4610- >= (shellsByEnvironmentID[environment.id]?.snapshotSequence ?? .min) else {4611- return4612- }4613- shellsByEnvironmentID[environment.id] = shell4614- if activeEnvironment?.id == environment.id {4615- latestShell = shell4616- }4617- if includeArchived,4618- let archivedShell = try? await client.archivedShellSnapshot(),4619- isKnownClient(client, environmentID: environment.id, generation: generation) {4620- archivedThreadsByEnvironmentID[environment.id] = archivedShell.threads.map {4621- mapThread($0, environment: environment)4622- }4623- archivedShellThreadsByEnvironmentID[environment.id] = Dictionary(4624- uniqueKeysWithValues: archivedShell.threads.map { ($0.id, $0) }4625- )5098+ // Optional archive work cannot carry a pre-reload shell through another5099+ // suspension and then establish authority in the replacement bootstrap.5100+ let archivedShell = includeArchived ? try? await client.archivedShellSnapshot() : nil5101+ let currentConnectionID = await client.currentConnectionID()
- @@ -3982,8 +4221,4 @@39824221 case .unrelated:39834222 continue39844223 }3985- if let shell = self.latestShell {3986- await self.emitSnapshot(3987- shell, client: activeClient, expectedGeneration: generation3988- )3989- }4224+ let environments = try await self.runtime.environments()apps/swift-ios/Features/Root/FeatureRootModel.swift line 1538OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1523,4 +1529,10 @@15231529 return true15241530 }152515311532+ private func forgetDeliveredMessages(threadID: String) {1533+ deliveredAwaitingDetail = deliveredAwaitingDetail.filter { $0.value.threadID != threadID }1534+ serverMessageIDs[threadID] = nil1535+ }1536+15261537 private func removeDetail(id: String) {1538+ forgetDeliveredMessages(threadID: id)
- @@ -1823,3 +1863,8 @@18231863 }18241864 pendingCompletionSubmissionIDs.remove(submission.id)18251865 pendingSubmissionsByID.removeValue(forKey: submission.id)1866+ // A transcript that already includes it confirmed delivery; do not retain it.1867+ if serverMessageIDs[submission.threadID]?.contains(submission.identity.messageID) != true {1868+ var message = queuedMessage(for: submission)1869+ message.state = .complete1870+ deliveredAwaitingDetail[submission.identity.messageID] = (submission.threadID, message)
- @@ -483,3 +669,5 @@483669 }484670485671 func removeEnvironment(id: String) async throws {672+ shellConnectionIDsByEnvironmentID[id] = nil673+ aggregateRefreshWorkers.removeValue(forKey: id)?.task.cancel()@@ -4095,0 +4594,21 @@4594+ owner.publishAggregateSnapshot(self.savedEnvironments, changedEnvironmentIDs: dirty)4595+ }4596+ }4597+4598+ func applyShell(4599+ _ shell: OrchestrationShellSnapshot?, client: T3Client,4600+ environment: Environment, saved: [Environment], replacingEpoch: Bool = false4601+ ) -> Duration {4602+ guard let owner, isCurrent else { return failureInterval }4603+ let previous = owner.shellsByEnvironmentID[environment.id]4604+ let changed = shell.map { $0 != previous } ?? false4605+ let membershipChanged = shell.map {4606+ $0.projects.map(\.id) != previous?.projects.map(\.id)4607+ || $0.threads.map(\.id) != previous?.threads.map(\.id)4608+ } ?? false4609+ if replacingEpoch, let shell { owner.shellsByEnvironmentID[environment.id] = shell }4610+ owner.applyEnvironmentLoad(EnvironmentShellLoad(4611+ environment: environment, client: client, shell: shell, config: nil4612+ ))4613+ if membershipChanged { owner.rebuildEntityIndexes(saved) }4614+ owner.publishAggregateSnapshot(saved, changedEnvironmentIDs: [environment.id])
- @@ -4050,13 +4468,10 @@40504468 return4469+ } catch {4470+ // HTTP recovery belongs to this peer's single fallback loop.40514471 }4052- let passiveEnvironments = environments.filter {4053- $0.isEnabled && $0.id != activeEnvironment.id4054- }4055- guard !passiveEnvironments.isEmpty else {4056- nextInterval = idleInterval4057- 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)4472+ guard owns(environment) else { return }4473+ state.isLive = false4474+ // A read begun before the stream lost completeness cannot4475+ // repair that gap, even if the socket identity is unchanged.4476+ state.authorityRevision &+= 14477+ markStreamPaused(environment)
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed