fix(swift-ios): record thread receipts and keep tool history chronological #10766
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 28 commits into
t3code/rebuild-mobile-app-swift fromrefs/pull/10766/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
saphid(GitHub profile, opens in a new tab) changed the title
- @@ -7354,15 +8150,8 @@73548150 requiresFullRebuild = true7355- messages.removeAll(keepingCapacity: true)7356- activities.removeAll(keepingCapacity: true)8151+ ordered.removeAll(keepingCapacity: true)73578152 case let .message(message):7358- if let index = messages.firstIndex(where: { $0.id == message.id }) {7359- messages[index] = message7360- } else {7361- messages.append(message)7362- }7363- case let .activity(activity):7364- if let index = activities.firstIndex(where: { $0.id == activity.id }) {7365- activities[index] = activity7366- } else {7367- activities.append(activity)7368- }8153+ if case let .message(previous) = ordered.last, previous.id == message.id {8154+ ordered[ordered.count - 1] = mutation8155+ } else { ordered.append(mutation) }8156+ case .activity:8157+ ordered.append(mutation)apps/swift-ios/Features/Root/FeatureRootModel.swift line 1222Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1015,16 +1206,13 @@10151206 for submission in queued {10161207 if !(await discardQueuedSubmission(submission)) {1208+ discardedAll = false10171209 scheduleOutboxRetry()10181210 }10191211 }1212+ guard discardedAll else { throw FeatureStopStatusUnavailableError() }10201213 if pendingThreadsByID[threadID] == nil,10211214 snapshot.threads.contains(where: { $0.id == threadID }) {1022- await perform {1023- try await client.cancelTurn(threadID: threadID)1024- }1215+ try await client.cancelTurn(threadID: threadID)1216+ return true10251217 }1026- scheduleOutboxDrain()1027- return1028- }1029- await perform {1030- try await client.cancelTurn(threadID: threadID)1218+ return false
- apps/swift-ios/App/NativeFeatureClient.swift line 2599OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2291,3 +2592,8 @@22912592 return snapshot.thread.messages.contains { $0.id == messageID }22922593 }229325942595+ func stopStatus(threadID: String) async throws -> FeatureThread {2596+ let route = try threadRoute(for: threadID)2597+ let generation = environmentGeneration2598+ let bootstrapID = foregroundBootstrapID2599+ try await refresh(client: route.client)
- apps/swift-ios/Features/Root/FeatureRootModel.swift line 1739OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1523,4 +1730,10 @@15231730 return true15241731 }152517321733+ private func forgetDeliveredMessages(threadID: String) {1734+ deliveredAwaitingDetail = deliveredAwaitingDetail.filter { $0.value.threadID != threadID }1735+ serverMessageIDs[threadID] = nil1736+ }1737+15261738 private func removeDetail(id: String) {1739+ forgetDeliveredMessages(threadID: id)
- @@ -1823,3 +2066,6 @@18232066 }18242067 pendingCompletionSubmissionIDs.remove(submission.id)18252068 pendingSubmissionsByID.removeValue(forKey: submission.id)2069+ // A transcript that already includes it confirmed delivery; do not retain it.2070+ if serverMessageIDs[submission.threadID]?.contains(submission.identity.messageID) != true {2071+ var message = queuedMessage(for: submission)
- @@ -6122,11 +7055,7 @@61227055 let messages = thread.messages.map {61237056 mapMessage($0, environmentID: environmentID)61247057 }6125- let workIsLive = thread.session?.status == "starting"6126- || thread.session?.status == "running"6127- || backgroundLiveness(threadID: thread.id, environmentID: environmentID) == .working6128- let activities = thread.activities.compactMap {6129- NativeActivityNotice.message($0, createdAt: parseDate($0.createdAt))6130- }6131- + collapsedWorkLogs(thread.activities, sessionIsLive: workIsLive)6132- return (messages + activities).sorted { $0.createdAt < $1.createdAt }7058+ // Older pages contain earlier turn windows, but carry current session7059+ // metadata. That metadata must not revive their historical tool rows.7060+ return NativeTranscriptTimeline(7061+ messages: messages, activities: thread.activities, sessionIsLive: false
saphid(GitHub profile, opens in a new tab) changed the title
juliusmarminge closed this
Sign in to join this conversation.

Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies.