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 }