From d46fb03a0747d6c46b2355c74f1994d163aee58b Mon Sep 17 00:00:00 2001 From: Rune Olsen Date: Wed, 19 Aug 2026 12:52:21 +0200 Subject: [PATCH] Clear crash-recovery draft on save, not just on discard attemptSaveCurrentConversation() (Save/Save As) and confirmDiscardIfNeeded's no-unsaved-changes early return both left the on-disk draft_conversation.json untouched, so a stale snapshot from before the save lingered and triggered "Restore unsaved conversation?" on next launch even though everything had already been saved with no changes since. --- oAI/ViewModels/ChatViewModel.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/oAI/ViewModels/ChatViewModel.swift b/oAI/ViewModels/ChatViewModel.swift index 5f0420c..c09e892 100644 --- a/oAI/ViewModels/ChatViewModel.swift +++ b/oAI/ViewModels/ChatViewModel.swift @@ -756,6 +756,7 @@ Don't narrate future actions ("Let me...") - just use the tools. savedMessageCount = chatMessages.count notesEnabled = false notesFilename = nil + DraftRecoveryService.shared.clear() showSystemMessage("Saved as \"\(details.name)\"") Task { await GitSyncService.shared.autoSync() } } catch { @@ -2359,7 +2360,14 @@ Don't narrate future actions ("Let me...") - just use the tools. /// discards the crash-recovery draft and proceeds; Cancel calls `onCancel()` — the caller's /// original action (new chat / clear / switch / quit) must not happen. func confirmDiscardIfNeeded(then proceed: @escaping () -> Void, onCancel: @escaping () -> Void = {}) { - guard hasUnsavedChanges else { proceed(); return } + guard hasUnsavedChanges else { + // Nothing unsaved means any on-disk crash-recovery draft is now stale (either a + // save already covered it, or there was nothing worth mirroring) — clear it so the + // next launch doesn't offer to "restore" a conversation that's already saved intact. + DraftRecoveryService.shared.clear() + proceed() + return + } let alert = NSAlert() alert.alertStyle = .warning @@ -2401,6 +2409,7 @@ Don't narrate future actions ("Let me...") - just use the tools. id: id, name: name, messages: chatMessages, primaryModel: selectedModel?.id ) savedMessageCount = chatMessages.count + DraftRecoveryService.shared.clear() showSystemMessage("Saved \"\(name)\"") Task { await GitSyncService.shared.autoSync() } return true @@ -2421,6 +2430,7 @@ Don't narrate future actions ("Let me...") - just use the tools. savedMessageCount = chatMessages.count notesEnabled = false notesFilename = nil + DraftRecoveryService.shared.clear() showSystemMessage("Saved as \"\(details.name)\"") Task { await GitSyncService.shared.autoSync() } return true