Skip to content

The agent that grows with you

style: normalize verified queue admission imports and spacing

Tekniumd3ad7a90ec58
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 5bdd3ee0334..1530a0d7c83 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
@@ -1,6 +1,7 @@
import { act, cleanup, renderHook, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { HermesConnection } from '@/global'
import {
$parkedQueueSessions,
$queuedPromptsBySession,
@@ -10,9 +11,7 @@ import {
MAX_AUTO_DRAIN_ATTEMPTS,
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'
@@ -75,11 +74,13 @@ describe('useComposerQueue park integration', () => {
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 }))
@@ -99,11 +100,13 @@ describe('useComposerQueue park integration', () => {
let accept!: (value: boolean) => void
const clearDraft = vi.fn()
const draftRef = { current: 'same text' }
+
const hook = renderHook(({ key }) => useComposerQueue({
activeQueueSessionKey: key, attachments: [], busy: true, clearDraft, draftRef,
focusInput: () => undefined, loadIntoComposer: () => undefined, onCancel: vi.fn(), onSteer: undefined,
onSubmit: () => new Promise<boolean>(resolve => { accept = resolve }), queueEditRef: { current: null }, queueSessionKey: key, sessionId: key
}), { initialProps: { key: 'outgoing' } })
+
try {
let pending: boolean | Promise<boolean> = false
act(() => { pending = hook.result.current.queueCurrentDraft() })
@@ -132,9 +135,11 @@ describe('useComposerQueue park integration', () => {
}
expect(onSubmit).toHaveBeenCalledTimes(MAX_AUTO_DRAIN_ATTEMPTS)
+
for (const [, options] of onSubmit.mock.calls) {
expect(options).toMatchObject({ submission_id: entry.id })
}
+
await act(async () => {
await vi.advanceTimersByTimeAsync(300_000)
})
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 19a6e57989c..35f9090c835 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
@@ -17,8 +17,8 @@ import {
promoteQueuedPrompt,
type QueuedPromptEntry,
removeQueuedPrompt,
- shouldAutoDrain,
serverOwnsComposerQueue,
+ shouldAutoDrain,
unparkQueuedPrompts,
updateQueuedPrompt
} from '@/store/composer-queue'
@@ -195,10 +195,12 @@ export function useComposerQueue({
sessionId: sessionId ?? null, storedSessionId: activeQueueSessionKey
})).then(accepted => {
if (accepted !== true) { return false }
+
if (currentQueueKeyRef.current === activeQueueSessionKey && draftRef.current === text) {
clearDraft()
scope.attachments.removeOccurrences(attachments)
}
+
return true
}).catch(() => false)
}
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
index d29ad9a8137..5bbcb34b128 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
@@ -5,8 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import { PaneVisibleContext } from '@/components/pane-shell/pane-visibility'
import { $clarifyRequests } from '@/store/clarify'
import type { ComposerAttachment } from '@/store/composer'
-import { $connection } from '@/store/session'
-import { getQueuedPrompts, $queuedPromptsBySession } from '@/store/composer-queue'
+import { $queuedPromptsBySession, getQueuedPrompts } from '@/store/composer-queue'
import { $gateway } from '@/store/gateway'
import {
clearAllPrompts,
@@ -15,6 +14,7 @@ import {
setSecretRequest,
setSudoRequest
} from '@/store/prompts'
+import { $connection } from '@/store/session'
import { type ComposerTarget, requestComposerSubmit } from '../focus'
import { ComposerScopeProvider, ComposerSurfaceProvider, MAIN_COMPOSER_SCOPE } from '../scope'
@@ -154,6 +154,7 @@ describe('useComposerSubmit external request routing', () => {
$queuedPromptsBySession.set({})
const h = renderSubmitHook({ busy: true, text: 'keep guidance' })
h.onSteer.mockResolvedValue(false)
+
try {
act(() => h.hook.result.current.steerDraft())
await waitFor(() => expect(h.onSubmit).toHaveBeenCalledWith('keep guidance', expect.objectContaining({ fromQueue: true, sessionId: 'runtime-session', storedSessionId: 'stored-session' })))
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 75e0ca6b102..ec10f87f50a 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
@@ -7,7 +7,7 @@ import type { BusyInputMode } from '@/store/busy-input-mode'
import { hasClarifyRequest, skipClarifyRequest } from '@/store/clarify'
import { clearSessionDraft, type ComposerAttachment } from '@/store/composer'
import { resetBrowseState } from '@/store/composer-input-history'
-import { enqueueQueuedPrompt, serverOwnsComposerQueue, type QueuedPromptEntry } from '@/store/composer-queue'
+import { enqueueQueuedPrompt, type QueuedPromptEntry, serverOwnsComposerQueue } from '@/store/composer-queue'
import { hasMcpSetupRequest, skipMcpSetupRequest } from '@/store/mcp-setup'
import { hasBlockingPromptRequest } from '@/store/prompts'
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.tsx
index 07d2efd208e..5c032c44422 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
@@ -308,10 +308,13 @@ describe('durable submit acknowledgement', () => {
update: async (key, entry) => { journal.update(key, entry === null ? null : JSON.parse(entry)) }
} }
let accepted = false
+
const requestGateway = vi.fn(async (_method: string, params?: Record<string, unknown>) => {
expect(Object.values(journal.read())).toHaveLength(1)
+
return { admission_id: 'server-admission', submission_id: params?.submission_id, session_id: params?.session_id, status: accepted ? 'queued' : 'unknown' } as never
})
+
try {
let handle: HarnessHandle | null = null
await actRender(<Harness onReady={h => (handle = h)} rawAdmissionReceipts refreshSessions={async () => undefined} requestGateway={requestGateway} />)
@@ -431,14 +434,18 @@ describe('terminal receipt settlement', () => {
it('admits a native queued input without taking ownership of the running turn', async () => {
let handle: HarnessHandle | null = null
+
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
if (method !== 'prompt.submit') { return {} as never }
expect(handle!.state()).toMatchObject({ busy: true, awaitingResponse: true, streamId: 'owner-stream', turnLive: true })
+
return { admission_id: 'server-queue', submission_id: params?.submission_id, session_id: RUNTIME_SESSION_ID, status: 'queued' } as never
})
+
await actRender(<Harness onReady={h => (handle = h)} rawAdmissionReceipts refreshSessions={async () => undefined} requestGateway={requestGateway} />)
Object.assign(handle!.state(), { busy: true, awaitingResponse: true, streamId: 'owner-stream', turnLive: true })
$connection.set({ wsUrl: 'ws://localhost/api/ws?native_dial=unminted', mode: 'local' } as never)
+
try {
expect(await handle!.submitText('next input', { fromQueue: true })).toBe(true)
expect(handle!.state()).toMatchObject({ busy: true, awaitingResponse: true, streamId: 'owner-stream', turnLive: true })
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.ts
index 932ddbea2ea..a0ddc25e1af 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
@@ -494,6 +494,7 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {
const dropOptimistic = (sid: null | string) => {
if (queueAdmission) { return }
+
if (!sid) {
if (targetIsCurrentView()) {
scope.setMessages(current => current.filter(m => m.id !== optimisticId))
@@ -1004,6 +1005,7 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {
if (queueAdmission) {
notifyError(err, copy.promptFailed)
+
return false
}
diff --git a/apps/desktop/src/store/composer-queue.ts b/apps/desktop/src/store/composer-queue.ts
index be030089a42..6f300e1d9dd 100644
--- a/apps/desktop/src/store/composer-queue.ts
+++ b/apps/desktop/src/store/composer-queue.ts
@@ -1,15 +1,19 @@
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'))
}
diff --git a/apps/desktop/src/store/pending-submissions.ts b/apps/desktop/src/store/pending-submissions.ts
index 6204379aa83..5d2faf38320 100644
--- a/apps/desktop/src/store/pending-submissions.ts
+++ b/apps/desktop/src/store/pending-submissions.ts
@@ -26,6 +26,7 @@ export function reconcilePendingSubmissions(key: string, value: unknown): void {
for (const raw of value) {
if (!raw || typeof raw.admission_id !== 'string' || !['queued', 'started', 'unknown'].includes(raw.status)) { continue }
const id = raw.admission_id
+
if (typeof raw.input_id === 'string') { admissionByInput.set(raw.input_id, id) }
receipts.set(id, { ...known[id], id, text: typeof raw.user === 'string' ? raw.user : known[id]?.text ?? '', status: raw.status })
}