Skip to content

The agent that grows with you

fix: route native composer Queue through existing admission submit

Teknium4ce95d5f2eaa
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx
index 2d29d8b6b87..065ce1b6507 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx
@@ -11,6 +11,9 @@ import {
parkQueuedPrompts
} from '@/store/composer-queue'
+import { $connection } from '@/store/session'
+import type { HermesConnection } from '@/global'
+
import type { QueueEditState } from '../composer-utils'
import type { ChatBarProps } from '../types'
@@ -67,6 +70,30 @@ describe('useComposerQueue park integration', () => {
$parkedQueueSessions.set({})
})
+ it('admits native Queue through submit and retains an uncertain draft without a local replay', async () => {
+ $connection.set({ mode: 'local', wsUrl: 'ws://localhost/api/ws?native_dial=unminted' } as HermesConnection)
+ const draftRef = { current: 'durable queue' }
+ const clearDraft = vi.fn(() => { draftRef.current = '' })
+ const onSubmit = vi.fn<ChatBarProps['onSubmit']>().mockResolvedValue(false)
+ const hook = renderHook(({ busy }) => useComposerQueue({
+ activeQueueSessionKey: SESSION_KEY, attachments: [], busy, clearDraft, draftRef,
+ focusInput: () => undefined, loadIntoComposer: () => undefined, onCancel: vi.fn(), onSteer: undefined,
+ onSubmit, queueEditRef: { current: null }, queueSessionKey: SESSION_KEY, sessionId: 'rt-session-queue-hook'
+ }), { initialProps: { busy: true } })
+ try {
+ await act(async () => { await hook.result.current.queueCurrentDraft() })
+ expect(onSubmit).toHaveBeenCalledWith('durable queue', expect.objectContaining({ fromQueue: true, storedSessionId: SESSION_KEY }))
+ expect(draftRef.current).toBe('durable queue')
+ expect(getQueuedPrompts(SESSION_KEY)).toEqual([])
+ onSubmit.mockResolvedValue(true)
+ await act(async () => { await hook.result.current.queueCurrentDraft() })
+ expect(clearDraft).toHaveBeenCalledTimes(1)
+ hook.rerender({ busy: false })
+ await act(async () => { await Promise.resolve() })
+ expect(onSubmit).toHaveBeenCalledTimes(2)
+ } finally { $connection.set(null) }
+ })
+
it('reschedules rejected foreground drains to a bounded stop and keeps manual recovery', async () => {
vi.useFakeTimers()
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.ts
index 51837070a6d..bfc0aa1fdb4 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
@@ -18,6 +18,7 @@ import {
type QueuedPromptEntry,
removeQueuedPrompt,
shouldAutoDrain,
+ serverOwnsComposerQueue,
unparkQueuedPrompts,
updateQueuedPrompt
} from '@/store/composer-queue'
@@ -186,6 +187,17 @@ export function useComposerQueue({
return false
}
+ if (serverOwnsComposerQueue(sessionId ?? activeQueueSessionKey)) {
+ return Promise.resolve(onSubmit(text, {
+ attachments: cloneAttachments(attachments), fromQueue: true,
+ sessionId: sessionId ?? null, storedSessionId: activeQueueSessionKey
+ })).then(accepted => {
+ if (accepted !== true) { return false }
+ if (draftRef.current === text) { clearDraft(); scope.attachments.clear() }
+ return true
+ }).catch(() => false)
+ }
+
if (!enqueueQueuedPrompt(activeQueueSessionKey, { text, attachments })) {
return false
}
@@ -195,7 +207,7 @@ export function useComposerQueue({
triggerHaptic('selection')
return true
- }, [activeQueueSessionKey, attachments, clearDraft, draftRef, scope.attachments])
+ }, [activeQueueSessionKey, attachments, clearDraft, draftRef, scope.attachments, onSubmit, sessionId])
// All queue drain paths share one lock + send-then-remove sequence.
// `pickEntry` lets each caller choose head, by-id, or skip-edited.
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
index 72f1fc9fbf0..1a3c799e199 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
@@ -37,7 +37,7 @@ interface UseComposerSubmitArgs {
onCancel: ChatBarProps['onCancel']
onSteer: ChatBarProps['onSteer']
onSubmit: ChatBarProps['onSubmit']
- queueCurrentDraft: () => boolean
+ queueCurrentDraft: () => boolean | Promise<boolean>
queueEdit: QueueEditState | null
queuedPrompts: QueuedPromptEntry[]
sessionId: string | null | undefined
diff --git a/apps/desktop/src/store/composer-queue.ts b/apps/desktop/src/store/composer-queue.ts
index d5f1768544c..be030089a42 100644
--- a/apps/desktop/src/store/composer-queue.ts
+++ b/apps/desktop/src/store/composer-queue.ts
@@ -1,6 +1,17 @@
import { atom } from 'nanostores'
import { SLASH_COMMAND_RE } from '@/lib/chat-runtime'
+import { $connection } from './session'
+import { knownOwnerForSession } from './session-states'
+
+/** Local owner routes use canonical admission; remote legacy queues stay local. */
+export function serverOwnsComposerQueue(sessionId: string | null | undefined): boolean {
+ const owner = knownOwnerForSession(sessionId)
+ if (owner && typeof owner === 'object' && owner.mode) { return owner.mode === 'local' }
+ const connection = $connection.get()
+ if (owner && typeof owner === 'object' && owner.connectionId !== connection?.connectionId) { return false }
+ return Boolean(connection?.wsUrl && new URL(connection.wsUrl).searchParams.has('native_dial'))
+}
import type { ComposerAttachment } from './composer'