The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): stop the queue-drain exhaustion banner from replaying after restart (#98015)
Hermes Agentaac12dfda54d
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 e8f749c1c4c..027aae1cd80 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@@ -9,6 +9,7 @@ import { resetBrowseState } from '@/store/composer-input-history'import {$parkedQueueSessions,$queuedPromptsBySession,+ clearQueuedPromptDrainFailures,enqueueQueuedPrompt,getQueuedPrompts,isSteerableEntry,@@ -287,6 +288,9 @@ export function useComposerQueue({// A manual send clears the auto-drain backoff so a stuck entry the user// taps gets a fresh attempt (and re-enables auto-retry on success).drainFailuresRef.current.delete(id)+ // Same for the persisted budget the background drain keeps on the+ // entry (#98015) — a user gesture is fresh intent, not a replay.+ clearQueuedPromptDrainFailures(activeQueueSessionKey, id)return runDrain(entries => entries.find(e => e.id === id))},diff --git a/apps/desktop/src/app/session/hooks/use-background-queue-drain.test.tsx b/apps/desktop/src/app/session/hooks/use-background-queue-drain.test.tsxindex fa37b7eeca1..0e458a0fc0e 100644--- a/apps/desktop/src/app/session/hooks/use-background-queue-drain.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-background-queue-drain.test.tsx@@ -8,8 +8,10 @@ import {$queuedPromptsBySession,enqueueQueuedPrompt,getQueuedPrompts,+ MAX_AUTO_DRAIN_ATTEMPTS,parkQueuedPrompts} from '@/store/composer-queue'+import { $notifications, clearNotifications } from '@/store/notifications'import { $sessions, setSessions, setSessionsLoading } from '@/store/session'import { clearAllSessionStates, publishSessionState } from '@/store/session-states'import type { SessionInfo } from '@/types/hermes'@@ -79,6 +81,7 @@ describe('useBackgroundQueueDrain', () => {$parkedQueueSessions.set({})$sessions.set([])setSessionsLoading(true)+ clearNotifications()clearAllSessionStates()})@@ -278,4 +281,101 @@ describe('useBackgroundQueueDrain', () => {await waitFor(() => expect(getQueuedPrompts('stored-session-a')).toHaveLength(0))})++ it('drops a gone session\'s queued prompt quietly at drain exhaustion instead of erroring (#98015)', async () => {+ vi.useFakeTimers()++ // The session list has settled and no row answers to the queued session:+ // the conversation is gone from this backend (reaped runtime whose stored+ // resume refuses — the post-restart shape the issue reports).+ setSessions([])+ const runtimeMap = { current: new Map<string, string>() }+ const submitText = vi.fn(async () => false)++ enqueueQueuedPrompt('stored-session-a', { text: 'never sends', attachments: [] })++ render(<Harness runtimeMap={runtimeMap} submitText={submitText} />)++ await act(async () => {+ await Promise.resolve()+ })++ for (let attempt = 1; attempt < MAX_AUTO_DRAIN_ATTEMPTS; attempt++) {+ await act(async () => {+ await vi.advanceTimersByTimeAsync(750)+ })+ }++ expect(submitText).toHaveBeenCalledTimes(MAX_AUTO_DRAIN_ATTEMPTS)++ // The entry is dropped and the notice is a quiet info, not the old+ // "message not sent" error banner.+ await act(async () => {+ await Promise.resolve()+ })+ expect(getQueuedPrompts('stored-session-a')).toHaveLength(0)+ const stuck = $notifications.get().find(n => n.id === 'composer-background-queue-stuck-stored-session-a')+ expect(stuck?.kind).toBe('info')+ })++ it('keeps the queued prompt for a session the loaded list still knows, with a quiet notice (#98015)', async () => {+ vi.useFakeTimers()++ setSessions([lineageSession({ id: 'stored-session-a' })])+ const runtimeMap = { current: new Map([['stored-session-a', 'rt-session-a']]) }+ const submitText = vi.fn(async () => false)++ enqueueQueuedPrompt('stored-session-a', { text: 'retry from the panel', attachments: [] })++ render(<Harness runtimeMap={runtimeMap} submitText={submitText} />)++ await act(async () => {+ await Promise.resolve()+ })++ for (let attempt = 1; attempt < MAX_AUTO_DRAIN_ATTEMPTS; attempt++) {+ await act(async () => {+ await vi.advanceTimersByTimeAsync(750)+ })+ }++ // The conversation exists — the entry survives for a manual send, and the+ // notice is downgraded from the error banner.+ expect(getQueuedPrompts('stored-session-a')).toHaveLength(1)+ const stuck = $notifications.get().find(n => n.id === 'composer-background-queue-stuck-stored-session-a')+ expect(stuck?.kind).toBe('info')+ })++ it('does not replay the retry ladder for a queue restored after prior exhaustion (#98015)', async () => {+ vi.useFakeTimers()++ // A queue restored from localStorage with the persisted drain budget+ // already spent: no attempts, no notice — the every-boot replay of four+ // rejections plus a banner is the reported symptom.+ const runtimeMap = { current: new Map<string, string>() }+ const submitText = vi.fn(async () => true)++ setSessions([lineageSession({ id: 'stored-session-a' })])+ $queuedPromptsBySession.set({+ 'stored-session-a': [+ {+ id: 'queued-restored',+ text: 'already exhausted in a previous process',+ attachments: [],+ queuedAt: 1,+ drainFailures: MAX_AUTO_DRAIN_ATTEMPTS+ }+ ]+ })++ render(<Harness runtimeMap={runtimeMap} submitText={submitText} />)++ await act(async () => {+ await vi.advanceTimersByTimeAsync(750 * 6)+ })++ expect(submitText).not.toHaveBeenCalled()+ expect(getQueuedPrompts('stored-session-a').map(e => e.id)).toEqual(['queued-restored'])+ expect($notifications.get()).toHaveLength(0)+ })})diff --git a/apps/desktop/src/app/session/hooks/use-background-queue-drain.ts b/apps/desktop/src/app/session/hooks/use-background-queue-drain.tsindex b67722eb677..11766a16565 100644--- a/apps/desktop/src/app/session/hooks/use-background-queue-drain.ts+++ b/apps/desktop/src/app/session/hooks/use-background-queue-drain.ts@@ -8,12 +8,19 @@ import {$queuedPromptsBySession,getQueuedPrompts,MAX_AUTO_DRAIN_ATTEMPTS,+ noteQueuedPromptDrainFailure,type QueuedPromptEntry,removeQueuedPrompt,shouldAutoDrain} from '@/store/composer-queue'import { notify } from '@/store/notifications'-import { $sessions, $sessionsLoading, idsShareLineage } from '@/store/session'+import {+ $sessions,+ $sessionsLoading,+ getSessionOwnerHint,+ idsShareLineage,+ sessionMatchesStoredId+} from '@/store/session'import { $workingSessionIds } from '@/store/session-states'import type { SubmitTextOptions } from './use-prompt-actions/utils'@@ -92,13 +99,48 @@ export function useBackgroundQueueDrain({drainingSessionIdsRef.current.add(sessionKey)const onFail = () => {- const failures = (drainFailuresRef.current.get(entry.id) ?? 0) + 1+ const failures = (drainFailuresRef.current.get(entry.id) ?? entry.drainFailures ?? 0) + 1drainFailuresRef.current.set(entry.id, failures)+ // Persist the budget with the queue: a restart must not replay four+ // more rejections (and the exhaustion notice) against a session that+ // is exactly as dead as it was when the process exited (#98015).+ noteQueuedPromptDrainFailure(sessionKey, entry.id)if (failures >= MAX_AUTO_DRAIN_ATTEMPTS) {+ // The session rejected every drain attempt. Discovery has settled+ // (the effect gates on it), so the loaded list plus owner hints are+ // authoritative: a session no row or hint answers to — by id or+ // lineage — is gone from this backend (deleted from another+ // surface, or its stored resume refuses permanently). Owner hints+ // count: a hidden bot chat never occupies the recents list, yet+ // its queue is exactly the one worth preserving. Its queued prompt+ // can never send; keep it and every future boot replays this+ // cycle for nothing. Drop it and say so quietly.+ const sessionKnown =+ $sessions.get().some(session => sessionMatchesStoredId(session, sessionKey)) ||+ getSessionOwnerHint(sessionKey) !== undefined++ if (!sessionKnown) {+ removeQueuedPrompt(sessionKey, entry.id)+ notify({+ id: `composer-background-queue-stuck-${sessionKey}`,+ kind: 'info',+ title: t.composer.queueDroppedTitle,+ message: t.composer.queueDroppedBody+ })++ return+ }++ // The conversation still exists — the runtime just would not come+ // back (backend restarting, resume refusing). Keep the entry: it+ // is real data the user can still send from the queue panel, and a+ // manual send clears the retry budget. Downgrade the notice from+ // the old error banner: "not sent, still queued, try again" is+ // accurate, "message not sent" as an ERROR read as data loss.notify({id: `composer-background-queue-stuck-${sessionKey}`,- kind: 'error',+ kind: 'info',title: t.composer.queueStuckTitle,message: t.composer.queueStuckBody})@@ -186,7 +228,7 @@ export function useBackgroundQueueDrain({const entry = entries[0]- if (!entry || (drainFailuresRef.current.get(entry.id) ?? 0) >= MAX_AUTO_DRAIN_ATTEMPTS) {+ if (!entry || (drainFailuresRef.current.get(entry.id) ?? entry.drainFailures ?? 0) >= MAX_AUTO_DRAIN_ATTEMPTS) {continue}diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.tsindex 632475c3f24..07d202375db 100644--- a/apps/desktop/src/i18n/ar.ts+++ b/apps/desktop/src/i18n/ar.ts@@ -2383,6 +2383,9 @@ export const ar = defineLocale({queueDelete: 'حذف من الطابور',queueStuckTitle: 'لم تُرسل الرسالة في قائمة الانتظار',queueStuckBody: 'ظل دور في قائمة الانتظار يفشل في الإرسال. ما زال في قائمة الانتظار — حاول إرساله مرة أخرى.',+ queueDroppedTitle: 'تم إسقاط عنصر قائمة الانتظار',+ queueDroppedBody:+ 'أُسقط هذا العنصر في الخلفية لأن جلسته تعذّر استئنافها بعد محاولات متكررة. بقية قائمة الانتظار لم تتأثر.',previewUnavailable: 'المعاينة غير متاحة',previewLabel: label => `معاينة ${label}`,couldNotPreview: label => `تعذرت معاينة ${label}`,diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.tsindex e2b54e08b31..79495c5e26b 100644--- a/apps/desktop/src/i18n/de.ts+++ b/apps/desktop/src/i18n/de.ts@@ -4278,6 +4278,9 @@ export const deOverrides = {queueStuckTitle: 'Eingereihte Nachricht nicht gesendet',queueStuckBody:'Ein eingereihter Turn konnte nicht gesendet werden. Er ist noch in der Warteschlange — versuchen Sie, ihn erneut zu senden.',+ queueDroppedTitle: 'Eingereihte Eingabe verworfen',+ queueDroppedBody:+ 'Dieser Hintergrund-Eintrag wurde verworfen, da seine Sitzung nach wiederholten Versuchen nicht fortgesetzt werden konnte. Die übrige Warteschlange ist unverändert.',previewUnavailable: 'Vorschau nicht verfügbar',previewLabel: label => `Vorschau ${label}`,couldNotPreview: label => `Vorschau von ${label} fehlgeschlagen`,diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex a4a03dcd5e0..2176df7746a 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -3889,6 +3889,9 @@ export const en: Translations = {queueResumeTip: 'Paused by Stop — resume sending the queued turns',queueStuckTitle: 'Queued message not sent',queueStuckBody: 'A queued turn kept failing to send. It is still in the queue — try sending it again.',+ queueDroppedTitle: 'Queued prompt dropped',+ queueDroppedBody:+ 'This background queue entry was dropped because its session could not be resumed after repeated attempts. Nothing else in the queue was affected.',previewUnavailable: 'Preview unavailable',previewLabel: label => `Preview ${label}`,couldNotPreview: label => `Could not preview ${label}`,diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.tsindex 349aabdf375..f8971e89e56 100644--- a/apps/desktop/src/i18n/es.ts+++ b/apps/desktop/src/i18n/es.ts@@ -4268,6 +4268,9 @@ export const esOverrides = {queueResumeTip: 'La cola se pausó al detener; reanuda el envío de los turnos en cola',queueStuckTitle: 'Mensaje en cola no enviado',queueStuckBody: 'Un turno en cola no llegó a enviarse. Sigue en la cola; vuelve a intentarlo.',+ queueDroppedTitle: 'Entrada en cola descartada',+ queueDroppedBody:+ 'Se descartó esta entrada en segundo plano porque su sesión no se pudo reanudar tras varios intentos. El resto de la cola no se ha visto afectado.',previewUnavailable: 'Vista previa no disponible',previewLabel: label => `Vista previa de ${label}`,couldNotPreview: label => `No se pudo previsualizar ${label}`,diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.tsindex d009fb270a0..a0c5eaf035c 100644--- a/apps/desktop/src/i18n/fr.ts+++ b/apps/desktop/src/i18n/fr.ts@@ -4288,6 +4288,9 @@ export const frOverrides = {queueStuckTitle: "Message en file d'attente non envoyé",queueStuckBody:"Un tour en file d'attente a continué à échouer lors de l'envoi. Il est toujours en file d'attente — essayez de l'envoyer à nouveau.",+ queueDroppedTitle: "Élément en file d'attente abandonné",+ queueDroppedBody:+ "Cette entrée d'arrière-plan a été abandonnée car sa session n'a pas pu être reprise après plusieurs tentatives. Le reste de la file d'attente est inchangé.",previewUnavailable: 'Aperçu indisponible',previewLabel: label => `Aperçu ${label}`,couldNotPreview: label => `Impossible d'apercevoir ${label}`,diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.tsindex ee31b6ee2a4..4b65c90c687 100644--- a/apps/desktop/src/i18n/ja.ts+++ b/apps/desktop/src/i18n/ja.ts@@ -2800,6 +2800,9 @@ export const ja = defineLocale({queueStuckTitle: 'キュー内のメッセージを送信できません',queueStuckBody:'キューに入れたターンの送信が繰り返し失敗しました。まだキューに残っています。もう一度送信してください。',+ queueDroppedTitle: 'キューのエントリを破棄しました',+ queueDroppedBody:+ 'このバックグラウンドのエントリは、セッションを繰り返し再開できなかったため破棄されました。キューの他のエントリには影響しません。',previewUnavailable: 'プレビューは利用できません',previewLabel: label => `${label} のプレビュー`,couldNotPreview: label => `${label} をプレビューできませんでした`,diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.tsindex 868fa3ae4cb..0693f142eac 100644--- a/apps/desktop/src/i18n/ru.ts+++ b/apps/desktop/src/i18n/ru.ts@@ -3003,6 +3003,9 @@ export const ru = defineLocale({queueStuckTitle: 'Сообщение из очереди не отправлено',queueStuckBody:'Ход из очереди несколько раз не удалось отправить. Он всё ещё в очереди — попробуйте отправить снова.',+ queueDroppedTitle: 'Элемент очереди отброшен',+ queueDroppedBody:+ 'Эта фоновая запись была отброшена: её сеанс не удалось возобновить после нескольких попыток. Остальная очередь не затронута.',previewUnavailable: 'Предпросмотр недоступен',previewLabel: label => `Предпросмотр ${label}`,couldNotPreview: label => `Не удалось предпросмотреть ${label}`,diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.tsindex 2d4ad68e9e5..ca87319adb8 100644--- a/apps/desktop/src/i18n/zh-hant.ts+++ b/apps/desktop/src/i18n/zh-hant.ts@@ -3013,6 +3013,8 @@ export const zhHant = defineLocale({queueResumeTip: '已被停止操作暫停 — 繼續傳送排隊的回合',queueStuckTitle: '佇列訊息未送出',queueStuckBody: '佇列中的對話多次傳送失敗。它仍在佇列中,請重試傳送。',+ queueDroppedTitle: '已捨棄佇列內容',+ queueDroppedBody: '該背景佇列項目因工作階段多次嘗試後仍無法恢復而遭捨棄。佇列中的其他內容不受影響。',previewUnavailable: '預覽不可用',previewLabel: label => `預覽 ${label}`,couldNotPreview: label => `無法預覽 ${label}`,diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex 2ebb2a1b4a0..23f64de9dbc 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -3673,6 +3673,8 @@ export const zh = defineLocale({queueResumeTip: '已被停止操作暂停 — 继续发送排队的回合',queueStuckTitle: '排队消息未发送',queueStuckBody: '排队的对话多次发送失败。它仍在队列中,请重试发送。',+ queueDroppedTitle: '已丢弃排队内容',+ queueDroppedBody: '该后台队列条目因会话多次尝试后仍无法恢复而被丢弃。队列中的其他内容不受影响。',previewUnavailable: '预览不可用',previewLabel: label => `预览 ${label}`,couldNotPreview: label => `无法预览 ${label}`,diff --git a/apps/desktop/src/store/composer-queue.ts b/apps/desktop/src/store/composer-queue.tsindex b83f1b4d305..d0a036a9cec 100644--- a/apps/desktop/src/store/composer-queue.ts+++ b/apps/desktop/src/store/composer-queue.ts@@ -21,6 +21,12 @@ export interface QueuedPromptEntry {/** A hidden note (a setup line for the model) parked while the turn ran. The panel* shows a neutral label and the drain submits it hidden again. */displayKind?: 'hidden'+ /** Consecutive auto-drain attempts that rejected this entry, persisted with+ * the queue so a restart does not replay the whole retry ladder (and its+ * exhaustion notice) for a session that is just as dead as before (#98015).+ * A user gesture — manual send, redirect, queueing a fresh prompt — clears+ * it, exactly like the composer's in-process counter. */+ drainFailures?: numberattachments: ComposerAttachment[]queuedAt: number}@@ -174,7 +180,13 @@ export const enqueueQueuedPrompt = (queuedAt: Date.now()}- writeSession(sid, [...queueFor(sid), entry])+ writeSession(+ sid,+ // Queueing a fresh prompt is fresh intent to keep the conversation+ // moving — lift the persisted drain-failure budget off the entries+ // already waiting there, exactly like the park (#98015).+ [...queueFor(sid).map(e => (e.drainFailures ? { ...e, drainFailures: undefined } : e)), entry]+ )// Queueing a new prompt is fresh intent to keep the conversation moving —// a park from an earlier Stop must not hold this (or the entries ahead of// it) back.@@ -230,6 +242,52 @@ export const removeQueuedPrompt = (return true}+/** Count one more rejected auto-drain attempt against a queued entry and+ * persist it with the queue (#98015). The in-process retry ladder stays+ * identical; only its budget survives restarts, so a session that is dead in+ * this process is not retried four more times on every future launch. */+export const noteQueuedPromptDrainFailure = (key: string | null | undefined, id: string): void => {+ const sid = sidOf(key)++ if (!sid) {+ return+ }++ const queue = queueFor(sid)++ if (!queue.some(e => e.id === id)) {+ return+ }++ writeSession(+ sid,+ queue.map(e => (e.id === id ? { ...e, drainFailures: (e.drainFailures ?? 0) + 1 } : e))+ )+}++/** Clear a queued entry's persisted drain-failure budget — the queue-panel+ * sibling of the composer's in-process counter reset. Called on the user+ * gestures that express fresh intent to send (manual send, redirect, and+ * implicitly by removal on success). */+export const clearQueuedPromptDrainFailures = (key: string | null | undefined, id: string): void => {+ const sid = sidOf(key)++ if (!sid) {+ return+ }++ const queue = queueFor(sid)++ if (!queue.some(e => e.id === id && e.drainFailures)) {+ return+ }++ writeSession(+ sid,+ queue.map(e => (e.id === id ? { ...e, drainFailures: undefined } : e))+ )+}+export const promoteQueuedPrompt = (key: string | null | undefined, id: string): boolean => {const sid = sidOf(key)