The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(quick-entry): report stored-session submit acceptance with exact identity
LeonardoLGDS7b67383354b3
diff --git a/apps/desktop/src/app/chat/session-tile-actions.test.ts b/apps/desktop/src/app/chat/session-tile-actions.test.tsindex f9f2991d0fa..19854fb5613 100644--- a/apps/desktop/src/app/chat/session-tile-actions.test.ts+++ b/apps/desktop/src/app/chat/session-tile-actions.test.ts@@ -93,7 +93,7 @@ describe('useSessionTileActions sleep/wake session recovery', () => {executeSlash: vi.fn(async () => undefined),interruptSession: vi.fn(async () => undefined),resumeTile: vi.fn(async () => RUNTIME_SESSION_ID),- submitToSession: vi.fn(async () => undefined),+ submitToSession: vi.fn(async () => RUNTIME_SESSION_ID),updateSession: vi.fn((_runtimeId, updater) =>updater({attachedImages: [],diff --git a/apps/desktop/src/app/chat/session-tile-attachments.test.tsx b/apps/desktop/src/app/chat/session-tile-attachments.test.tsxindex 162c9dc6110..90018b77fc1 100644--- a/apps/desktop/src/app/chat/session-tile-attachments.test.tsx+++ b/apps/desktop/src/app/chat/session-tile-attachments.test.tsx@@ -89,7 +89,7 @@ function installDelegate(): void {executeSlash: vi.fn(async () => undefined),interruptSession: vi.fn(async () => undefined),resumeTile: vi.fn(async () => RUNTIME_ID),- submitToSession: vi.fn(async () => undefined),+ submitToSession: vi.fn(async () => RUNTIME_ID),updateSession})}diff --git a/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts b/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.tsindex f7eb29a3a3c..1f138447f9d 100644--- a/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts+++ b/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts@@ -50,26 +50,7 @@ describe('useQuickEntryBridge', () => {vi.clearAllMocks()})- it('does not acknowledge a selected-session void submit as success', async () => {- const correlationId = 'selected-submit-correlation'- const ackSubmit = vi.fn()- ackSubmit.mockImplementationOnce(() => {- throw new Error('ack channel failed')- })- window.hermesDesktop = {- quickEntry: {- ackSubmit,- pushState: vi.fn()- }- } as typeof window.hermesDesktop-- const resumeTile = vi.fn(async () => 'runtime-session-1')- const submitToSession = vi.fn(async () => {})- vi.mocked(sessionTileDelegate).mockReturnValue({- resumeTile,- submitToSession- } as ReturnType<typeof sessionTileDelegate>)-+ async function renderBridge() {function Harness() {useQuickEntryBridge({submitText: () => true,@@ -89,10 +70,35 @@ describe('useQuickEntryBridge', () => {root?.render(createElement(Harness))})+ return { container, submit: registeredSubmitHandler.current! }+ }++ it('acknowledges an accepted selected-session submit with exact identity', async () => {+ const correlationId = 'selected-submit-correlation'+ const ackSubmit = vi.fn()+ ackSubmit.mockImplementationOnce(() => {+ throw new Error('ack channel failed')+ })+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const resumeTile = vi.fn(async () => 'runtime-session-1')+ const submitToSession = vi.fn(async () => 'runtime-session-1')+ vi.mocked(sessionTileDelegate).mockReturnValue({+ resumeTile,+ submitToSession+ } as unknown as ReturnType<typeof sessionTileDelegate>)++ const { container, submit } = await renderBridge()+expect(registeredSubmitHandler.current).toBeTypeOf('function')await act(async () => {- await registeredSubmitHandler.current?.({+ await submit({correlationId,target: 'stored-session-1',text: 'Send from Quick Entry'@@ -101,6 +107,74 @@ describe('useQuickEntryBridge', () => {expect(resumeTile).toHaveBeenCalledWith('stored-session-1')expect(submitToSession).toHaveBeenCalledWith('runtime-session-1', 'Send from Quick Entry')+ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, {+ ok: true,+ runtimeSessionId: 'runtime-session-1',+ sessionId: 'stored-session-1'+ })++ container.remove()+ })++ it('reports the recovered runtime id when the delegate rebinds it', async () => {+ const correlationId = 'selected-submit-recovered'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const resumeTile = vi.fn(async () => 'runtime-session-before-recovery')+ const submitToSession = vi.fn(async () => 'runtime-session-recovered')+ vi.mocked(sessionTileDelegate).mockReturnValue({+ resumeTile,+ submitToSession+ } as unknown as ReturnType<typeof sessionTileDelegate>)++ const { container, submit } = await renderBridge()++ await act(async () => {+ await submit({ correlationId, target: 'stored-session-1', text: 'Recover me' })+ })++ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, {+ ok: true,+ runtimeSessionId: 'runtime-session-recovered',+ sessionId: 'stored-session-1'+ })++ container.remove()+ })++ it('keeps a post-dispatch failure non-retryable', async () => {+ const correlationId = 'selected-submit-post-dispatch-failure'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const resumeTile = vi.fn(async () => 'runtime-session-1')+ const submitToSession = vi.fn(async () => {+ throw new Error('gateway down')+ })+ vi.mocked(sessionTileDelegate).mockReturnValue({+ resumeTile,+ submitToSession+ } as unknown as ReturnType<typeof sessionTileDelegate>)++ const { container, submit } = await renderBridge()++ await act(async () => {+ await submit({ correlationId, target: 'stored-session-1', text: 'Fail after dispatch' })+ })+expect(ackSubmit).toHaveBeenCalledTimes(1)expect(ackSubmit).toHaveBeenCalledWith(correlationId, {code: 'submit-failed',@@ -111,4 +185,41 @@ describe('useQuickEntryBridge', () => {container.remove()})++ it('keeps a pre-dispatch failure retryable', async () => {+ const correlationId = 'selected-submit-pre-dispatch-failure'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const resumeTile = vi.fn(async () => {+ throw new Error('resume failed')+ })+ const submitToSession = vi.fn(async () => 'runtime-session-1')+ vi.mocked(sessionTileDelegate).mockReturnValue({+ resumeTile,+ submitToSession+ } as unknown as ReturnType<typeof sessionTileDelegate>)++ const { container, submit } = await renderBridge()++ await act(async () => {+ await submit({ correlationId, target: 'stored-session-1', text: 'Fail before dispatch' })+ })++ expect(submitToSession).not.toHaveBeenCalled()+ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, {+ code: 'submit-failed',+ message: 'resume failed',+ ok: false,+ retryable: true+ })++ container.remove()+ })})diff --git a/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.ts b/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.tsindex 95937028da7..17ffdeabf3d 100644--- a/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.ts+++ b/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.ts@@ -117,14 +117,9 @@ export function useQuickEntryBridge({try {const runtimeId = await delegate.resumeTile(target)promptDispatched = true- await delegate.submitToSession(runtimeId, text)-- ack({- code: 'submit-failed',- message: 'The selected session prompt was dispatched, but backend acceptance is unknown.',- ok: false,- retryable: false- })+ const acceptedRuntimeId = await delegate.submitToSession(runtimeId, text)++ ack({ ok: true, runtimeSessionId: acceptedRuntimeId, sessionId: target })} catch (error) {if (promptDispatched) {ack({diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.tsindex 72aacd8d24f..9254fdc365c 100644--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts@@ -23,7 +23,7 @@ vi.mock('@/store/gateway', async importActual => ({requestGatewayForProfile: vi.fn()}))-const { getLatestSessionMessages } = await import('@/hermes')+const { getLatestSessionMessages, PROMPT_SUBMIT_REQUEST_TIMEOUT_MS } = await import('@/hermes')const { requestGatewayForAgent, requestGatewayForProfile } = await import('@/store/gateway')const row = (over: Partial<SessionInfo>): SessionInfo =>@@ -758,3 +758,73 @@ describe('useSessionTileDelegate stale multi-window guard (#65047)', () => {expect($notifications.get().some(note => note.kind === 'warning')).toBe(false)})})++describe('useSessionTileDelegate submitToSession', () => {+ beforeEach(() => {+ setSessions([])+ })++ afterEach(() => {+ setSessions([])+ })++ it('returns the accepting runtime id on both the happy and recovered paths', async () => {+ setSessions([row({ id: 'stored-submit', profile: 'default' })])++ const state = { busy: false, messages: [{ id: 'm1' }], storedSessionId: 'stored-submit' }+ const runtimeIdByStoredSessionIdRef = { current: new Map([['stored-submit', 'runtime-dead']]) }+ const sessionStateByRuntimeIdRef = { current: new Map([['runtime-dead', state]]) }+ const requestGateway = vi.fn(async (method: string) => {+ if (method === 'prompt.submit') {+ return {} as never+ }++ if (method === 'session.resume') {+ return { session_id: 'runtime-recovered' } as never+ }++ throw new Error(`unexpected gateway method: ${method}`)+ })++ let promptAttempts = 0+ requestGateway.mockImplementationOnce(async () => {+ promptAttempts += 1+ throw new Error('session not found')+ })++ renderTile(requestGateway, { runtimeIdByStoredSessionIdRef, sessionStateByRuntimeIdRef })+ const delegate = sessionTileDelegate()!++ const recoveredId = await delegate.submitToSession('runtime-dead', 'Send from Quick Entry')+ expect(recoveredId).toBe('runtime-recovered')++ const acceptedId = await delegate.submitToSession('runtime-recovered', 'Send again')+ expect(acceptedId).toBe('runtime-recovered')+ expect(promptAttempts).toBe(1)+ expect(runtimeIdByStoredSessionIdRef.current.get('stored-submit')).toBe('runtime-recovered')+ expect(requestGateway).toHaveBeenNthCalledWith(+ 1,+ 'prompt.submit',+ { session_id: 'runtime-dead', text: 'Send from Quick Entry' },+ PROMPT_SUBMIT_REQUEST_TIMEOUT_MS+ )+ expect(requestGateway).toHaveBeenNthCalledWith(2, 'session.resume', {+ session_id: 'stored-submit',+ source: 'desktop',+ omit_messages: true,+ profile: 'default'+ })+ expect(requestGateway).toHaveBeenNthCalledWith(+ 3,+ 'prompt.submit',+ { session_id: 'runtime-recovered', text: 'Send from Quick Entry' },+ PROMPT_SUBMIT_REQUEST_TIMEOUT_MS+ )+ expect(requestGateway).toHaveBeenNthCalledWith(+ 4,+ 'prompt.submit',+ { session_id: 'runtime-recovered', text: 'Send again' },+ PROMPT_SUBMIT_REQUEST_TIMEOUT_MS+ )+ })+})diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.tsindex 92377be42d5..268e925d816 100644--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts@@ -464,7 +464,7 @@ export function useSessionTileDelegate({if (isReadOnlyRuntimeId(runtimeId)) {notify({ kind: 'info', message: translateNow('desktop.readOnlyTranscriptSendBlocked') })- return+ return runtimeId}const storedSessionId = storedSessionIdForRuntime(runtimeId)@@ -505,13 +505,22 @@ export function useSessionTileDelegate({: requestGatewaynoteMessageSent($sessionTiles.get().find(tile => tile.runtimeId === runtimeId)?.workspaceMode ?? 'sessions')+ let acceptedRuntimeId = runtimeIdawait withSessionNotFoundResume(runtimeId,storedSessionId,liveId => routedRequest('prompt.submit', { session_id: liveId, text }, PROMPT_SUBMIT_REQUEST_TIMEOUT_MS),- { requestGateway: routedRequest, onRecovered: rebindTileRuntime(runtimeId) }+ {+ requestGateway: routedRequest,+ onRecovered: recoveredId => {+ acceptedRuntimeId = recoveredId+ rebindTileRuntime(runtimeId)(recoveredId)+ }+ })++ return acceptedRuntimeId},updateSession: (runtimeId, updater) => updateSessionState(runtimeId, updater)})diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex deed4f0b72a..dd89a30a350 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -2305,8 +2305,12 @@ export interface SessionTileDelegate {* without writing when the cache never held it (no phantom entries); the* caller writes the mirror itself. */updateHeldSession?(runtimeId: string, updater: (state: ClientSessionState) => ClientSessionState): boolean- /** Submit a prompt to a tile's live session. */- submitToSession(runtimeId: string, text: string): Promise<void>+ /**+ * Resolves with the live runtime session id that ACCEPTED the prompt. A+ * session-not-found recovery can rebind the runtime, so the accepted id may+ * differ from the input id; callers that report delivery must use this value.+ */+ submitToSession(runtimeId: string, text: string): Promise<string>/** THE session-state write path — routes through the wiring cache so the* cache, the primary view (when active), and every tile mirror agree. */updateSession(runtimeId: string, updater: (state: ClientSessionState) => ClientSessionState): ClientSessionState