The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve connection request for /btw
Charan Rathore06cc14bca327
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.tsxindex df09c60eb3c..96f8e0deafc 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@@ -2,10 +2,13 @@ import { act, cleanup, renderHook, waitFor } from '@testing-library/react'import { type Dispatch, type PropsWithChildren, type SetStateAction, useLayoutEffect, useState } from 'react'import { afterEach, describe, expect, it, vi } from 'vitest'+import * as sessionOwnerUtils from '@/app/session/hooks/use-session-actions/utils'import { PaneVisibleContext } from '@/components/pane-shell/pane-visibility'import { $clarifyRequests } from '@/store/clarify'import type { ComposerAttachment } from '@/store/composer'import { clearQueuedPrompts, getQueuedPrompts } from '@/store/composer-queue'+import { $connectionRequests, type ConnectionRequest } from '@/store/connection-request'+import { $gateway } from '@/store/gateway'import {clearAllPrompts,hasBlockingPromptRequest,@@ -583,6 +586,87 @@ describe('useComposerSubmit with a clarify parked on the session', () => {})})+describe('useComposerSubmit with a connection card parked on the session', () => {+ afterEach(() => {+ cleanup()+ $connectionRequests.set({})+ $gateway.set(null)+ vi.restoreAllMocks()+ })++ const parkConnection = () => {+ const connection: ConnectionRequest = {+ toolCallId: 'call-connection',+ opId: 'op-connection',+ seq: 1,+ deadlineAt: 1_800_000_000,+ sessionId: 'runtime-session',+ targets: [+ {+ name: 'gmail',+ kind: 'connector',+ action: 'connect',+ state: 'pending',+ detail: '',+ connectUrl: null,+ connectionId: '',+ tools: [],+ requiredEnv: [],+ instructions: null,+ discoveryError: null+ }+ ],+ settled: false,+ settledBy: null+ }++ $connectionRequests.set({ 'runtime-session': connection })+ }++ it.each(['/btw what is the task?', '/BTW what is the task?', '/btw'])(+ 'keeps the connection card answerable while dispatching %s',+ async text => {+ parkConnection()+ vi.spyOn(sessionOwnerUtils, 'resolveSessionOwner').mockRejectedValue(new Error('test no owner'))+ const gatewayRequest = vi.fn(async () => ({}))+ $gateway.set({ request: gatewayRequest } as NonNullable<ReturnType<typeof $gateway.get>>)+ const { hook, onSubmit, onSteer } = renderSubmitHook({ busy: true, text })++ act(() => {+ hook.result.current.submitDraft()+ })++ await waitFor(() => expect(onSubmit).toHaveBeenCalledWith(text, expect.anything()))+ expect(onSteer).not.toHaveBeenCalled()+ expect(gatewayRequest).not.toHaveBeenCalledWith('connection.respond', expect.anything())+ expect($connectionRequests.get()['runtime-session']?.settled).toBe(false)+ }+ )++ it('still continues the connection request for an ordinary reply', async () => {+ parkConnection()+ vi.spyOn(sessionOwnerUtils, 'resolveSessionOwner').mockRejectedValue(new Error('test no owner'))+ const gatewayRequest = vi.fn(async () => ({}))+ $gateway.set({ request: gatewayRequest } as NonNullable<ReturnType<typeof $gateway.get>>)+ const { hook, onSteer } = renderSubmitHook({ busy: true, text: 'continue without connecting' })++ act(() => {+ hook.result.current.submitDraft()+ })++ await waitFor(() => expect(onSteer).toHaveBeenCalledWith('continue without connecting'))+ await waitFor(() =>+ expect(gatewayRequest).toHaveBeenCalledWith(+ 'connection.respond',+ expect.objectContaining({+ op_id: 'op-connection',+ result: { settled_by: 'continue' }+ })+ )+ )+ })+})+describe('useComposerSubmit with a blocking prompt parked on the session', () => {// Typing cannot answer approval/sudo/secret prompts, so the busy submit must// route text to the QUEUE — a steer would sit undelivered behind the blockeddiff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.tsindex 02e9ff8bdef..1b5c26a5fff 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@@ -225,19 +225,20 @@ export function useComposerSubmit({// (default 5 min) — the message looks sent and nothing happens. Typing a// real message instead of picking an option IS the answer "none of these":// skip the question so the tool returns, then route the words normally.- // /btw is a side question, not a reply to clarify.//// Fire-and-forget, not awaited: the skip clears the card synchronously and// both RPCs ride the same socket in call order, so the gateway resolves the- // clarify before it sees the follow-up. /btw takes the separate slash path.- // Awaiting first would leave the draft+ // clarify before it sees the follow-up. Awaiting first would leave the draft// live for a tick — long enough for a second Enter to send it twice.- if (payloadPresent && !queueEdit && !/^\/btw(?:\s|$)/i.test(text.trim()) && hasClarifyRequest(sessionId)) {+ // /btw takes a separate side-question path and answers neither parked card.+ const isSideQuestion = /^\/btw(?:\s|$)/i.test(text.trim())++ if (payloadPresent && !queueEdit && !isSideQuestion && hasClarifyRequest(sessionId)) {void skipClarifyRequest(sessionId)}- // Same for a pending connection card: typing declines every target.- if (payloadPresent && !queueEdit && hasConnectionRequest(sessionId)) {+ // Same for a pending connection card: ordinary typing continues the operation.+ if (payloadPresent && !queueEdit && !isSideQuestion && hasConnectionRequest(sessionId)) {void skipConnectionRequest(sessionId)}