The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(chat): keep the draft and the failed prompt when a send fails
M3gA-Mindf95bfe7a753a
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsxindex b72094af5c..df61669c0d 100644--- a/app/src/features/conversations/Conversations.tsx+++ b/app/src/features/conversations/Conversations.tsx@@ -1306,6 +1306,13 @@ const Conversations = ({// A corrected retry must replace the already-persisted failed prompt;// appending it would leave both prompts in the transcript. The edit// operation truncates the failed tail and starts the corrected turn.+ await editMessage({+ threadId: sendingThreadId,+ messageId: previousFailedMessage.id,+ content: messageText,+ });+ // Only once the core accepted the edit: a failed edit leaves the+ // failed prompt in the core, so the transcript must keep it too.dispatch(truncateMessagesFrom({threadId: sendingThreadId,@@ -1313,11 +1320,6 @@ const Conversations = ({inclusive: true,}));- await editMessage({- threadId: sendingThreadId,- messageId: previousFailedMessage.id,- content: messageText,- });setInputValue('');setAttachments([]);attachmentsRef.current = [];@@ -1348,6 +1350,15 @@ const Conversations = ({}const msg = error instanceof Error ? error.message : String(error);setSendError(chatSendError('cloud_send_failed', msg));+ // assistant-ui already cleared the composer; restore the draft so a+ // failed persist or edit doesn't lose what the user typed.+ preserveSendErrorForRestoredDraftRef.current = true;+ failedAttachmentsByThreadRef.current.set(sendingThreadId, pendingAttachments);+ setInputValue(normalized);+ if (selectedThreadId === sendingThreadId) {+ attachmentsRef.current = pendingAttachments.slice();+ setAttachments(pendingAttachments);+ }pendingSendsRef.current.delete(sendingThreadId);removePendingSendingThread(sendingThreadId);return;@@ -1356,7 +1367,6 @@ const Conversations = ({setAttachments([]);attachmentsRef.current = [];failedAttachmentsByThreadRef.current.delete(sendingThreadId);- persistedFailedMessageByThreadRef.current.delete(sendingThreadId);setSendError(null);setAttachError(null);// Silence watchdog: fires only if 120s pass without ANY inference signal@@ -1390,6 +1400,10 @@ const Conversations = ({send_mode: 'standard',has_attachments: pendingAttachments.length > 0,});+ // Only a send the core accepted retires the persisted prompt; after a+ // failed send it stays, so a corrected retry replaces it (edit) instead+ // of appending a second copy.+ persistedFailedMessageByThreadRef.current.delete(sendingThreadId);// Backend accepted the send; lifecycle ('started' → 'streaming') now// owns the `isSending` UI lock. Release the pending guard so the next// user turn isn't blocked by a stale ref/state.diff --git a/app/src/pages/__tests__/Conversations.render.test.tsx b/app/src/pages/__tests__/Conversations.render.test.tsxindex 6050c0f43e..00b2448dce 100644--- a/app/src/pages/__tests__/Conversations.render.test.tsx+++ b/app/src/pages/__tests__/Conversations.render.test.tsx@@ -16,7 +16,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { SidebarSlotOutlet, SidebarSlotProvider } from '../../components/layout/shell/SidebarSlot';import { threadApi } from '../../services/api/threadApi';-import { chatCancel, chatRemoveQueueItem, chatSend } from '../../services/chatService';+import { chatCancel, chatRemoveQueueItem, chatSend, editMessage } from '../../services/chatService';import { CoreRpcError } from '../../services/coreRpcClient';import chatRuntimeReducer, {beginInferenceTurn,@@ -78,6 +78,7 @@ vi.mock('../../services/chatService', () => ({chatClearQueue: vi.fn().mockResolvedValue(0),chatRemoveQueueItem: vi.fn().mockResolvedValue(true),chatSend: vi.fn().mockResolvedValue(undefined),+ editMessage: vi.fn().mockResolvedValue(undefined),subscribeChatEvents: vi.fn(() => () => {}),useRustChat: vi.fn(() => true),}));@@ -2247,6 +2248,46 @@ describe('Conversations — smoke render (#1123 welcome-lock removal)', () => {});});+ it('restores the draft when saving the prompt locally fails', async () => {+ vi.mocked(threadApi.appendMessage).mockRejectedValueOnce(new Error('disk full'));+ const { textarea } = await renderSelectedConversation();+ await act(async () => {+ setComposerText(textarea, 'do not lose me');+ });+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'Send message' }));+ });+ await waitFor(() => expect(threadApi.appendMessage).toHaveBeenCalled());+ expect(chatSend).not.toHaveBeenCalled();+ await waitFor(() => expect(textarea).toHaveTextContent('do not lose me'));+ });++ it('keeps the failed prompt in the transcript when the corrected retry edit fails', async () => {+ vi.mocked(chatSend).mockRejectedValueOnce(new Error('emit failed'));+ const { store, textarea, thread } = await renderSelectedConversation();+ await act(async () => {+ setComposerText(textarea, 'first try');+ });+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'Send message' }));+ });+ await waitFor(() => expect(chatSend).toHaveBeenCalledTimes(1));+ const transcript = () =>+ (store!.getState().thread.messagesByThreadId[thread.id] ?? []).map(m => m.content);+ await waitFor(() => expect(transcript()).toContain('first try'));++ vi.mocked(editMessage).mockRejectedValueOnce(new Error('edit failed'));+ await act(async () => {+ setComposerText(textarea, 'second try');+ });+ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'Send message' }));+ });+ await waitFor(() => expect(editMessage).toHaveBeenCalledTimes(1));+ expect(transcript()).toContain('first try');+ await waitFor(() => expect(textarea).toHaveTextContent('second try'));+ });+it('sends with Enter when the composer is not composing text', async () => {const { textarea, thread } = await renderSelectedConversation();