Skip to content

Commit ca60f03

Browse files
saltukalakusclaude
andcommitted
fix: gracefully degrade voice correction when agent connection is lost
Two bugs fixed: 1. recordingState stuck at .processing when no client is available: sendVoiceCorrectionRequest early-returned with voiceCorrectedText=rawTranscript but isVoiceCorrectionPending was never set true→false, so onChange never fired and the .processing UI (spinner hiding the input area) persisted forever. Fix: also reset recordingState = .idle in onChange(of: voiceCorrectedText), which fires in ALL code paths since voiceCorrectedText is always set. 2. Long hang when client exists but connection is lost (stale cachedClient): sendMessage triggered full auto-reconnect logic, keeping the user in .processing for up to ~30 s before eventually calling onComplete. Fix: check client.connectionState upfront in sendVoiceCorrectionRequest; if not .connected, fall back to raw transcript immediately without reconnect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9cc4846 commit ca60f03

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Aptove/ViewModels/ChatViewModel.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,10 @@ class ChatViewModel: ObservableObject {
518518
cachedClient = client
519519
}
520520

521-
guard let client = client else {
521+
// If there is no client, or the client is not currently connected,
522+
// degrade immediately to the raw transcript — do not attempt reconnect,
523+
// which would leave the user stuck in .processing for up to 30 s.
524+
guard let client, case .connected = client.connectionState else {
522525
voiceCorrectedText = rawTranscript
523526
return
524527
}

Aptove/Views/ChatView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ struct ChatView: View {
283283
messageText = text
284284
isInputFocused = true
285285
viewModel.voiceCorrectedText = nil
286+
// Always reset recording state when text is ready — handles both
287+
// successful AI correction and immediate fallback (no/lost connection).
288+
voiceViewModel.recordingState = .idle
286289
}
287290
}
288291
.onChange(of: viewModel.isVoiceCorrectionPending) { _, pending in

0 commit comments

Comments
 (0)