Skip to content

Commit f95ca90

Browse files
authored
fix(ios): persist voice notes through offline delivery (#101236)
* fix(ios): persist voice note delivery state * fix(ios): pin chats during attachment staging * fix(ios): keep voice notes on captured chat * fix(ios): keep voice notes durable through staging * fix(ios): harden voice note lifecycle * test(ios): satisfy strict concurrency in voice note proof * fix(ios): keep legacy attachment sends live * fix(ios): retain legacy drafts during outbox restore * fix(ios): pin voice note recipient presentation * fix(ios): preserve confirmed voice note duration * chore(i18n): refresh voice note source inventory * chore: leave release notes to release automation
1 parent f305e70 commit f95ca90

19 files changed

Lines changed: 1529 additions & 307 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 105 additions & 73 deletions
Large diffs are not rendered by default.

‎apps/ios/Sources/Design/ChatProTab.swift‎

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ struct ChatProTab: View {
1717
// Track the real agent so gateway metadata replaces the captured transport.
1818
@State private var viewModelTransportAgentID = ""
1919
@State private var viewModelRoutingContract = ""
20+
@State private var viewModelPresentationAgentID = "main"
21+
@State private var viewModelPresentationAgentName = "Main"
22+
@State private var viewModelPresentationAgentBadge = "M"
23+
@State private var viewModelHasVerifiedOfflineRoutingIdentity = false
2024
@State private var speech: OpenClawChatSpeechController?
2125
let headerLeadingAction: OpenClawSidebarHeaderAction?
2226
let headerTitle: String?
@@ -75,6 +79,14 @@ struct ChatProTab: View {
7579
.onChange(of: self.appModel.chatSessionRoutingContract) { _, _ in
7680
self.syncChatViewModel()
7781
}
82+
.onChange(of: self.appModel.voiceNoteRecorder.ownsPendingChatAttachment) { _, _ in
83+
self.viewModel?.attachmentOwnerActivityChanged()
84+
self.syncChatViewModel()
85+
}
86+
.onChange(of: self.viewModel?.isAttachmentOwnerPinned) { _, pinned in
87+
guard pinned == false else { return }
88+
self.syncChatViewModel()
89+
}
7890
.onChange(of: self.appModel.isAppleReviewDemoModeEnabled) { _, _ in
7991
self.syncChatViewModel()
8092
self.viewModel?.refresh()
@@ -145,11 +157,11 @@ struct ChatProTab: View {
145157
showsAssistantAvatars: false,
146158
composerChrome: .clean,
147159
isComposerEnabled: self.gatewayConnected || self.canQueueOffline,
148-
isAttachmentInputEnabled: self.gatewayConnected,
160+
isAttachmentInputEnabled: self.gatewayConnected || self.canQueueOffline,
149161
messagePlaceholder: self.messagePlaceholder,
150162
emptyAssistantIntro: String(localized: "What would you like to work on?"),
151163
emptyAssistantPrompts: Self.emptyAssistantPrompts,
152-
talkControl: self.talkControl,
164+
talkControl: viewModel.isAttachmentOwnerPinned ? nil : self.talkControl,
153165
voiceNoteControl: self.voiceNoteControl,
154166
speech: self.speech)
155167
// iMessage-style grey bubbles for agent replies in the clean chrome.
@@ -188,6 +200,7 @@ struct ChatProTab: View {
188200
self.viewModelOwnerID = ownerID
189201
self.viewModelTransportAgentID = transportAgentID
190202
self.viewModelRoutingContract = routingContract
203+
self.captureCurrentPresentationIdentity()
191204
self.viewModel = self.makeChatViewModel(sessionKey: sessionKey)
192205
return
193206
}
@@ -197,31 +210,46 @@ struct ChatProTab: View {
197210
currentTransportAgentID: self.viewModelTransportAgentID,
198211
nextTransportAgentID: transportAgentID)
199212
{
213+
// Keep recording, staging, and delivery on their captured route.
214+
// The pin-change observer replays this rebuild with latest state.
215+
guard !viewModel.isAttachmentOwnerPinned else { return }
200216
self.viewModelOwnerID = ownerID
201217
self.viewModelTransportAgentID = transportAgentID
202218
self.viewModelRoutingContract = routingContract
219+
self.captureCurrentPresentationIdentity()
203220
self.viewModel = self.makeChatViewModel(sessionKey: sessionKey)
204221
return
205222
}
206223
if self.viewModelRoutingContract != routingContract {
207224
self.viewModelRoutingContract = routingContract
208225
viewModel.syncSessionRoutingContract(self.appModel.chatSessionRoutingContract)
209226
}
210-
guard viewModel.sessionKey != sessionKey else { return }
211227
viewModel.syncSession(to: sessionKey)
228+
if !viewModel.isAttachmentOwnerPinned {
229+
self.captureCurrentPresentationIdentity()
230+
}
231+
}
232+
233+
private func captureCurrentPresentationIdentity() {
234+
self.viewModelPresentationAgentID = self.currentAgentID
235+
self.viewModelPresentationAgentName = self.currentAgentDisplayName
236+
self.viewModelPresentationAgentBadge = self.currentAgentBadge
237+
self.viewModelHasVerifiedOfflineRoutingIdentity = self.appModel.hasVerifiedChatOfflineRoutingIdentity
212238
}
213239

214240
private func makeChatViewModel(sessionKey: String) -> OpenClawChatViewModel {
215241
// One store instance backs both seams so the transcript cache and the
216242
// offline outbox share a single SQLite connection.
217243
let offlineStore = self.appModel.makeChatOfflineStore()
244+
let voiceNoteRecorder = self.appModel.voiceNoteRecorder
218245
return OpenClawChatViewModel(
219246
sessionKey: sessionKey,
220247
// Bind durable rows and their transport lease to the exact same
221248
// gateway owner even if app state switches between these calls.
222249
transport: self.appModel.makeChatTransport(outboxGatewayID: offlineStore?.gatewayID),
223250
activeAgentId: self.appModel.chatDeliveryAgentId,
224251
sessionRoutingContract: self.appModel.chatSessionRoutingContract,
252+
attachmentOwnerIsActive: { voiceNoteRecorder.ownsPendingChatAttachment },
225253
transcriptCache: offlineStore,
226254
outbox: offlineStore,
227255
onSessionChanged: { sessionKey in
@@ -249,12 +277,7 @@ struct ChatProTab: View {
249277
private var voiceNoteControl: OpenClawChatVoiceNoteControl {
250278
OpenClawChatVoiceNoteControl(
251279
recorder: self.appModel.voiceNoteRecorder,
252-
isTalkActive: self.appModel.talkMode.isEnabled || self.appModel.talkMode.isPushToTalkActive)
253-
}
254-
255-
private var activeAgentID: String {
256-
self.normalized(self.appModel.chatAgentId)
257-
?? "main"
280+
isTalkActive: self.appModel.isTalkCaptureActive)
258281
}
259282

260283
@ViewBuilder
@@ -296,7 +319,7 @@ struct ChatProTab: View {
296319
Image(systemName: "plus.bubble")
297320
}
298321
}
299-
.disabled(self.viewModel == nil || !self.gatewayConnected)
322+
.disabled(self.viewModel == nil || !self.gatewayConnected || self.isAttachmentOwnerPinned)
300323

301324
if self.activeAgent?.workspacegit == true {
302325
Button {
@@ -309,7 +332,7 @@ struct ChatProTab: View {
309332
Image(systemName: "arrow.triangle.branch")
310333
}
311334
}
312-
.disabled(self.viewModel == nil || !self.gatewayConnected)
335+
.disabled(self.viewModel == nil || !self.gatewayConnected || self.isAttachmentOwnerPinned)
313336
}
314337

315338
Divider()
@@ -358,7 +381,23 @@ struct ChatProTab: View {
358381
}
359382

360383
private var gatewayDisplayState: GatewayDisplayState {
361-
GatewayStatusBuilder.build(appModel: self.appModel)
384+
Self.presentationGatewayState(
385+
current: GatewayStatusBuilder.build(appModel: self.appModel),
386+
isAttachmentOwnerPinned: self.isAttachmentOwnerPinned,
387+
capturedOwnerID: self.viewModelOwnerID,
388+
currentOwnerID: self.appModel.chatViewModelOwnerID)
389+
}
390+
391+
nonisolated static func presentationGatewayState(
392+
current: GatewayDisplayState,
393+
isAttachmentOwnerPinned: Bool,
394+
capturedOwnerID: String,
395+
currentOwnerID: String) -> GatewayDisplayState
396+
{
397+
if isAttachmentOwnerPinned, capturedOwnerID != currentOwnerID {
398+
return .disconnected
399+
}
400+
return current
362401
}
363402

364403
private var gatewayAccessibilityLabel: String {
@@ -403,7 +442,9 @@ struct ChatProTab: View {
403442

404443
private var canQueueOffline: Bool {
405444
self.viewModel?.supportsOfflineTextOutbox == true &&
406-
self.appModel.hasVerifiedChatOfflineRoutingIdentity
445+
(self.isAttachmentOwnerPinned
446+
? self.viewModelHasVerifiedOfflineRoutingIdentity
447+
: self.appModel.hasVerifiedChatOfflineRoutingIdentity)
407448
}
408449

409450
private var headerDisplayTitle: String {
@@ -419,22 +460,50 @@ struct ChatProTab: View {
419460
OpenClawBrand.accent
420461
}
421462

463+
private var isAttachmentOwnerPinned: Bool {
464+
self.viewModel?.isAttachmentOwnerPinned == true
465+
}
466+
467+
private var currentAgentID: String {
468+
self.normalized(self.appModel.chatAgentId) ?? "main"
469+
}
470+
471+
private var currentActiveAgent: AgentSummary? {
472+
self.appModel.gatewayAgents.first { $0.id == self.currentAgentID }
473+
}
474+
475+
private var activeAgentID: String {
476+
self.isAttachmentOwnerPinned ? self.viewModelPresentationAgentID : self.currentAgentID
477+
}
478+
422479
private var activeAgent: AgentSummary? {
423480
self.appModel.gatewayAgents.first { $0.id == self.activeAgentID }
424481
}
425482

483+
private var currentAgentDisplayName: String {
484+
self.normalized(self.currentActiveAgent?.name) ?? self.appModel.chatAgentName
485+
}
486+
426487
private var agentDisplayName: String {
427-
self.normalized(self.activeAgent?.name) ?? self.appModel.chatAgentName
488+
self.isAttachmentOwnerPinned ? self.viewModelPresentationAgentName : self.currentAgentDisplayName
428489
}
429490

430-
private var agentBadge: String {
431-
if let identity = activeAgent?.identity,
491+
private var currentAgentBadge: String {
492+
if let identity = self.currentActiveAgent?.identity,
432493
let emoji = identity["emoji"]?.value as? String,
433494
let normalizedEmoji = Self.normalizedBadgeEmoji(emoji)
434495
{
435496
return normalizedEmoji
436497
}
437-
let words = self.agentDisplayName
498+
return Self.initialsBadge(for: self.currentAgentDisplayName)
499+
}
500+
501+
private var agentBadge: String {
502+
self.isAttachmentOwnerPinned ? self.viewModelPresentationAgentBadge : self.currentAgentBadge
503+
}
504+
505+
nonisolated static func initialsBadge(for displayName: String) -> String {
506+
let words = displayName
438507
.split(whereSeparator: { $0.isWhitespace || $0 == "-" || $0 == "_" })
439508
.prefix(2)
440509
let initials = words.compactMap(\.first).map(String.init).joined()

‎apps/ios/Sources/Info.plist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<key>NSLocationWhenInUseUsageDescription</key>
6868
<string>OpenClaw uses your location when you allow location sharing.</string>
6969
<key>NSMicrophoneUsageDescription</key>
70-
<string>OpenClaw uses the microphone for realtime chat, voice wake, and push-to-talk.</string>
70+
<string>OpenClaw uses the microphone for realtime chat, voice wake, push-to-talk, and voice notes.</string>
7171
<key>NSMotionUsageDescription</key>
7272
<string>OpenClaw may use motion data to support device-aware interactions and automations.</string>
7373
<key>NSPhotoLibraryUsageDescription</key>

‎apps/ios/Sources/Model/NodeAppModel.swift‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ final class NodeAppModel {
312312
self.operatorGateway
313313
}
314314

315+
var isTalkCaptureActive: Bool {
316+
// PTT owns its Voice Wake lease before permission and audio setup.
317+
// Count that pending interval so Chat cannot race another mic owner.
318+
self.talkMode.isEnabled || self.talkMode.isPushToTalkActive || self.pttVoiceWakeLeaseCount > 0
319+
}
320+
315321
var localChatFixture: LocalChatFixture? {
316322
if self.isScreenshotFixtureModeEnabled { return .appScreenshots }
317323
if self.isAppleReviewDemoModeEnabled { return .appleReviewDemo }
@@ -518,6 +524,9 @@ final class NodeAppModel {
518524
self.watchMessagingService = watchMessagingService
519525
self.talkMode = talkMode
520526
self.voiceNoteRecorder = voiceNoteRecorder
527+
self.voiceNoteRecorder.setCaptureAdmissionHandler { [weak self] in
528+
self?.isTalkCaptureActive == false
529+
}
521530
self.apnsDeviceTokenHex = UserDefaults.standard.string(forKey: Self.apnsDeviceTokenUserDefaultsKey)
522531
restorePersistedWatchExecApprovalBridgeState()
523532
GatewayDiagnostics.bootstrap()
@@ -700,6 +709,11 @@ final class NodeAppModel {
700709
self.backgroundedAt = Date()
701710
self.reconnectAfterBackgroundArmed = true
702711
self.beginBackgroundConnectionGracePeriod()
712+
if self.voiceNoteRecorder.isRecording || self.voiceNoteRecorder.isRequestingPermission {
713+
// Cancel first: releasing the voice-note suppression reason can
714+
// schedule Voice Wake, which the background suspension must catch.
715+
self.voiceNoteRecorder.cancel()
716+
}
703717
// Release voice wake mic in background.
704718
self.backgroundVoiceWakeSuspended = self.voiceWake.suspendForExternalAudioCapture()
705719
let shouldKeepTalkActive = keepTalkActive && self.talkMode.isEnabled
@@ -1982,21 +1996,8 @@ final class NodeAppModel {
19821996
}
19831997

19841998
private func handleTalkInvoke(_ req: BridgeInvokeRequest) async throws -> BridgeInvokeResponse {
1985-
if req.command == OpenClawTalkCommand.pttOnce.rawValue ||
1986-
req.command == OpenClawTalkCommand.pttStart.rawValue
1987-
{
1988-
// Composer recording and PTT use separate AVAudio stacks. Refuse the
1989-
// second owner before it can reconfigure the shared audio session.
1990-
guard !self.voiceNoteRecorder.isRecording,
1991-
!self.voiceNoteRecorder.isRequestingPermission
1992-
else {
1993-
throw NSError(domain: "TalkMode", code: 8, userInfo: [
1994-
NSLocalizedDescriptionKey: "Voice note recording is active",
1995-
])
1996-
}
1997-
}
1998-
19991999
if req.command == OpenClawTalkCommand.pttOnce.rawValue {
2000+
try self.rejectTalkCaptureWhileVoiceNoteActive()
20002001
self.acquirePttVoiceWakeLease()
20012002
defer { self.releasePttVoiceWakeLease() }
20022003
let payload = try await talkMode.runPushToTalkOnce()
@@ -2009,6 +2010,7 @@ final class NodeAppModel {
20092010

20102011
switch req.command {
20112012
case OpenClawTalkCommand.pttStart.rawValue:
2013+
try self.rejectTalkCaptureWhileVoiceNoteActive()
20122014
let acquiredLease = !self.pttSessionOwnsVoiceWakeLease
20132015
if acquiredLease {
20142016
self.acquirePttVoiceWakeLease()
@@ -2050,6 +2052,15 @@ final class NodeAppModel {
20502052
}
20512053
}
20522054

2055+
private func rejectTalkCaptureWhileVoiceNoteActive() throws {
2056+
// Remote PTT bypasses the Chat Talk toggle. Preserve the user's draft;
2057+
// Talk must not reconfigure AVAudioSession while its recorder owns it.
2058+
guard self.voiceNoteRecorder.isRecording || self.voiceNoteRecorder.isRequestingPermission else { return }
2059+
throw NSError(domain: "TalkMode", code: 8, userInfo: [
2060+
NSLocalizedDescriptionKey: "Finish or cancel the active voice note before starting push-to-talk.",
2061+
])
2062+
}
2063+
20532064
private func acquirePttVoiceWakeLease() {
20542065
if self.pttVoiceWakeLeaseCount == 0 {
20552066
self.pttVoiceWakeWasSuspended = self.voiceWake.suspendForExternalAudioCapture()

‎apps/ios/Sources/sv.lproj/InfoPlist.strings‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"NSContactsUsageDescription" = "OpenClaw använder dina kontakter så att du kan söka efter och hänvisa till personer när du använder assistenten.";
88
"NSLocationWhenInUseUsageDescription" = "OpenClaw använder din plats när du tillåter platsdelning.";
99
"NSLocationAlwaysAndWhenInUseUsageDescription" = "OpenClaw kan dela din plats i bakgrunden när du aktiverar Alltid.";
10-
"NSMicrophoneUsageDescription" = "OpenClaw använder mikrofonen för realtidschatt, röstaktivering och tryck-och-prata.";
10+
"NSMicrophoneUsageDescription" = "OpenClaw använder mikrofonen för realtidschatt, röstaktivering, tryck-och-prata och röstmeddelanden.";
1111
"NSMotionUsageDescription" = "OpenClaw kan använda rörelsedata för att stödja enhetsmedvetna interaktioner och automatiseringar.";
1212
"NSPhotoLibraryUsageDescription" = "OpenClaw låter din assistent läsa bilder som du tillåter och låter dig välja bilder att dela.";
1313
"NSRemindersFullAccessUsageDescription" = "OpenClaw använder dina påminnelser för att lista, lägga till och slutföra uppgifter när du aktiverar åtkomst till påminnelser.";

‎apps/ios/Tests/GatewayStatusBuilderTests.swift‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import OpenClawKit
22
import Testing
33
@testable import OpenClaw
44

5-
@Suite struct GatewayStatusBuilderTests {
6-
@Test func pausedProblemKeepsErrorStatus() {
5+
struct GatewayStatusBuilderTests {
6+
@Test func `paused problem keeps error status`() {
77
let state = GatewayStatusBuilder.build(
88
gatewayServerName: nil,
99
lastGatewayProblem: GatewayConnectionProblem(
@@ -19,7 +19,7 @@ import Testing
1919
#expect(state == .error)
2020
}
2121

22-
@Test func transientProblemAllowsConnectingStatus() {
22+
@Test func `transient problem allows connecting status`() {
2323
let state = GatewayStatusBuilder.build(
2424
gatewayServerName: nil,
2525
lastGatewayProblem: GatewayConnectionProblem(
@@ -34,7 +34,7 @@ import Testing
3434
#expect(state == .connecting)
3535
}
3636

37-
@Test func chatGatewayPillLabelsMatchDisplayState() {
37+
@Test func `chat gateway pill labels match display state`() {
3838
#expect(ChatProTab.gatewayPillTitle(state: .disconnected, isGatewayUsable: false) == "Offline")
3939
#expect(ChatProTab.gatewayPillTitle(state: .connecting, isGatewayUsable: false) == "Connecting")
4040
#expect(ChatProTab.gatewayPillTitle(state: .error, isGatewayUsable: false) == "Attention")
@@ -47,6 +47,25 @@ import Testing
4747
#expect(ChatProTab.normalizedBadgeEmoji("?") == nil)
4848
#expect(ChatProTab.normalizedBadgeEmoji(" ") == nil)
4949
#expect(ChatProTab.normalizedBadgeEmoji(nil) == nil)
50+
#expect(ChatProTab.initialsBadge(for: "Agent Smith") == "AS")
51+
}
52+
53+
@Test func `pinned attachment displays its captured gateway owner`() {
54+
#expect(ChatProTab.presentationGatewayState(
55+
current: .connected,
56+
isAttachmentOwnerPinned: true,
57+
capturedOwnerID: "gateway-a",
58+
currentOwnerID: "gateway-b") == .disconnected)
59+
#expect(ChatProTab.presentationGatewayState(
60+
current: .connected,
61+
isAttachmentOwnerPinned: true,
62+
capturedOwnerID: "gateway-a",
63+
currentOwnerID: "gateway-a") == .connected)
64+
#expect(ChatProTab.presentationGatewayState(
65+
current: .connected,
66+
isAttachmentOwnerPinned: false,
67+
capturedOwnerID: "gateway-a",
68+
currentOwnerID: "gateway-b") == .connected)
5069
}
5170

5271
@Test func `chat starter prompts stay stable and actionable`() {

0 commit comments

Comments
 (0)