The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve accepted input and clarify persistent-work Quit
David Dudok de Witf8e234ed89dd
diff --git a/apps/desktop/electron/quit-guard.test.ts b/apps/desktop/electron/quit-guard.test.tsindex 8888f99b40f..b3459e39d43 100644--- a/apps/desktop/electron/quit-guard.test.ts+++ b/apps/desktop/electron/quit-guard.test.ts@@ -31,7 +31,10 @@ test('quitPromptFor stays out of the way when nothing is running', () => {})test('quitPromptFor stays out of the way during an update handoff', () => {- assert.equal(quitPromptFor({ count: 2, titles: ['Fix login'] }, true), null)+ const work = mergeActiveWork([normalizeActiveWork({ count: 2, titles: ['Fix login'] })])++ assert.ok(quitPromptFor(work, false))+ assert.equal(quitPromptFor(work, true), null)})test('quitPromptFor names the running chats', () => {@@ -58,5 +61,18 @@ test('quitPromptFor speaks singular for one chat', () => {assert.ok(prompt)assert.equal(prompt.message, 'Hermes is still working on 1 chat.')- assert.ok(prompt.detail.includes('mid-turn'))+})++test('active-work reports with unknown lifecycle keep a scoped confirmation, not a work-loss claim', () => {+ // The real IPC summary has no connection identity or Desktop-tool activity.+ // Neither named nor untitled work proves it is independent of the client.+ for (const titles of [[], ['Fix login']]) {+ const work = mergeActiveWork([normalizeActiveWork({ count: 1, titles })])+ const prompt = quitPromptFor(work, false)++ assert.ok(prompt)+ assert.match(prompt.detail, /[Rr]unning and queued work on a persistent gateway continues after Desktop quits/)+ assert.match(prompt.detail, /[Aa]ctivity that depends on this app or an older connection may be interrupted/)+ assert.doesNotMatch(prompt.detail, /work.*(?:lost|stops)|stops the agent|all work continues/i)+ }})diff --git a/apps/desktop/electron/quit-guard.ts b/apps/desktop/electron/quit-guard.tsindex e2bb40e59da..eb6628d6f38 100644--- a/apps/desktop/electron/quit-guard.ts+++ b/apps/desktop/electron/quit-guard.ts@@ -1,8 +1,7 @@-// Quitting with a turn in flight kills the backend mid-tool-call: the work is-// lost, and anything the agent had half-written to disk stays half-written.-// Renderers publish what they're running; the main process asks before it lets-// that go. The decision + copy live here (pure, testable) so main.ts only owns-// the IPC and the dialog call.+// Persistent gateways own their work independently of Desktop. Renderer reports+// do not identify connections or client-dependent activity, so a busy report+// still needs a scoped confirmation, not a claim that quitting loses all work.+// The decision + copy live here so main.ts only owns the IPC and dialog call.const MAX_LISTED = 4@@ -82,7 +81,8 @@ export function quitPromptFor(work: ActiveWork, quittingForHandoff: boolean): nudetail: [lines.join('\n'),lines.length > 0 ? '' : null,- 'Quitting stops the agent mid-turn. Any work it has not finished writing is lost.'+ 'Running and queued work on a persistent gateway continues after Desktop quits. ' ++ 'Activity that depends on this app or an older connection may be interrupted.'].filter(line => line !== null).join('\n')diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/queued-first-input.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/queued-first-input.test.tsxnew file mode 100644index 00000000000..ae98de5f33b--- /dev/null+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/queued-first-input.test.tsx@@ -0,0 +1,161 @@+import { act, cleanup, renderHook } from '@testing-library/react'+import { useRef } from 'react'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'++import { PRIMARY_SESSION_VIEW } from '@/app/chat/session-view'+import { en } from '@/i18n/en'+import { chatMessageText, textPart } from '@/lib/chat-messages'+import {+ $connection,+ $messages,+ setActiveSessionId,+ setAwaitingResponse,+ setBusy,+ setMessages,+ setSelectedStoredSessionId,+ setSessions+} from '@/store/session'+import { clearAllSessionStates } from '@/store/session-states'+import { makeSessionInfo } from '@/test/session-info'++import { useSessionStateCache } from '../use-session-state-cache'++import { useSubmitPrompt } from './submit'++const SID = 'local-first-input'+const INPUT = 'Prepare the weekly report'++function mount(startBeforeReceipt = false) {+ let start = () => undefined++ const request = vi.fn(async (_method: string, params: Record<string, unknown>) => {+ if (startBeforeReceipt) {+ start()+ }++ return { admission_id: 'admission-1', submission_id: params.submission_id, session_id: SID, status: 'queued' }+ })++ const hook = renderHook(() => {+ const busyRef = useRef(false)++ const cache = useSessionStateCache({+ activeSessionId: SID,+ selectedStoredSessionId: SID,+ busyRef,+ setMessages,+ setBusy,+ setAwaitingResponse+ })++ const submit = useSubmitPrompt({+ ...cache,+ busyRef,+ copy: en.desktop,+ createBackendSessionForSend: async () => null,+ getRoutedStoredSessionId: () => SID,+ getRouteToken: () => `/${SID}`,+ requestGateway: request as Parameters<typeof useSubmitPrompt>[0]['requestGateway'],+ resumeStoredSession: async () => undefined,+ syncAttachmentsForSubmit: async (sessionId, attachments) => ({ sessionId, attachments })+ })++ return { cache, submit }+ })++ act(() => {+ hook.result.current.cache.updateSessionState(SID, state => state, SID)+ })++ start = () => {+ hook.result.current.cache.updateSessionState(+ SID,+ state => ({+ ...state,+ busy: true,+ awaitingResponse: true,+ turnLive: true,+ turnStartedAt: 1234+ }),+ SID+ )+ }++ return { hook, request }+}++beforeEach(() => {+ window.localStorage.clear()+ clearAllSessionStates()+ setMessages([])+ setBusy(false)+ setAwaitingResponse(false)+ setActiveSessionId(SID)+ setSelectedStoredSessionId(SID)+ setSessions([makeSessionInfo({ id: SID, source: 'gui', message_count: 0 })])+ $connection.set({+ mode: 'local',+ connectionId: 'local',+ profile: 'default',+ baseUrl: 'http://127.0.0.1:1',+ wsUrl: 'ws://127.0.0.1:1/api/ws?native_dial=1',+ token: '',+ logs: [],+ isFullscreen: false,+ nativeOverlayWidth: 0,+ windowButtonPosition: null+ })+})++afterEach(() => {+ cleanup()+ clearAllSessionStates()+ setMessages([])+ setBusy(false)+ setAwaitingResponse(false)+ setActiveSessionId(null)+ setSelectedStoredSessionId(null)+ setSessions([])+ $connection.set(null)+ vi.restoreAllMocks()+})++it.each([false, true])('keeps first input visible when a queued receipt races start=%s', async startBeforeReceipt => {+ const { hook, request } = mount(startBeforeReceipt)+ await act(async () => {+ expect(await hook.result.current.submit(INPUT)).toBe(true)+ })+ expect(request).toHaveBeenCalledTimes(1)+ expect(PRIMARY_SESSION_VIEW.$messages.get().map(chatMessageText)).toEqual([INPUT])+ expect(PRIMARY_SESSION_VIEW.$messagesEmpty.get()).toBe(false)+ expect(PRIMARY_SESSION_VIEW.$busy.get()).toBe(true)++ if (startBeforeReceipt) {+ expect(hook.result.current.cache.sessionStateByRuntimeIdRef.current.get(SID)).toMatchObject({+ turnLive: true,+ turnStartedAt: 1234+ })+ }+})++it('does not graft explicitly queued input onto the active turn', async () => {+ const { hook } = mount()+ act(() => {+ hook.result.current.cache.updateSessionState(+ SID,+ state => ({+ ...state,+ busy: true,+ turnLive: true,+ messages: [{ id: 'current-answer', role: 'assistant', parts: [textPart('Still working')] }]+ }),+ SID+ )+ })+ await act(async () => {+ expect(await hook.result.current.submit(INPUT, { fromQueue: true })).toBe(true)+ })+ expect(PRIMARY_SESSION_VIEW.$messages.get().map(chatMessageText)).toEqual(['Still working'])+ expect(PRIMARY_SESSION_VIEW.$busy.get()).toBe(true)+ expect($messages.get().some(message => chatMessageText(message) === INPUT)).toBe(false)+})diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.tsindex c8f0da92a42..c119e762309 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts@@ -953,9 +953,10 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {status: result.status})- if (result.status === 'queued') {- dropOptimistic(sessionId)- } else if (result.status === 'terminal') {+ // Queued is also the initial receipt for an idle session's first+ // turn. Keep its input and any start event that raced this ACK;+ // explicit queue-only sends never inserted an optimistic bubble.+ if (result.status === 'terminal') {// Deduplication does not start a turn or promise another terminal// event. Remove our duplicate bubble, but preserve any live turn// that an owner event established while the receipt was in flight.