Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading