Skip to content

The agent that grows with you

fix(desktop): say when a restored unsent message lost its attachments

Teknium2ec65bcc2d66
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts
index c51ea3544e5..687f54e53ce 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts
@@ -3,6 +3,7 @@ import { SLASH_COMMAND_RE } from '@hermes/shared'
import { type RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
import { isElementInHiddenPane } from '@/components/pane-shell/pane-visibility'
+import { translateNow } from '@/i18n'
import { sanitizeComposerInput } from '@/lib/composer-input-sanitize'
import { isTouchInteraction } from '@/lib/touch-interaction'
import { useStoreSelector } from '@/lib/use-session-slice'
@@ -31,6 +32,7 @@ import { isBrowsingHistory } from '@/store/composer-input-history'
import { adoptInterruptedSend, type InterruptedSendHandlers, restoreInterruptedSend } from '@/store/composer-outbox'
import { $composerPopout } from '@/store/composer-popout'
import { migrateQueuedPrompts } from '@/store/composer-queue'
+import { notify } from '@/store/notifications'
import { type ComposerStoreWriter, createComposerStoreWriter } from '../composer-store-writer'
import {
@@ -91,6 +93,20 @@ interface UseComposerDraftArgs {
sessionId: string | null | undefined
}
+// A send restored after its page died comes back as its words: attachment bytes do not outlive the
+// page. Say so, or the user takes the restored draft for the whole message and sends it without them.
+function noteAttachmentsNotRestored(retry: ComposerDraftRetry | undefined) {
+ if (retry?.attachmentIds.length) {
+ notify({
+ id: 'restored-draft-attachments',
+ kind: 'warning',
+ message: translateNow('promptNotices.restoredDraftAttachmentsDropped'),
+ // Raised while the chat opens: opening a chat clears the last chat's notices right after.
+ persistent: true
+ })
+ }
+}
+
/**
* The composer's draft engine — the detached source-of-truth spine. The live
* text lives in the contentEditable DOM + `draftRef`; React only sees coarse
@@ -690,13 +706,19 @@ export function useComposerDraft({
}
draftScopeRef.current = activeQueueSessionKey
- draftRetryRef.current = readDraftRetry(activeQueueSessionKey)
+ const storedRetry = readDraftRetry(activeQueueSessionKey)
const { attachments, text } = takeSessionDraft(activeQueueSessionKey)
savedDraftRef.current = savedDraft(text, attachments)
- draftRetryRef.current = loadedDraftRetry(draftRetryRef.current, text, attachments)
+ draftRetryRef.current = loadedDraftRetry(storedRetry, text, attachments)
loadIntoComposer(text, attachments, true)
+ if (draftRetryRef.current && draftRetryRef.current !== storedRetry) {
+ // Recorded text-only, so the notice is said once, not again on every return to this chat.
+ writeDraftRetry(activeQueueSessionKey, draftRetryRef.current)
+ noteAttachmentsNotRestored(storedRetry)
+ }
+
// Takes back a draft that is still exactly `retry`'s send under its identity.
const clearRestoredDraft = (retry: ComposerDraftRetry) => {
if (
@@ -724,6 +746,7 @@ export function useComposerDraft({
stashAt(activeQueueSessionKey, retry.text, [])
rememberDraftRetry(activeQueueSessionKey, { ...retry, attachmentIds: [] })
loadIntoComposer(retry.text, [])
+ noteAttachmentsNotRestored(retry)
return true
},
@@ -741,6 +764,12 @@ export function useComposerDraft({
rememberDraftRetry(activeQueueSessionKey, { ...adopted, attachmentIds: retryAttachmentIds(attachments) })
}
+ // The saved draft can already carry a text-only identity for these words; the journaled send
+ // still names the attachments the reload dropped.
+ if (adopted && !attachments.length) {
+ noteAttachmentsNotRestored(adopted)
+ }
+
if (!text.trim() && attachments.length === 0) {
// A send its page never finished (the window closed or reloaded mid-send) is this draft.
void restoreInterruptedSend(activeQueueSessionKey, interruptedSend)
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx
index 7554f2a920e..6b255e2bf4c 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx
@@ -143,6 +143,11 @@ const outboxKeys = () =>
key.startsWith('hermes:composer-outbox:')
)
+// The notice that a restored send came back without its attachments (this page's notification store).
+const attachmentsNotice = async () =>
+ (await import('@/store/notifications')).$notifications.get().find(notice => notice.id === 'restored-draft-attachments')
+ ?.message
+
const saveDraft = (text: string) =>
window.localStorage.setItem('hermes:composer-drafts:v3', JSON.stringify({ 'stored-B': text }))
@@ -171,6 +176,7 @@ it('a message sent right before the window closes is never lost and never sent t
await openPage(relaunched)
await act(async () => {})
expect(handles.editor()).toBe('')
+ expect(await attachmentsNotice()).toBeUndefined()
closeWindow()
// Enter, then the window closes before the send chain reaches prompt.submit.
@@ -242,6 +248,7 @@ it('an interrupted send with attachments comes back once, under its id, even whe
const offered = vi.fn<ChatBarProps['onSubmit']>(async () => true)
await openPage(offered)
await waitFor(() => expect(handles.editor()).toBe('offered words'))
+ expect(await attachmentsNotice()).toBe("Attachments from your unsent message weren't restored. Attach them again before you send it.")
await act(async () => handles.submitDraft())
expect(offered.mock.calls[0][1]?.submission_id).toBe(offeredId)
closeWindow()
@@ -253,6 +260,7 @@ it('an interrupted send with attachments comes back once, under its id, even whe
const reopened = vi.fn<ChatBarProps['onSubmit']>(async () => true)
await openPage(reopened)
expect(handles.editor()).toBe('saved words')
+ expect(await attachmentsNotice()).toBeTruthy()
await act(async () => handles.submitDraft())
expect(reopened.mock.calls[0][1]?.submission_id).toBe(savedId)
closeWindow()
@@ -283,6 +291,7 @@ it('an interrupted send with attachments comes back once, under its id, even whe
const retried = vi.fn<ChatBarProps['onSubmit']>(async () => true)
await openPage(retried)
expect(handles.editor()).toBe('unknown words')
+ expect(await attachmentsNotice()).toBeTruthy()
await act(async () => handles.submitDraft())
expect(retried.mock.calls[0][1]?.submission_id).toBe(timedOut.mock.calls[0][1]?.submission_id)
})
diff --git a/apps/desktop/src/i18n/ar_boot.ts b/apps/desktop/src/i18n/ar_boot.ts
index dd7a55c2be0..1b2a602ba5c 100644
--- a/apps/desktop/src/i18n/ar_boot.ts
+++ b/apps/desktop/src/i18n/ar_boot.ts
@@ -78,6 +78,7 @@ export const arBoot = {
promptNotices: {
legacySendUnconfirmed:
'تعذّر على هذا الخادم تأكيد الإرسال السابق لهذه الرسالة، لذا ربما تم تنفيذها بالفعل. راجع المحادثة قبل إرسالها مرة أخرى.',
+ restoredDraftAttachmentsDropped: 'لم تتم استعادة مرفقات رسالتك غير المرسلة. أرفقها مرة أخرى قبل إرسالها.',
mcpReloadDeferred:
'هذه المحادثة مشغولة: يُطبَّق تغيير MCP بعد انتهاء دورها وإعادة تحميل MCP مجددًا، أو عند إعادة فتح المحادثة',
mcpReloadUnavailable: servers => `تعذّر الاتصال: ${servers}`,
diff --git a/apps/desktop/src/i18n/de_notices.ts b/apps/desktop/src/i18n/de_notices.ts
index 0552e42fccd..924f1657540 100644
--- a/apps/desktop/src/i18n/de_notices.ts
+++ b/apps/desktop/src/i18n/de_notices.ts
@@ -21,6 +21,8 @@ export const deNotices = {
promptNotices: {
legacySendUnconfirmed:
'Dieser Server konnte das frühere Senden dieser Nachricht nicht bestätigen; sie wurde möglicherweise bereits ausgeführt. Prüfe die Unterhaltung, bevor du sie erneut sendest.',
+ restoredDraftAttachmentsDropped:
+ 'Anhänge aus deiner nicht gesendeten Nachricht wurden nicht wiederhergestellt. Füge sie erneut hinzu, bevor du sie sendest.',
mcpReloadDeferred:
'Dieser Chat ist beschäftigt: Die MCP-Änderung gilt, sobald sein Durchlauf endet und MCP erneut geladen wird, oder wenn du den Chat wieder öffnest',
mcpReloadUnavailable: servers => `Keine Verbindung: ${servers}`,
diff --git a/apps/desktop/src/i18n/en_notices.ts b/apps/desktop/src/i18n/en_notices.ts
index 34d36eb096d..3a3fca6491b 100644
--- a/apps/desktop/src/i18n/en_notices.ts
+++ b/apps/desktop/src/i18n/en_notices.ts
@@ -21,6 +21,8 @@ export const enNotices = {
promptNotices: {
legacySendUnconfirmed:
'This server could not confirm the earlier send of this message, so it may already have run. Check the conversation before sending it again.',
+ restoredDraftAttachmentsDropped:
+ "Attachments from your unsent message weren't restored. Attach them again before you send it.",
mcpReloadDeferred:
'This chat is busy: the MCP change applies once its turn finishes and MCP reloads again, or when you reopen the chat',
mcpReloadUnavailable: servers => `Did not connect: ${servers}`,
diff --git a/apps/desktop/src/i18n/es_notices.ts b/apps/desktop/src/i18n/es_notices.ts
index 6d5b7ccd571..9cf60a08845 100644
--- a/apps/desktop/src/i18n/es_notices.ts
+++ b/apps/desktop/src/i18n/es_notices.ts
@@ -21,6 +21,8 @@ export const esNotices = {
promptNotices: {
legacySendUnconfirmed:
'Este servidor no pudo confirmar el envío anterior de este mensaje, así que es posible que ya se haya ejecutado. Revisa la conversación antes de volver a enviarlo.',
+ restoredDraftAttachmentsDropped:
+ 'Los adjuntos de tu mensaje no enviado no se restauraron. Vuelve a adjuntarlos antes de enviarlo.',
mcpReloadDeferred:
'Este chat está ocupado: el cambio de MCP se aplica cuando termine su turno y MCP se recargue de nuevo, o al volver a abrir el chat',
mcpReloadUnavailable: servers => `No se conectó: ${servers}`,
diff --git a/apps/desktop/src/i18n/fr_notices.ts b/apps/desktop/src/i18n/fr_notices.ts
index 82bc5bc4653..ac2b2ad99f2 100644
--- a/apps/desktop/src/i18n/fr_notices.ts
+++ b/apps/desktop/src/i18n/fr_notices.ts
@@ -21,6 +21,8 @@ export const frNotices = {
promptNotices: {
legacySendUnconfirmed:
"Ce serveur n'a pas pu confirmer l'envoi précédent de ce message ; il a peut-être déjà été exécuté. Vérifiez la conversation avant de le renvoyer.",
+ restoredDraftAttachmentsDropped:
+ "Les pièces jointes de votre message non envoyé n'ont pas été restaurées. Joignez-les à nouveau avant de l'envoyer.",
mcpReloadDeferred:
'Cette discussion est occupée : la modification MCP s’applique à la fin de son tour et au prochain rechargement MCP, ou à la réouverture de la discussion',
mcpReloadUnavailable: servers => `Connexion impossible : ${servers}`,
diff --git a/apps/desktop/src/i18n/ja_notices.ts b/apps/desktop/src/i18n/ja_notices.ts
index f07f677aff0..063df05645e 100644
--- a/apps/desktop/src/i18n/ja_notices.ts
+++ b/apps/desktop/src/i18n/ja_notices.ts
@@ -21,6 +21,8 @@ export const jaNotices = {
promptNotices: {
legacySendUnconfirmed:
'このサーバーはこのメッセージの前回の送信を確認できなかったため、すでに実行された可能性があります。再送信する前に会話を確認してください。',
+ restoredDraftAttachmentsDropped:
+ '未送信のメッセージの添付ファイルは復元されませんでした。送信する前にもう一度添付してください。',
mcpReloadDeferred:
'このチャットは処理中です。MCP の変更は現在のターンが終わって MCP を再読み込みしたとき、またはチャットを開き直したときに反映されます',
mcpReloadUnavailable: servers => `接続できませんでした: ${servers}`,
diff --git a/apps/desktop/src/i18n/ru_notices.ts b/apps/desktop/src/i18n/ru_notices.ts
index 2f16980065a..c4c61b5c3fa 100644
--- a/apps/desktop/src/i18n/ru_notices.ts
+++ b/apps/desktop/src/i18n/ru_notices.ts
@@ -21,6 +21,8 @@ export const ruNotices = {
promptNotices: {
legacySendUnconfirmed:
'Этот сервер не смог подтвердить предыдущую отправку этого сообщения, поэтому оно, возможно, уже выполнено. Проверьте беседу, прежде чем отправлять его снова.',
+ restoredDraftAttachmentsDropped:
+ 'Вложения из неотправленного сообщения не восстановлены. Прикрепите их снова, прежде чем отправлять его.',
mcpReloadDeferred:
'Чат занят: изменение MCP применится, когда завершится текущий ход и MCP будет перезагружен снова, или при повторном открытии чата',
mcpReloadUnavailable: servers => `Не удалось подключиться: ${servers}`,
diff --git a/apps/desktop/src/i18n/types_notices.ts b/apps/desktop/src/i18n/types_notices.ts
index 6b256efa966..13516ea2969 100644
--- a/apps/desktop/src/i18n/types_notices.ts
+++ b/apps/desktop/src/i18n/types_notices.ts
@@ -15,6 +15,8 @@ export interface NoticeTranslations {
promptNotices: {
/** An explicit retry of a send whose identityless (legacy) acknowledgement was lost. */
legacySendUnconfirmed: string
+ /** An interrupted send restored as a draft: its attachments did not outlive the page. */
+ restoredDraftAttachmentsDropped: string
/** reload.mcp left the chat's servers as they were: a turn was running or waiting. */
mcpReloadDeferred: string
/** A reloaded MCP server the chat does not run (no_mcp, an explicit pick, a platform allowlist). */
diff --git a/apps/desktop/src/i18n/zh-hant_boot.ts b/apps/desktop/src/i18n/zh-hant_boot.ts
index 61fdcc596d6..f86989acbd7 100644
--- a/apps/desktop/src/i18n/zh-hant_boot.ts
+++ b/apps/desktop/src/i18n/zh-hant_boot.ts
@@ -80,6 +80,7 @@ export const zhHantBoot = {
},
promptNotices: {
legacySendUnconfirmed: '此伺服器無法確認這則訊息先前的傳送,它可能已經執行過。再次傳送前請先查看對話。',
+ restoredDraftAttachmentsDropped: '未傳送訊息中的附件沒有還原。傳送前請重新附加。',
mcpReloadDeferred: '此對話正忙:MCP 變更會在目前輪次結束並再次重新載入 MCP 後生效,或在重新開啟對話時生效',
mcpReloadUnavailable: servers => `未能連線:${servers}`,
compactedTurnUnavailable: '這則訊息在壓縮對話時已被摘要,無法再還原或編輯。',
diff --git a/apps/desktop/src/i18n/zh_notices.ts b/apps/desktop/src/i18n/zh_notices.ts
index c4c99e27ec7..8b3594d8669 100644
--- a/apps/desktop/src/i18n/zh_notices.ts
+++ b/apps/desktop/src/i18n/zh_notices.ts
@@ -19,6 +19,7 @@ export const zhNotices = {
},
promptNotices: {
legacySendUnconfirmed: '此服务器无法确认这条消息之前的发送,它可能已经运行过。再次发送前请先查看对话。',
+ restoredDraftAttachmentsDropped: '未发送消息中的附件没有恢复。发送前请重新添加。',
mcpReloadDeferred: '此对话正忙:MCP 更改将在当前轮次结束并再次重新加载 MCP 后生效,或在重新打开对话时生效',
mcpReloadUnavailable: servers => `未能连接:${servers}`,
compactedTurnUnavailable: '这条消息在压缩对话时已被概括,无法再恢复或编辑。',
diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.json
index 81dd15a91a9..3244a5fe5ab 100644
--- a/locales/_keys.desktop.json
+++ b/locales/_keys.desktop.json
@@ -2598,6 +2598,7 @@
"promptNotices.legacySendUnconfirmed",
"promptNotices.mcpReloadDeferred",
"promptNotices.mcpReloadUnavailable",
+ "promptNotices.restoredDraftAttachmentsDropped",
"promptNotices.sessionCommands.busy",
"promptNotices.sessionCommands.busyCompressing",
"promptNotices.sessionCommands.countOne",