The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): show a prompt forwarded to the gateway owner as queued, and a busy owner as retryable
Teknium6078078a9655
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 45d7dc93fe6..6b10f14d1e0 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@@ -5616,6 +5616,75 @@ describe('usePromptActions live-owner refusal (#106217)', () => {// Not a stale-runtime symptom: no resume/re-mint attempt hides the refusal.expect(requestGateway.mock.calls.map(c => c[0])).toEqual(['prompt.submit'])})++ it('turns a SESSION_OWNER_BUSY refusal into a retryable card, not "Start new session" (#140385)', async () => {+ let latest: Record<string, unknown> | undefined++ const requestGateway = vi.fn(async (method: string) => {+ if (method === 'prompt.submit') {+ throw new JsonRpcGatewayError(+ 'The gateway is running a turn in this chat and a rewind or attachment cannot join its queue. Nothing was sent. Send it again when the current turn ends.',+ { code: 4090, data: { reason: 'SESSION_OWNER_BUSY' } }+ )+ }++ return {} as never+ })++ let handle: HarnessHandle | null = null+ await actRender(+ <Harness+ onReady={h => (handle = h)}+ onSeedState={next => {+ latest = next+ }}+ refreshSessions={async () => undefined}+ requestGateway={requestGateway}+ />+ )++ expect(await handle!.submitText('continue here')).toBe(false)+ const bubble = (latest?.messages as { errorSurface?: Record<string, unknown> }[]).at(-1)+ expect(bubble?.errorSurface).toEqual({ layer: 'gateway', code: 'SESSION_OWNER_BUSY', retryable: true })+ })++ it('shows a prompt the legacy backend forwarded to the gateway owner as queued, not as a failed turn (#140385)', async () => {+ let latest: Record<string, unknown> | undefined++ // The legacy backend refuses `submission_id` (4000, pre-admission), then answers the identityless+ // retry with the owner's queued receipt: the prompt waits in the gateway's FIFO.+ const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {+ if (method === 'prompt.submit' && params?.submission_id) {+ throw new JsonRpcGatewayError("unknown field 'submission_id'", { code: 4000 })+ }++ if (method === 'prompt.submit') {+ return { status: 'queued', admission_id: 'owner-admission', forwarded: true } as never+ }++ return {} as never+ })++ let handle: HarnessHandle | null = null+ await actRender(+ <Harness+ onReady={h => (handle = h)}+ onSeedState={next => {+ latest = next+ }}+ refreshSessions={async () => undefined}+ requestGateway={requestGateway}+ />+ )++ expect(await handle!.submitText('my own question')).toBe(true)+ const messages = (latest?.messages ?? []) as { error?: string; role?: string }[]+ // No failed-turn card and no optimistic bubble: the queued-row card stands for the send.+ expect(messages.some(message => message.error)).toBe(false)+ expect(messages.some(message => message.role === 'user')).toBe(false)+ expect(latest?.busy).toBe(false)+ expect(latest?.awaitingResponse).toBe(false)+ })})describe('usePromptActions send from a window behind the stored transcript', () => {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 64369f07f44..2631d05fa49 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@@ -64,6 +64,7 @@ import {isProviderSetupError,isSessionBusyError,isSessionNotOwnedError,+ isSessionOwnerBusyError,isTargetSessionBusy,releaseSubmitInFlight,SessionRecoveryAborted,@@ -155,7 +156,7 @@ export function rebindPaneToResumedRuntime({/** The prompt submit pipeline, extracted from usePromptActions. *//** Canonical admission receipt; `user_row_id` binds the optimistic bubble to its durable row. */-type SubmitReceipt = Pick<PromptSubmitResult, 'user_row_id'> & {+type SubmitReceipt = Pick<PromptSubmitResult, 'forwarded' | 'user_row_id'> & {admission_id?: stringsubmission_id?: stringsession_id?: string@@ -1256,6 +1257,15 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {return false}+ // RT-37: a legacy backend handed this prompt to the gateway that owns the chat; it+ // waits in that owner's FIFO behind the gateway's turn. The queued-row card (the+ // backend's pending_submissions) stands for it until the owner starts it, so no+ // optimistic bubble or spinner here; the owner's start and completion repaint it.+ if (legacyAccepted && result?.forwarded === true && result.status === 'queued') {+ dropOptimistic(sessionId)+ releaseBusy()+ }+acceptedRuntimeSessionId = receiptSessionId} catch (firstErr) {if (firstErr instanceof SessionRecoveryAborted) {@@ -1320,6 +1330,9 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {// Another surface owns the session (#106217): a deterministic gateway// refusal, so the error card drops Retry and offers a new session.const notOwned = isSessionNotOwnedError(err)+ // The gateway owner is mid-turn and could not queue this send (#140385): transient, so the+ // card offers to send it again once the turn ends instead of a new session.+ const ownerBusy = !notOwned && isSessionOwnerBusyError(err)updateSessionState(sessionId,@@ -1333,6 +1346,7 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {parts: [],error: message || copy.promptFailed,...(notOwned && { errorSurface: { layer: 'gateway', code: 'SESSION_NOT_OWNED', retryable: false } }),+ ...(ownerBusy && { errorSurface: { layer: 'gateway', code: 'SESSION_OWNER_BUSY', retryable: true } }),branchGroupId: state.pendingBranchGroup ?? undefined,completedAt: occurredAt,timestamp: occurredAtdiff --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 96fbd313108..d2c130d3bd9 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@@ -308,6 +308,12 @@ export function isSessionNotOwnedError(error: unknown): boolean {return reason === 'SESSION_NOT_OWNED' || /already has a live owner/i.test(error instanceof Error ? error.message : '')}+// prompt.submit refused because the gateway that owns this chat is mid-turn and could not queue+// the send (4090 / SESSION_OWNER_BUSY, #140385). Transient: the turn ends on its own.+export function isSessionOwnerBusyError(error: unknown): boolean {+ return error instanceof JsonRpcGatewayError && (error.data as { reason?: unknown } | undefined)?.reason === 'SESSION_OWNER_BUSY'+}+const sleep = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms))// Retry a gateway call across transient "session busy" so it never reaches thediff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex cfb6311975c..0e6aa063d90 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -4694,6 +4694,10 @@ export const en: Translations = {title: 'Hermes got stuck in a loop',body: 'The reply kept repeating the same steps, so Hermes stopped it. Retry, or start a new chat if it happens again.'},+ SESSION_OWNER_BUSY: {+ title: 'Hermes is busy in this chat',+ body: 'Another turn is running in this chat and your message could not wait in its queue. Nothing was sent. Retry once the current turn ends.'+ },SESSION_NOT_OWNED: {title: 'This chat is open somewhere else',body: 'This chat is currently open in another Hermes window or terminal. Close it there and send your message again, or start a new chat here.'diff --git a/apps/desktop/src/i18n/overlay-gaps.json b/apps/desktop/src/i18n/overlay-gaps.jsonindex 9d7b63769c2..7bf98817afa 100644--- a/apps/desktop/src/i18n/overlay-gaps.json+++ b/apps/desktop/src/i18n/overlay-gaps.json@@ -52,6 +52,8 @@"assistant.thread.errorChooseModel": ["ar","ja","ru","zh","zh-hant"],"assistant.thread.errorCodes.SESSION_NOT_OWNED.body": ["ar","ja","ru","zh","zh-hant"],"assistant.thread.errorCodes.SESSION_NOT_OWNED.title": ["ar","ja","ru","zh","zh-hant"],+ "assistant.thread.errorCodes.SESSION_OWNER_BUSY.body": ["ar","de","es","fr","ja","ru","zh","zh-hant"],+ "assistant.thread.errorCodes.SESSION_OWNER_BUSY.title": ["ar","de","es","fr","ja","ru","zh","zh-hant"],"assistant.thread.errorCodes.auth.body": ["ar","ja","ru","zh","zh-hant"],"assistant.thread.errorCodes.auth.title": ["ar","ja","ru","zh","zh-hant"],"assistant.thread.errorCodes.auth_permanent.body": ["ar","ja","ru","zh","zh-hant"],diff --git a/apps/desktop/src/lib/error-surface.ts b/apps/desktop/src/lib/error-surface.tsindex 079d731d766..f9bf015b234 100644--- a/apps/desktop/src/lib/error-surface.ts+++ b/apps/desktop/src/lib/error-surface.ts@@ -49,6 +49,8 @@ export const ERROR_CODE_KEYS = ['empty_response','loop_error','SESSION_NOT_OWNED',+ // The gateway that owns the chat is mid-turn and could not queue this send: transient.+ 'SESSION_OWNER_BUSY','disk_full',// Raised by the desktop, never by the backend: the backend reported a turn// over after its events stopped, and no reply reached this window.@@ -267,6 +269,7 @@ const SWITCH_PROVIDER_LAYERS: readonly ErrorSurfaceLayer[] = ['auth', 'billing',// conversation, a blocked prompt, a chat another surface owns).const CODE_PLANS: Partial<Record<ErrorCodeKey, Partial<ErrorRecoveryPlan>>> = {SESSION_NOT_OWNED: { retry: false, startNewSession: true },+ SESSION_OWNER_BUSY: { retry: true, startNewSession: false },content_policy_blocked: { editMessage: true, retry: false },context_overflow: { compress: true, retry: false, startNewSession: true },disk_full: { openHermesFolder: true, retry: true },