The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(quick-entry): prove accepted identity on the current-chat submit path
LeonardoLGDS19f4d8bfad18
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 1f138447f9d..5b695ca89ef 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@@ -8,6 +8,8 @@ const registeredSubmitHandler = vi.hoisted(() => ({current: null as ((payload: { correlationId: string; target: string; text: string }) => void) | null}))+type SubmitTextForBridge = Parameters<typeof useQuickEntryBridge>[0]['submitText']+vi.mock('@/store/quick-entry', async importOriginal => {const actual = await importOriginal<typeof import('@/store/quick-entry')>()@@ -34,7 +36,12 @@ describe('quickEntrySubmitAck', () => {})})- it('acknowledges only an accepted prompt as success', () => {+ it('names the accepted identity on an accepted ack', () => {+ expect(quickEntrySubmitAck(true, { runtimeSessionId: 'rt-1', storedSessionId: 'st-1' })).toEqual({+ ok: true,+ runtimeSessionId: 'rt-1',+ sessionId: 'st-1'+ })expect(quickEntrySubmitAck(true)).toEqual({ ok: true })})})@@ -50,10 +57,10 @@ describe('useQuickEntryBridge', () => {vi.clearAllMocks()})- async function renderBridge() {+ async function renderBridge(submitText: SubmitTextForBridge = () => true) {function Harness() {useQuickEntryBridge({- submitText: () => true,+ submitText,submitTextToNewSession: async () => ({runtimeSessionId: 'runtime-new',sessionId: 'stored-new'@@ -73,6 +80,117 @@ describe('useQuickEntryBridge', () => {return { container, submit: registeredSubmitHandler.current! }}+ it('acknowledges a current-chat submit with the identity the pipeline accepted', async () => {+ const correlationId = 'current-submit-correlation'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const submitText = vi.fn(async (text: string, options?: Parameters<SubmitTextForBridge>[1]) => {+ options?.onAccepted?.({ runtimeSessionId: 'rt-current-1', storedSessionId: 'st-current-1' })+ expect(text).toBe('Send to current chat')+ return true+ })+ const { container, submit } = await renderBridge(submitText)++ await act(async () => {+ await submit({ correlationId, target: 'current', text: 'Send to current chat' })+ })++ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, {+ ok: true,+ runtimeSessionId: 'rt-current-1',+ sessionId: 'st-current-1'+ })++ container.remove()+ })++ it('acknowledges a current-chat submit with no identity without inventing one', async () => {+ const correlationId = 'current-submit-no-identity'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const { container, submit } = await renderBridge(vi.fn(async () => true))++ await act(async () => {+ await submit({ correlationId, target: 'current', text: 'No identity path' })+ })++ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, { ok: true })++ container.remove()+ })++ it('keeps a rejected current-chat submit retryable', async () => {+ const correlationId = 'current-submit-rejected'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const { container, submit } = await renderBridge(vi.fn(async () => false))++ await act(async () => {+ await submit({ correlationId, target: 'current', text: 'Rejected prompt' })+ })++ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, {+ code: 'submit-rejected',+ message: 'The prompt was not accepted.',+ ok: false,+ retryable: true+ })++ container.remove()+ })++ it('reports a failed current-chat submit as retryable', async () => {+ const correlationId = 'current-submit-failed'+ const ackSubmit = vi.fn()+ window.hermesDesktop = {+ quickEntry: {+ ackSubmit,+ pushState: vi.fn()+ }+ } as unknown as typeof window.hermesDesktop++ const { container, submit } = await renderBridge(+ vi.fn(async () => {+ throw new Error('gateway down')+ })+ )++ await act(async () => {+ await submit({ correlationId, target: 'current', text: 'Failed prompt' })+ })++ expect(ackSubmit).toHaveBeenCalledTimes(1)+ expect(ackSubmit).toHaveBeenCalledWith(correlationId, {+ code: 'submit-failed',+ message: 'gateway down',+ ok: false,+ retryable: true+ })++ container.remove()+ })+it('acknowledges an accepted selected-session submit with exact identity', async () => {const correlationId = 'selected-submit-correlation'const ackSubmit = vi.fn()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 17ffdeabf3d..de5bcefb027 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@@ -13,10 +13,19 @@ import { sessionTileDelegate } from '@/store/session-states'import { isAuxiliaryWindow } from '@/store/windows'interface QuickEntryBridgeParams {- submitText: (text: string) => Promise<boolean> | boolean+ submitText: (+ text: string,+ options?: { onAccepted?: (identity: QuickEntryAcceptedIdentity) => void }+ ) => Promise<boolean> | booleansubmitTextToNewSession: (text: string) => Promise<{ runtimeSessionId: string; sessionId: string }>}+/** Exact session identity that accepted a prompt (runtime + durable stored id). */+interface QuickEntryAcceptedIdentity {+ runtimeSessionId: string+ storedSessionId: null | string+}+// The picker is a capture aid, not a session browser — a handful of recent// rows is the whole point.const QUICK_ENTRY_SESSION_OPTIONS = 5@@ -26,15 +35,25 @@ const QUICK_ENTRY_SESSION_OPTIONS = 5* without throwing (for example, while the target is busy). That is a failed* delivery, not an acknowledgement of success.*/-export function quickEntrySubmitAck(submitted: boolean): QuickEntrySubmitResult {- return submitted- ? { ok: true }- : {- code: 'submit-rejected',- message: 'The prompt was not accepted.',- ok: false,- retryable: true- }+export function quickEntrySubmitAck(+ submitted: boolean,+ identity?: null | QuickEntryAcceptedIdentity+): QuickEntrySubmitResult {+ if (!submitted) {+ return {+ code: 'submit-rejected',+ message: 'The prompt was not accepted.',+ ok: false,+ retryable: true+ }+ }++ // An accepted prompt names the session that accepted it. A submit that+ // resolved true without an identity callback (slash commands, which never+ // reach prompt.submit) still acknowledges, but claims no backend session.+ return identity+ ? { ok: true, runtimeSessionId: identity.runtimeSessionId, sessionId: identity.storedSessionId }+ : { ok: true }}function sessionOptions(): QuickEntrySessionOption[] {@@ -147,9 +166,15 @@ export function useQuickEntryBridge({return}+ let acceptedIdentity: null | QuickEntryAcceptedIdentity = null+try {- const submitted = await submitTextRef.current(text)- ack(quickEntrySubmitAck(submitted))+ const submitted = await submitTextRef.current(text, {+ onAccepted: identity => {+ acceptedIdentity = identity+ }+ })+ ack(quickEntrySubmitAck(submitted, acceptedIdentity))} catch (error) {ack({ code: 'submit-failed', message: error instanceof Error ? error.message : String(error), ok: false, retryable: true })}diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsxindex 0844a193915..ef2b9cf3af8 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.test.tsx@@ -2736,6 +2736,51 @@ describe('usePromptActions submit / queue drain semantics', () => {expect(requestGateway).not.toHaveBeenCalledWith('prompt.submit', expect.anything())dropSessionState(RUNTIME_SESSION_ID)})++ it('reports the exact accepted identity through onAccepted after a stale-runtime recovery', async () => {+ const STORED_SESSION_ID = 'stored-db-xyz789'+ const RECOVERED_SESSION_ID = 'rt-recovered-456'+ let submitAttempts = 0++ const requestGateway = vi.fn(async (method: string) => {+ if (method === 'prompt.submit') {+ submitAttempts += 1++ if (submitAttempts === 1) {+ throw new Error('session not found')+ }++ return {} as never+ }++ if (method === 'session.resume') {+ return { session_id: RECOVERED_SESSION_ID } as never+ }++ return {} as never+ })++ let handle: HarnessHandle | null = null+ await actRender(+ <Harness+ onReady={h => (handle = h)}+ refreshSessions={async () => undefined}+ requestGateway={requestGateway}+ storedSessionId={STORED_SESSION_ID}+ />+ )++ const onAccepted = vi.fn()++ const ok = await handle!.submitText('identity after wake', { onAccepted })++ expect(ok).toBe(true)+ expect(onAccepted).toHaveBeenCalledTimes(1)+ expect(onAccepted).toHaveBeenCalledWith({+ runtimeSessionId: RECOVERED_SESSION_ID,+ storedSessionId: STORED_SESSION_ID+ })+ })})describe('usePromptActions redirectPrompt', () => {@@ -3650,6 +3695,7 @@ describe('usePromptActions file attachment sync', () => {params: { session_id: RUNTIME_SESSION_ID, text: '@file:data/report.txt\n\nsummarize' }})})+})describe('usePromptActions eager-upload races', () => {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 e782a68f555..b5611d2c1b4 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@@ -934,10 +934,14 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {// other session-scoped RPC (attach, /compress, rewind, interrupt) goes// through the same helper so one policy covers the whole bug class.let submitErr: unknown = null+ // The identity the backend actually accepted: the live runtime id,+ // replaced below when a stale binding was recovered.+ let acceptedRuntimeSessionId = liveSessionId+ // Hoisted out of the recovery call so the acceptance report can name+ // the durable session even when no recovery was needed.+ const recoverStoredSessionId = targetStoredSessionId ?? selectedStoredSessionIdRef.currenttry {- const recoverStoredSessionId = targetStoredSessionId ?? selectedStoredSessionIdRef.current-// A bot's chat is a tile scoped to the `bots` workspace; the primary chat is Sessions mode.noteMessageSent($sessionTiles.get().find(tile => tile.runtimeId === sessionId)?.workspaceMode ?? 'sessions')@@ -999,6 +1003,8 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {}})}++ acceptedRuntimeSessionId = submitted.sessionId} catch (firstErr) {if (firstErr instanceof SessionRecoveryAborted) {console.warn('[submit-drift-abort]', firstErr.reason, { phase: 'post-resume-retry' })@@ -1013,6 +1019,16 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {throw submitErr}+ // The prompt is now accepted. Report the EXACT identity it landed on+ // (recovered id included) so a caller that must prove delivery — the+ // Quick Entry bridge — never guesses the foreground session. Fires+ // before the local cleanup below: acceptance is already true even if a+ // later local step throws.+ options?.onAccepted?.({+ runtimeSessionId: acceptedRuntimeSessionId,+ storedSessionId: recoverStoredSessionId ?? null+ })+if (usingComposerAttachments) {// A submit owns only the occurrences that actually reached the// gateway. Tokenized chips match across staging clones; legacy chipsdiff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.tsindex b1b5f0ff13e..788a348a41c 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/utils.ts@@ -722,6 +722,13 @@ export interface SubmitTextOptions {* model-bound note by the gateway (never persisted, never rendered). */voiceContext?: stringfromQueue?: boolean+ /** Called once with the EXACT session identity the backend accepted the+ * prompt into — the live runtime id after any stale-runtime recovery, plus+ * the durable stored id when the caller knows it. A caller that must prove+ * delivery to another surface (Quick Entry) uses this instead of guessing+ * from the foreground session. Never called for a rejected or aborted+ * submit, and never for slash commands, which never reach prompt.submit. */+ onAccepted?: (identity: { runtimeSessionId: string; storedSessionId: null | string }) => void/** Runtime session id to submit into. Queue drains pass this so a* backgrounded/source session cannot be replaced by the current foreground* session between enqueue and drain. */