The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): clear a shared prompt card when another window answers it
Teknium4f11ec5d9d12
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.settled.test.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.settled.test.tsnew file mode 100644index 00000000000..9eb5a0a5aee--- /dev/null+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.settled.test.ts@@ -0,0 +1,39 @@+import { afterEach, describe, expect, it, vi } from 'vitest'++import { $approvalRequests, clearApprovalRequest, setApprovalRequest } from '@/store/prompts'++import { handleInputRequestEvent } from './input-requests'+import type { GatewayEventContext } from './types'++// A canonical gateway fans one approval out to every attached window; whichever window+// answers, the authority publishes `approval.settled {prompt_id}`. Every other window's+// Run/Reject bar must come down then, not stay parked on a prompt nobody can answer.+function settled(promptId: string): GatewayEventContext {+ const payload = { prompt_id: promptId, execution_generation: 3 }++ return {+ deps: { flushQueuedDeltas: vi.fn(), updateSessionState: vi.fn() } as unknown as GatewayEventContext['deps'],+ event: { payload, session_id: 's1', type: 'approval.settled' } as unknown as GatewayEventContext['event'],+ explicitSid: 's1',+ fromActiveSource: () => true,+ isActiveEvent: true,+ occurredAt: 1_700_000_000,+ payload: payload as unknown as GatewayEventContext['payload'],+ scheduleConfigRefresh: vi.fn(),+ sessionId: 's1'+ }+}++describe('canonical approval.settled', () => {+ afterEach(() => clearApprovalRequest('s1'))++ it('clears the bar a peer window answered and leaves other prompts alone', () => {+ setApprovalRequest({ sessionId: 's1', command: 'rm a', description: '', requestId: 'p-1', serverRequestId: 'p-1' })+ setApprovalRequest({ sessionId: 's1', command: 'rm b', description: '', requestId: 'p-2', serverRequestId: 'p-2' })++ expect(handleInputRequestEvent(settled('p-1'))).toBe(true)+ expect($approvalRequests.get()['s1']?.requestId).toBe('p-2')+ clearApprovalRequest('s1', 'p-2')+ expect($approvalRequests.get()['s1']).toBeUndefined()+ })+})diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.tsindex 8cf53335235..d608fb25517 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts@@ -96,6 +96,44 @@ export function handleInputRequestEvent(ctx: GatewayEventContext): boolean {return true}+ // Canonical gateways settle a shared prompt with `approval.settled` /+ // `clarify.settled {prompt_id}` once ANY attached viewer answered it (or the+ // turn ended). The prompt id is the server request id this window parked the+ // card under. Only the parked card comes down: the answer itself reaches the+ // transcript through the tool's own completion, so no "skipped" projection.+ if (event.type === 'approval.settled' || event.type === 'clarify.settled') {+ const promptId = (payload as { prompt_id?: unknown } | undefined)?.prompt_id++ if (typeof promptId !== 'string' || !promptId) {+ return true+ }++ forgetServerRequest(promptId)+ const key = sessionId ?? ''++ if (event.type === 'clarify.settled') {+ if ($clarifyRequests.get()[key]?.requestId === promptId) {+ clearClarifyRequest(promptId, sessionId)++ if (sessionId) {+ deps.updateSessionState(sessionId, state => ({ ...state, needsInput: false }))+ }+ }++ return true+ }++ const approval = sessionApprovalRequests(sessionId ?? null)+ .get()+ .find(request => request.serverRequestId === promptId)++ if (approval) {+ clearApprovalRequest(sessionId, approval.requestId)+ }++ return true+ }+if (event.type !== 'request.cancel') {return false}