The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): an unconfirmed queued-row edit keeps its identity and retries it
unsupportedpastelsf36b073fe1f4
diff --git a/apps/desktop/src/app/chat/composer/discard-lost-prompt.ts b/apps/desktop/src/app/chat/composer/discard-lost-prompt.tsindex b88fab2e661..2084934394e 100644--- a/apps/desktop/src/app/chat/composer/discard-lost-prompt.ts+++ b/apps/desktop/src/app/chat/composer/discard-lost-prompt.ts@@ -48,18 +48,20 @@ export async function steerQueuedPrompt(}/** Replace a server-queued admission with edited text: the authority cancels it and admits the- * edit as a new admission at the back of the FIFO, in one write. */+ * edit as a new admission at the back of the FIFO, in one write. `submissionId` is the edit's+ * identity: a retry of an unconfirmed save reuses it, and the owner replays a committed one. */export async function replaceQueuedPrompt(sessionId: string | null | undefined,queueSessionKey: string,admissionId: string,text: string,+ submissionId: string,request: GatewayRequest): Promise<unknown> {return requestForOwnedSession(queueSessionKey, request, 'prompt.replace_queued', {session_id: sessionId ?? queueSessionKey,admission_id: admissionId,- submission_id: crypto.randomUUID(),+ submission_id: submissionId,text})}diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsxindex 324fa415731..52a543154a6 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx@@ -51,7 +51,7 @@ function renderQueueHook(draft?: stringonCancel?: () => voidonSteer?: ChatBarProps['onSteer']- replaceServerQueued?: (admissionId: string, text: string) => Promise<unknown>+ replaceServerQueued?: (admissionId: string, text: string, submissionId: string) => Promise<unknown>} = {}) {const onSubmit = vi.fn<ChatBarProps['onSubmit']>(async () => true)@@ -571,7 +571,7 @@ describe('useComposerQueue scope', () => {expect(hook.result.current.exitQueuedEdit('save')).toBe(true)})- expect(replaceServerQueued).toHaveBeenCalledWith('adm-1', 'new words')+ expect(replaceServerQueued).toHaveBeenCalledWith('adm-1', 'new words', expect.any(String))expect(getQueuedPrompts(SESSION_KEY).map(entry => entry.text)).toEqual(['old words'])// The pre-edit draft comes back once the owner accepted the replacement.await waitFor(() => expect(draftRef.current).toBe('my draft'))@@ -585,7 +585,7 @@ describe('useComposerQueue scope', () => {clearNotifications()const replaceServerQueued = vi.fn(async () => {- throw new Error('admission_started')+ throw Object.assign(new Error('admission_started'), { data: { reason: 'admission_started' } })})const { draftRef, hook } = renderQueueHook({ busy: true, draft: 'my draft', replaceServerQueued })@@ -626,6 +626,73 @@ describe('useComposerQueue scope', () => {expect(draftRef.current).toBe('typed after save\n\nmy draft')})+ // Review: a reply lost in transport leaves the outcome unknown (the owner may have committed the+ // replacement). The edit stays open under the same identity, so Save retries prompt.replace_queued+ // with it (the owner replays a committed one) instead of turning the text into a fresh send.+ it('an unconfirmed Save keeps the edit open and retries under the same identity', async () => {+ reconcilePendingSubmissions(SESSION_KEY, [+ { admission_id: 'adm-1', status: 'queued', user: 'old words', controls: ['steer', 'replace'] }+ ])+ clearNotifications()+ const replies = [deferred(), deferred(), deferred()]+ const replaceServerQueued = vi.fn((_admissionId: string, _text: string, _submissionId: string) =>+ replies[replaceServerQueued.mock.calls.length - 1]!.promise)+ const { draftRef, hook } = renderQueueHook({ busy: true, draft: 'my draft', replaceServerQueued })++ act(() => hook.result.current.beginQueuedEdit(getQueuedPrompts(SESSION_KEY)[0]!))+ draftRef.current = 'new words'+ act(() => {+ hook.result.current.exitQueuedEdit('save')+ })+ await act(async () => replies[0]!.reject(new Error('Hermes gateway is not connected')))++ expect(hook.result.current.queueEdit?.entryId).toBe('adm-1')+ expect(draftRef.current).toBe('new words')+ expect($notifications.get().some(n => n.kind === 'warning')).toBe(true)++ // The replacement committed: the owner's snapshot lists it, and the old row is gone. The edit+ // stays open (no plain draft a later Enter would send again).+ act(() =>+ reconcilePendingSubmissions(SESSION_KEY, [{ admission_id: 'adm-2', status: 'queued', user: 'new words' }])+ )+ expect(hook.result.current.queueEdit?.entryId).toBe('adm-1')++ act(() => {+ expect(hook.result.current.exitQueuedEdit('save')).toBe(true)+ })+ const [first, second] = replaceServerQueued.mock.calls+ expect(second).toEqual(['adm-1', 'new words', first![2]])+ await act(async () => replies[1]!.resolve({ admission_id: 'adm-2' }))++ expect(hook.result.current.queueEdit).toBeNull()+ expect(draftRef.current).toBe('my draft')+ })++ it('a changed edit after an unconfirmed Save is a new identity', async () => {+ reconcilePendingSubmissions(SESSION_KEY, [+ { admission_id: 'adm-1', status: 'queued', user: 'old words', controls: ['steer', 'replace'] }+ ])+ const replaceServerQueued = vi.fn(async (_admissionId: string, _text: string, _submissionId: string) => {+ throw new Error('socket closed')+ })+ const { draftRef, hook } = renderQueueHook({ busy: true, replaceServerQueued })++ act(() => hook.result.current.beginQueuedEdit(getQueuedPrompts(SESSION_KEY)[0]!))+ draftRef.current = 'new words'+ await act(async () => {+ hook.result.current.exitQueuedEdit('save')+ })+ draftRef.current = 'other words'+ await act(async () => {+ hook.result.current.exitQueuedEdit('save')+ })++ expect(replaceServerQueued).toHaveBeenCalledTimes(2)+ const [first, second] = replaceServerQueued.mock.calls+ expect(second![1]).toBe('other words')+ expect(second![2]).not.toBe(first![2])+ })+it('a Save reply for an edit that was cancelled and reopened leaves the reopened edit alone', async () => {reconcilePendingSubmissions(SESSION_KEY, [{ admission_id: 'adm-1', status: 'queued', user: 'old words', controls: ['steer', 'replace'] }diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.tsindex 80bf565688b..88de17bec64 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts@@ -87,13 +87,17 @@ interface UseComposerQueueArgs {queueSessionKey: ChatBarProps['queueSessionKey']/** Ask the owner to replace a server-queued admission with edited text (default: through the* active gateway, routed to the session's owner). */- replaceServerQueued?: (admissionId: string, text: string) => Promise<unknown>+ replaceServerQueued?: (admissionId: string, text: string, submissionId: string) => Promise<unknown>sessionId: string | null | undefined}/** Text kept in the composer, followed by the draft a queued-row edit interrupted (when it differs). */const withPreEditDraft = (text: string, draft: string) => (draft.trim() && draft !== text ? `${text}\n\n${draft}` : text)+/** The owner answered with a named refusal: nothing was replaced. Anything else (a lost reply, a+ * dropped connection) leaves the outcome unknown. */+const isOwnerRefusal = (error: unknown) => typeof (error as { data?: { reason?: unknown } } | null)?.data?.reason === 'string'+/*** The composer's queue engine — everything about queued turns: the per-session* queue store binding, in-place queued-prompt editing (begin/step/exit), the@@ -117,7 +121,7 @@ export function useComposerQueue({queueEditRef,queueSessionKey,sessionId,- replaceServerQueued = (admissionId, text) => {+ replaceServerQueued = (admissionId, text, submissionId) => {const gateway = activeGateway()return gateway@@ -126,6 +130,7 @@ export function useComposerQueue({activeQueueSessionKey ?? admissionId,admissionId,text,+ submissionId,gateway.request.bind(gateway)): Promise.reject(new Error('Gateway unavailable'))@@ -165,11 +170,15 @@ export function useComposerQueue({// The one save the owner is answering: the exact edit it was made in, its own token and the// composer text at Save. Its answer settles only that save and never overwrites newer text.const serverSaveRef = useRef<{ edit: QueueEditState; text: string; token: symbol } | null>(null)+ // A save whose answer was lost: the owner may have committed it. Until a known outcome the edit+ // stays open and a Save of the same text retries under this identity (the owner replays it).+ const unconfirmedRef = useRef<{ admissionId: string; edited: string; submissionId: string } | null>(null)// The owner refused the replacement or started the row: nothing typed is lost. The edit stays// in the composer as an unsent draft (followed by the draft it interrupted), with the reason.const keepServerEditAsDraft = (edit: QueueEditState, text: string) => {serverEditRef.current = null+ unconfirmedRef.current = nullsetQueueEditSnapshot(null)loadIntoComposer(withPreEditDraft(text, edit.draft), edit.attachments)notify({@@ -289,7 +298,8 @@ export function useComposerQueue({return false}- if (editingQueuedPrompt?.serverStatus) {+ // A server row's edit (its row may be gone while an unconfirmed save of it is retried).+ if (serverEditRef.current === queueEdit.entryId) {// The owner replaces the admission and its pending fanout repaints the card. Text only,// like the row it replaces: the owner serves `replace` only for text-only rows.if (next.length > 0 || !text.trim()) {@@ -297,34 +307,52 @@ export function useComposerQueue({}const edited = frozen.frozenTransport ?? frozen.text- const entryId = editingQueuedPrompt.id+ const entryId = queueEdit.entryIdif (serverSaveRef.current?.edit === queueEdit) {return true // its save is already with the owner}- if (edited !== editingQueuedPrompt.text) {+ if (edited !== editingQueuedPrompt?.text) {// The edit stays open until the owner answers: only an accepted replacement restores the- // pre-edit draft; a refusal (started, queue full, transport) keeps the edited text.+ // pre-edit draft; a refusal keeps the edited text; an unknown outcome keeps the edit open.const save = { edit: queueEdit, text, token: Symbol('queued-edit-save') }+ const retained = unconfirmedRef.current++ const submissionId =+ retained?.admissionId === entryId && retained.edited === edited ? retained.submissionId : crypto.randomUUID()+serverSaveRef.current = save- const settle = (accepted: boolean) => {+ const settle = (outcome: 'accepted' | 'refused' | 'unconfirmed') => {if (serverSaveRef.current?.token !== save.token) {return}serverSaveRef.current = null-// Cancelled, or cancelled and reopened: that later edit is not this save's to settle.- if (queueEditRef.current !== save.edit) {+ const open = queueEditRef.current === save.edit+ // A known outcome spends the identity; an unknown one keeps it for the open edit's retry.+ unconfirmedRef.current = outcome === 'unconfirmed' && open ? { admissionId: entryId, edited, submissionId } : null++ if (!open) {+ return+ }++ if (outcome === 'unconfirmed') {+ notify({+ kind: 'warning',+ title: t.promptNotices.sessionCommands.queueEditUnconfirmedTitle,+ message: t.promptNotices.sessionCommands.queueEditUnconfirmed+ })+return}// What the composer holds now, typed after Save included.const current = draftRef.current- if (!accepted) {+ if (outcome === 'refused') {keepServerEditAsDraft(save.edit, current)return@@ -339,9 +367,9 @@ export function useComposerQueue({focusInput()}- replaceServerQueued(entryId, edited).then(- () => settle(true),- () => settle(false)+ replaceServerQueued(entryId, edited, submissionId).then(+ () => settle('accepted'),+ error => settle(isOwnerRefusal(error) ? 'refused' : 'unconfirmed'))triggerHaptic('success')@@ -364,6 +392,7 @@ export function useComposerQueue({}serverEditRef.current = null+ unconfirmedRef.current = nullsetQueueEditSnapshot(null)loadIntoComposer(queueEdit.draft, queueEdit.attachments)focusInput()@@ -756,8 +785,9 @@ export function useComposerQueue({return}- if (serverSaveRef.current?.edit === queueEdit) {- return // our own replacement retired it: the owner's answer settles the edit+ // Our own replacement may have retired it: the owner's answer (or a retried save) settles it.+ if (serverSaveRef.current?.edit === queueEdit || unconfirmedRef.current?.admissionId === queueEdit.entryId) {+ return}if (serverEditRef.current === queueEdit.entryId) {diff --git a/apps/desktop/src/i18n/ar_session_commands.ts b/apps/desktop/src/i18n/ar_session_commands.tsindex b4354407538..abd05f272b1 100644--- a/apps/desktop/src/i18n/ar_session_commands.ts+++ b/apps/desktop/src/i18n/ar_session_commands.ts@@ -15,5 +15,8 @@ export const arSessionCommands = {countOne: (count: string) => `${count} رسالة في قائمة الانتظار`,countOther: (count: string) => `${count} رسائل في قائمة الانتظار`,queueEditKeptTitle: 'لم تتغير الرسالة في قائمة الانتظار',- queueEditKept: 'بدأت أو رُفضت قبل حفظ تعديلك. نصك المعدّل موجود في مربع الكتابة.'+ queueEditKept: 'بدأت أو رُفضت قبل حفظ تعديلك. نصك المعدّل موجود في مربع الكتابة.',+ queueEditUnconfirmedTitle: 'لم يتم تأكيد التعديل',+ queueEditUnconfirmed:+ 'تعذّر على Hermes تأكيد تعديلك. احفظ مرة أخرى لإعادة محاولة التعديل نفسه؛ لن يُضاف إلى قائمة الانتظار مرتين.'}diff --git a/apps/desktop/src/i18n/de_session_commands.ts b/apps/desktop/src/i18n/de_session_commands.tsindex f37c41446b4..55f339fab1a 100644--- a/apps/desktop/src/i18n/de_session_commands.ts+++ b/apps/desktop/src/i18n/de_session_commands.ts@@ -17,5 +17,8 @@ export const deSessionCommands = {countOther: (count: string) => `${count} eingereihte Nachrichten`,queueEditKeptTitle: 'Eingereihte Nachricht nicht geändert',queueEditKept:- 'Sie wurde gestartet oder abgelehnt, bevor deine Änderung gespeichert war. Dein bearbeiteter Text steht im Eingabefeld.'+ 'Sie wurde gestartet oder abgelehnt, bevor deine Änderung gespeichert war. Dein bearbeiteter Text steht im Eingabefeld.',+ queueEditUnconfirmedTitle: 'Änderung nicht bestätigt',+ queueEditUnconfirmed:+ 'Hermes konnte deine Änderung nicht bestätigen. Speichere erneut, um dieselbe Änderung zu wiederholen; sie wird nie doppelt eingereiht.'}diff --git a/apps/desktop/src/i18n/en_session_commands.ts b/apps/desktop/src/i18n/en_session_commands.tsindex 34d6f495ab1..3f5483c579e 100644--- a/apps/desktop/src/i18n/en_session_commands.ts+++ b/apps/desktop/src/i18n/en_session_commands.ts@@ -17,5 +17,8 @@ export const enSessionCommands: SessionCommandNotices = {countOne: (count: string) => `${count} queued message`,countOther: (count: string) => `${count} queued messages`,queueEditKeptTitle: 'Queued message not changed',- queueEditKept: 'It started or was refused before your edit was saved. Your edited text is in the composer.'+ queueEditKept: 'It started or was refused before your edit was saved. Your edited text is in the composer.',+ queueEditUnconfirmedTitle: 'Edit not confirmed',+ queueEditUnconfirmed:+ 'Hermes could not confirm your edit. Save again to retry the same edit; it is never queued twice.'}diff --git a/apps/desktop/src/i18n/es_session_commands.ts b/apps/desktop/src/i18n/es_session_commands.tsindex 018b2e87c99..37206f01f68 100644--- a/apps/desktop/src/i18n/es_session_commands.ts+++ b/apps/desktop/src/i18n/es_session_commands.ts@@ -15,5 +15,8 @@ export const esSessionCommands = {countOne: (count: string) => `${count} mensaje en cola`,countOther: (count: string) => `${count} mensajes en cola`,queueEditKeptTitle: 'Mensaje en cola sin cambios',- queueEditKept: 'Empezó o fue rechazado antes de guardar tu edición. Tu texto editado está en el editor.'+ queueEditKept: 'Empezó o fue rechazado antes de guardar tu edición. Tu texto editado está en el editor.',+ queueEditUnconfirmedTitle: 'Edición sin confirmar',+ queueEditUnconfirmed:+ 'Hermes no pudo confirmar tu edición. Guarda de nuevo para reintentar la misma edición; nunca se pone en cola dos veces.'}diff --git a/apps/desktop/src/i18n/fr_session_commands.ts b/apps/desktop/src/i18n/fr_session_commands.tsindex dd55069d9de..bc7ecb038e2 100644--- a/apps/desktop/src/i18n/fr_session_commands.ts+++ b/apps/desktop/src/i18n/fr_session_commands.ts@@ -16,5 +16,8 @@ export const frSessionCommands = {countOther: (count: string) => `${count} messages en file`,queueEditKeptTitle: 'Message en file non modifié',queueEditKept:- "Il a démarré ou a été refusé avant l'enregistrement de ta modification. Ton texte modifié est dans la zone de saisie."+ "Il a démarré ou a été refusé avant l'enregistrement de ta modification. Ton texte modifié est dans la zone de saisie.",+ queueEditUnconfirmedTitle: 'Modification non confirmée',+ queueEditUnconfirmed:+ "Hermes n'a pas pu confirmer ta modification. Enregistre à nouveau pour réessayer la même modification ; elle n'est jamais mise en file deux fois."}diff --git a/apps/desktop/src/i18n/ja_session_commands.ts b/apps/desktop/src/i18n/ja_session_commands.tsindex 78eeb7c3780..df60b1c7cc1 100644--- a/apps/desktop/src/i18n/ja_session_commands.ts+++ b/apps/desktop/src/i18n/ja_session_commands.ts@@ -15,5 +15,7 @@ export const jaSessionCommands = {countOne: (count: string) => `キュー内のメッセージ ${count} 件`,countOther: (count: string) => `キュー内のメッセージ ${count} 件`,queueEditKeptTitle: 'キュー内のメッセージは変更されていません',- queueEditKept: '編集を保存する前に開始されたか、拒否されました。編集したテキストは入力欄にあります。'+ queueEditKept: '編集を保存する前に開始されたか、拒否されました。編集したテキストは入力欄にあります。',+ queueEditUnconfirmedTitle: '編集を確認できません',+ queueEditUnconfirmed: 'Hermes は編集を確認できませんでした。もう一度保存すると同じ編集を再試行します。二重にキューに入ることはありません。'}diff --git a/apps/desktop/src/i18n/ru_session_commands.ts b/apps/desktop/src/i18n/ru_session_commands.tsindex 5221934bd42..8904968b02a 100644--- a/apps/desktop/src/i18n/ru_session_commands.ts+++ b/apps/desktop/src/i18n/ru_session_commands.ts@@ -15,5 +15,8 @@ export const ruSessionCommands = {countOne: (count: string) => `сообщений в очереди: ${count}`,countOther: (count: string) => `сообщений в очереди: ${count}`,queueEditKeptTitle: 'Сообщение в очереди не изменено',- queueEditKept: 'Оно началось или было отклонено до сохранения правки. Отредактированный текст остался в поле ввода.'+ queueEditKept: 'Оно началось или было отклонено до сохранения правки. Отредактированный текст остался в поле ввода.',+ queueEditUnconfirmedTitle: 'Правка не подтверждена',+ queueEditUnconfirmed:+ 'Hermes не смог подтвердить правку. Сохраните ещё раз, чтобы повторить ту же правку; дважды в очередь она не попадёт.'}diff --git a/apps/desktop/src/i18n/types_notices.ts b/apps/desktop/src/i18n/types_notices.tsindex 93275f646fd..1e5e1bea001 100644--- a/apps/desktop/src/i18n/types_notices.ts+++ b/apps/desktop/src/i18n/types_notices.ts@@ -45,4 +45,7 @@ export interface SessionCommandNotices {/** A canonical queued row's edit the owner refused, or whose row started mid-edit. */queueEditKeptTitle: stringqueueEditKept: string+ /** A canonical queued row's save whose answer was lost: the edit stays open for a retry. */+ queueEditUnconfirmedTitle: string+ queueEditUnconfirmed: string}diff --git a/apps/desktop/src/i18n/zh-hant_session_commands.ts b/apps/desktop/src/i18n/zh-hant_session_commands.tsindex e1203c8e91a..ea0494314d7 100644--- a/apps/desktop/src/i18n/zh-hant_session_commands.ts+++ b/apps/desktop/src/i18n/zh-hant_session_commands.ts@@ -15,5 +15,7 @@ export const zhHantSessionCommands = {countOne: (count: string) => `${count} 則排隊訊息`,countOther: (count: string) => `${count} 則排隊訊息`,queueEditKeptTitle: '排隊訊息未變更',- queueEditKept: '在儲存編輯之前它已開始或被拒絕。編輯後的文字仍在輸入框中。'+ queueEditKept: '在儲存編輯之前它已開始或被拒絕。編輯後的文字仍在輸入框中。',+ queueEditUnconfirmedTitle: '編輯未確認',+ queueEditUnconfirmed: 'Hermes 無法確認你的編輯。再次儲存將重試同一編輯,不會重複排隊。'}diff --git a/apps/desktop/src/i18n/zh_session_commands.ts b/apps/desktop/src/i18n/zh_session_commands.tsindex 413511a0b40..27c60539613 100644--- a/apps/desktop/src/i18n/zh_session_commands.ts+++ b/apps/desktop/src/i18n/zh_session_commands.ts@@ -15,5 +15,7 @@ export const zhSessionCommands = {countOne: (count: string) => `${count} 条排队消息`,countOther: (count: string) => `${count} 条排队消息`,queueEditKeptTitle: '排队消息未更改',- queueEditKept: '在保存编辑之前它已开始或被拒绝。编辑后的文本仍在输入框中。'+ queueEditKept: '在保存编辑之前它已开始或被拒绝。编辑后的文本仍在输入框中。',+ queueEditUnconfirmedTitle: '编辑未确认',+ queueEditUnconfirmed: 'Hermes 无法确认你的编辑。再次保存将重试同一编辑,不会重复排队。'}diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.jsonindex 42803510f9c..187718f7adb 100644--- a/locales/_keys.desktop.json+++ b/locales/_keys.desktop.json@@ -2439,6 +2439,8 @@"promptNotices.sessionCommands.countOther","promptNotices.sessionCommands.queueEditKept","promptNotices.sessionCommands.queueEditKeptTitle",+ "promptNotices.sessionCommands.queueEditUnconfirmed",+ "promptNotices.sessionCommands.queueEditUnconfirmedTitle","promptNotices.sessionCommands.queueFailed","promptNotices.sessionCommands.queued","promptNotices.sessionCommands.retryNothing",