From f0229bf33a0d8b2608c95244b1637d19c96922b9 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 23 Oct 2026 19:35:47 +0000 Subject: [PATCH 1/3] fix(agent): report a free-text-only answer that won elsewhere #21320 skipped the superseded check on a 409 unless the conflict body carried a `selected` array. The schema allows a committed free-text-only answer (`status: answered`, `selected` null or omitted, `other_text` set), so a user whose answer lost to someone else's free text got no "answered somewhere else" notice and no telemetry. The rule "a body that names no answer cannot show another answer won" now lives in one predicate, `namesCommittedAnswer` (a `selected` array or non-empty `other_text`), checked inside `reportSupersededAnswer`, so the 202 receipt, the 409 conflict and the `agent_ask_resolved` frame all use it. The frame path previously had no guard, so an answered frame with a null selection also raised a false superseded report. Follow-up to the cursor-review findings on #21320. --- .../composables/agent/useAgentSession.test.ts | 61 +++++++++++++++++++ .../composables/agent/useAgentSession.ts | 36 +++++++---- 2 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts index 503d3a05d10..f1d1d42d0b2 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts @@ -2305,6 +2305,67 @@ describe('useAgentSession (v1 composition root)', () => { } ) + it.for([ + [ + 'a null selection', + { + error: 'already answered', + status: 'answered', + selected: null, + other_text: 'someone else' + } + ], + [ + 'no selection', + { + error: 'already answered', + status: 'answered', + other_text: 'someone else' + } + ] + ] as const)( + 'reports a 409 whose free text alone shows another answer won (%s)', + async ([, body]) => { + const { session, answerAsk } = await parkedOnQuestion() + answerAsk.mockRejectedValue( + new AgentApiError('already answered', 409, body) + ) + + await session.answerAsk('turn-1:call-1', { selected: ['sdxl'] }) + + expect(card()).toMatchObject({ + resolution: { + status: 'answered', + selected: [], + otherText: 'someone else' + } + }) + expect(reportError).toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ errorType: 'agent_ask_answer_superseded' }) + ) + expect(session.notices.value).toEqual([ + { + level: 'error', + text: enMessages.agent.runApproval.answerSuperseded + } + ]) + } + ) + + it('does not report an answered frame with a null selection as another answer winning', async () => { + const { session, emit } = await parkedOnQuestion() + await session.answerAsk('turn-1:call-1', { selected: ['sdxl'] }) + + emit(askResolved('msg-1', 'turn-1:call-1', null)) + + expect(reportError).not.toHaveBeenCalledWith( + expect.any(Error), + expect.objectContaining({ errorType: 'agent_ask_answer_superseded' }) + ) + expect(session.notices.value).toEqual([]) + }) + it('puts the card back in service when the server rejects the selection', async () => { const { session, answerAsk } = await parkedOnQuestion() answerAsk.mockRejectedValueOnce( diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts index 0d425a98c2b..ef2d395dd60 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts @@ -1,5 +1,8 @@ import { zAgentAskConflict } from '@comfyorg/ingest-types/zod' -import type { AgentAnswerRequest } from '@comfyorg/ingest-types' +import type { + AgentAnswerRequest, + AgentAskConflict +} from '@comfyorg/ingest-types' import { useIntervalFn } from '@vueuse/core' import { delay, xor } from 'es-toolkit' import { computed, ref, watch } from 'vue' @@ -347,6 +350,18 @@ function isRetryableAnswerFailure(error: unknown): boolean { return error instanceof TypeError || error instanceof DOMException } +type CommittedAnswerSource = Pick< + AgentAskConflict, + 'status' | 'selected' | 'other_text' +> + +function namesCommittedAnswer({ + selected, + other_text +}: CommittedAnswerSource): boolean { + return Array.isArray(selected) || Boolean(other_text) +} + function isSupersededAnswer( submitted: AgentAnswerRequest, committed: Extract @@ -1533,8 +1548,7 @@ export function useAgentSession(deps: AgentSessionDeps) { try { const receipt = await sendAnswer(currentThreadId, askId, answer) const committed = toAskResolution(receipt) - if (receipt.selected !== undefined) - reportSupersededAnswer(askId, committed) + reportSupersededAnswer(askId, receipt) conversationStore.commitAsk(askId, currentThreadId, committed) return true } catch (error) { @@ -1550,13 +1564,9 @@ export function useAgentSession(deps: AgentSessionDeps) { threadId: string ): void { if (error instanceof AgentApiError && error.status === 409) { - const conflict = zAgentAskConflict.safeParse(error.body).data - const committed = toAskResolution(conflict ?? {}) - // Same guard as the 202: a conflict that names no selection cannot - // show that another answer won. - if (Array.isArray(conflict?.selected)) - reportSupersededAnswer(askId, committed) - conversationStore.retireAsk(askId, committed, threadId) + const conflict = zAgentAskConflict.safeParse(error.body).data ?? {} + reportSupersededAnswer(askId, conflict) + conversationStore.retireAsk(askId, toAskResolution(conflict), threadId) return } const failure = classifyAnswerFailure(error) @@ -1587,8 +1597,10 @@ export function useAgentSession(deps: AgentSessionDeps) { function reportSupersededAnswer( askId: string, - committed: AskUserResolution + source: CommittedAnswerSource ): void { + if (!namesCommittedAnswer(source)) return + const committed = toAskResolution(source) if (committed.status !== 'answered') return const submitted = conversationStore.takeSubmittedAskAnswer(askId) if (submitted === undefined || !isSupersededAnswer(submitted, committed)) @@ -1804,7 +1816,7 @@ export function useAgentSession(deps: AgentSessionDeps) { observeLiveDelivery(event) if (event.type === 'agent_ask_resolved') { const resolution = toAskResolution(event.data) - reportSupersededAnswer(event.data.ask_id, resolution) + reportSupersededAnswer(event.data.ask_id, event.data) conversationStore.retireAsk( event.data.ask_id, resolution, From 79dd433ba2691def7c70210ce67a8afedc9d0c47 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 23 Oct 2026 19:51:08 +0000 Subject: [PATCH 2/3] test(agent): pin free-text-only 202 receipts and frames Covers the 202 receipt that names only free text (now reported when it differs) and the documented free-text-only frame shape (selected [] plus other_text). Derives the source type from toAskResolution instead of repeating its Pick. --- .../composables/agent/useAgentSession.test.ts | 50 +++++++++++++++++++ .../composables/agent/useAgentSession.ts | 10 +--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts index f1d1d42d0b2..0fd0276089e 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts @@ -2353,6 +2353,56 @@ describe('useAgentSession (v1 composition root)', () => { } ) + it.for([ + ['reports', 'someone else', true], + ['does not report', 'a LoRA', false] + ] as const)( + '%s a 202 that names only free text (%s)', + async ([, otherText, superseded]) => { + const { session } = await parkedOnQuestion({ + status: 'answered', + other_text: otherText + }) + + await session.answerAsk('turn-1:call-1', { + selected: [], + other_text: 'a LoRA' + }) + + expect(session.notices.value).toHaveLength(superseded ? 1 : 0) + } + ) + + it.for([ + ['reports', 'someone else', true], + ['does not report', 'a LoRA', false] + ] as const)( + '%s a free-text-only frame (%s)', + async ([, otherText, superseded]) => { + const { session, emit } = await parkedOnQuestion() + await session.answerAsk('turn-1:call-1', { + selected: [], + other_text: 'a LoRA' + }) + + emit( + wire({ + type: 'agent_ask_resolved', + data: { + thread_id: 'th-1', + message_id: 'msg-1', + ask_id: 'turn-1:call-1', + status: 'answered', + selected: [], + other_text: otherText + } + }) + ) + + expect(session.notices.value).toHaveLength(superseded ? 1 : 0) + } + ) + it('does not report an answered frame with a null selection as another answer winning', async () => { const { session, emit } = await parkedOnQuestion() await session.answerAsk('turn-1:call-1', { selected: ['sdxl'] }) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts index ef2d395dd60..65d4e050a3b 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts @@ -1,8 +1,5 @@ import { zAgentAskConflict } from '@comfyorg/ingest-types/zod' -import type { - AgentAnswerRequest, - AgentAskConflict -} from '@comfyorg/ingest-types' +import type { AgentAnswerRequest } from '@comfyorg/ingest-types' import { useIntervalFn } from '@vueuse/core' import { delay, xor } from 'es-toolkit' import { computed, ref, watch } from 'vue' @@ -350,10 +347,7 @@ function isRetryableAnswerFailure(error: unknown): boolean { return error instanceof TypeError || error instanceof DOMException } -type CommittedAnswerSource = Pick< - AgentAskConflict, - 'status' | 'selected' | 'other_text' -> +type CommittedAnswerSource = Parameters[0] function namesCommittedAnswer({ selected, From 8338ce5dfc6feb2b865b669a6f6a4059cdbb1865 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 23 Oct 2026 20:11:20 +0000 Subject: [PATCH 3/3] fix(agent): compare only free text when the committed selection is unknown A source that names free text but no selection array cannot show the user's options lost, so only the free text is compared. Without this, a 409, frame or 202 naming the user's own free text with no selection raised a false superseded notice. --- .../composables/agent/useAgentSession.test.ts | 18 ++++++++++++++++++ .../agent/composables/agent/useAgentSession.ts | 11 ++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts index 0fd0276089e..7d188ed2196 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts @@ -2403,6 +2403,24 @@ describe('useAgentSession (v1 composition root)', () => { } ) + it('does not report a 409 naming only the same free text as another answer winning', async () => { + const { session, answerAsk } = await parkedOnQuestion() + answerAsk.mockRejectedValue( + new AgentApiError('already answered', 409, { + error: 'already answered', + status: 'answered', + other_text: 'a LoRA' + }) + ) + + await session.answerAsk('turn-1:call-1', { + selected: ['sdxl'], + other_text: 'a LoRA' + }) + + expect(session.notices.value).toEqual([]) + }) + it('does not report an answered frame with a null selection as another answer winning', async () => { const { session, emit } = await parkedOnQuestion() await session.answerAsk('turn-1:call-1', { selected: ['sdxl'] }) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts index 65d4e050a3b..d1e2d408a87 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts @@ -358,10 +358,12 @@ function namesCommittedAnswer({ function isSupersededAnswer( submitted: AgentAnswerRequest, - committed: Extract + committed: Extract, + selectionKnown: boolean ): boolean { return ( - xor(submitted.selected, committed.selected).length > 0 || + (selectionKnown && + xor(submitted.selected, committed.selected).length > 0) || (submitted.other_text || undefined) !== committed.otherText ) } @@ -1597,7 +1599,10 @@ export function useAgentSession(deps: AgentSessionDeps) { const committed = toAskResolution(source) if (committed.status !== 'answered') return const submitted = conversationStore.takeSubmittedAskAnswer(askId) - if (submitted === undefined || !isSupersededAnswer(submitted, committed)) + if ( + submitted === undefined || + !isSupersededAnswer(submitted, committed, Array.isArray(source.selected)) + ) return reportError( new Error(