From 5190c8e0bc6da77dca48934d0be313a39d2f4708 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 22 Oct 2026 20:17:40 +0000 Subject: [PATCH] fix(agent): don't report a 409 with no selection as another answer winning (#21320) ## Summary A 409 from the ask answer endpoint can come back with `selected` missing or `null` (`AgentAskConflict.selected` is nullish). `toAskResolution` turns that into an answered resolution with `selected: []`, and the 409 branch always ran the superseded check. So a user who picked an option got a false "answered somewhere else" notice and an `agent_ask_answer_superseded` error report, even though nothing said another answer won. Fix: only run the superseded comparison when the conflict body actually carries a selection array. This is the same guard the 202 path already has (`receipt.selected !== undefined`). The card is still retired with the conflict's status, as before. Found by the cursor-review panel on the 1.57 backports of #19981/#20092 (https://github.com/Comfy-Org/ComfyUI_frontend/pull/21308, https://github.com/Comfy-Org/ComfyUI_frontend/pull/21309). The code there is identical to main, so this fix goes to main first and is backported after those land. ## Tests - New: `does not report a 409 with no selection as another answer winning` and `... with a null selection ...` in `useAgentSession.test.ts`. Both fail on main before the fix (`reportError` called with `agent_ask_answer_superseded`) and pass after. - Existing `shows the answer a 409 reports as already committed` (409 that names another selection) still reports superseded. - `useAgentSession.test.ts`: 253 pass. The one failure is the known order-dependent `(g18)` test, which fails on main without this change (https://linear.app/comfyorg/issue/FE-3485). --- .../composables/agent/useAgentSession.test.ts | 24 +++++++++++++++++++ .../composables/agent/useAgentSession.ts | 10 ++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts index f68ec9687cd..adc65efafad 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.test.ts @@ -2269,6 +2269,30 @@ describe('useAgentSession (v1 composition root)', () => { ) }) + it.for([ + ['no selection', { error: 'already answered', status: 'answered' }], + [ + 'a null selection', + { error: 'already answered', status: 'answered', selected: null } + ] + ] as const)( + 'does not report a 409 with %s as another answer winning', + 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(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 dfc89b5f7e3..01bf9dde1dc 100644 --- a/src/workbench/extensions/agent/composables/agent/useAgentSession.ts +++ b/src/workbench/extensions/agent/composables/agent/useAgentSession.ts @@ -1535,10 +1535,12 @@ export function useAgentSession(deps: AgentSessionDeps) { threadId: string ): void { if (error instanceof AgentApiError && error.status === 409) { - const committed = toAskResolution( - zAgentAskConflict.safeParse(error.body).data ?? {} - ) - reportSupersededAnswer(askId, committed) + 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) return }