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 @@ -2236,8 +2236,19 @@ describe('useAgentSession (v1 composition root)', () => {
resolution: { status: 'answered', selected: ['flux'] }
})
expect(reportError).toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({ errorType: 'agent_ask_answer_superseded' })
expect.objectContaining({
message: 'agent ask resolved with a different answer'
}),
expect.objectContaining({
errorType: 'agent_ask_answer_superseded',
tags: {
selection_changed: true,
other_text_changed: false,
selection_known: true,
committed_selected_count: 1,
submitted_selected_count: 1
}
})
)
})

Expand Down Expand Up @@ -2340,7 +2351,16 @@ describe('useAgentSession (v1 composition root)', () => {
})
expect(reportError).toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({ errorType: 'agent_ask_answer_superseded' })
expect.objectContaining({
errorType: 'agent_ask_answer_superseded',
tags: {
selection_changed: false,
other_text_changed: true,
selection_known: false,
committed_selected_count: undefined,
submitted_selected_count: 1
}
})
)
expect(session.notices.value).toEqual([
{
Expand Down Expand Up @@ -2536,14 +2556,17 @@ describe('useAgentSession (v1 composition root)', () => {
name: string
committed: Pick<AgentAskResolvedData, 'selected' | 'other_text'>
expected: AskUserResolution
changes: { selection_changed: boolean; other_text_changed: boolean }
}>([
{
name: 'a different option',
changes: { selection_changed: true, other_text_changed: true },
committed: { selected: ['flux'] },
expected: { status: 'answered', selected: ['flux'] }
},
{
name: 'a superset of it',
changes: { selection_changed: true, other_text_changed: false },
committed: { selected: ['sdxl', 'flux'], other_text: 'a LoRA' },
expected: {
status: 'answered',
Expand All @@ -2553,11 +2576,13 @@ describe('useAgentSession (v1 composition root)', () => {
},
{
name: 'a subset of it',
changes: { selection_changed: true, other_text_changed: false },
committed: { selected: [], other_text: 'a LoRA' },
expected: { status: 'answered', selected: [], otherText: 'a LoRA' }
},
{
name: 'free text alone',
changes: { selection_changed: true, other_text_changed: true },
committed: { selected: [], other_text: 'someone else' },
expected: {
status: 'answered',
Expand All @@ -2567,12 +2592,13 @@ describe('useAgentSession (v1 composition root)', () => {
},
{
name: 'the same option with other free text',
changes: { selection_changed: false, other_text_changed: true },
committed: { selected: ['sdxl'], other_text: 'a VAE' },
expected: { status: 'answered', selected: ['sdxl'], otherText: 'a VAE' }
}
])(
'shows the committed answer when $name won',
async ({ committed, expected }) => {
async ({ committed, expected, changes }) => {
const { session, emit } = await parkedOnQuestion()
await session.answerAsk('turn-1:call-1', {
selected: ['sdxl'],
Expand All @@ -2597,7 +2623,10 @@ describe('useAgentSession (v1 composition root)', () => {
expect(shown.resolution).toEqual(expected)
expect(reportError).toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({ errorType: 'agent_ask_answer_superseded' })
expect.objectContaining({
errorType: 'agent_ask_answer_superseded',
tags: expect.objectContaining(changes)
})
)
}
)
Expand Down Expand Up @@ -2925,7 +2954,14 @@ describe('useAgentSession (v1 composition root)', () => {

expect(reportError).toHaveBeenCalledWith(expect.any(Error), {
surface: 'agent',
errorType: 'agent_ask_answer_superseded'
errorType: 'agent_ask_answer_superseded',
tags: {
selection_changed: true,
other_text_changed: false,
selection_known: true,
committed_selected_count: 1,
submitted_selected_count: 1
}
})
expect(session.notices.value).toHaveLength(1)
expect(cardOnScreen()).toBe(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,17 @@ function namesCommittedAnswer({
return Array.isArray(selected) || Boolean(other_text)
}

function isSupersededAnswer(
function diffAnswers(
submitted: AgentAnswerRequest,
committed: Extract<AskUserResolution, { status: 'answered' }>,
selectionKnown: boolean
): boolean {
return (
(selectionKnown &&
xor(submitted.selected, committed.selected).length > 0) ||
(submitted.other_text || undefined) !== committed.otherText
)
) {
return {
selection_changed:
selectionKnown && xor(submitted.selected, committed.selected).length > 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Nit — When the committed source has no selected array (selectionKnown is false), selection_changed is sent as false. That reads as "unchanged" when the real answer is "unknown". The selection_known tag can tell the two apart, but a dashboard filtering on selection_changed:false alone will count the null-selection and free-text-only cases as confirmed same-selection outcomes. Leaving selection_changed undefined in that case, as committed_selected_count already does, would keep the tag accurate on its own.

Raised by 1 of 6 reviewers (claude-opus-5-5-xhigh edge-case).

other_text_changed:
(submitted.other_text || undefined) !== committed.otherText
}
}

let sessionGeneration = 0
Expand Down Expand Up @@ -1595,17 +1596,22 @@ 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, Array.isArray(source.selected))
)
return
reportError(
new Error(
`agent ask resolved as ${committed.selected.join(',')}, not ${submitted.selected.join(',')}`
),
{ surface: 'agent', errorType: 'agent_ask_answer_superseded' }
)
if (submitted === undefined) return
const selectionKnown = Array.isArray(source.selected)
const changes = diffAnswers(submitted, committed, selectionKnown)
if (!changes.selection_changed && !changes.other_text_changed) return
reportError(new Error('agent ask resolved with a different answer'), {
surface: 'agent',
errorType: 'agent_ask_answer_superseded',
tags: {
...changes,
selection_known: selectionKnown,
committed_selected_count: selectionKnown
? committed.selected.length
: undefined,
submitted_selected_count: submitted.selected.length
}
})
pushError(i18n.global.t('agent.runApproval.answerSuperseded'))
}

Expand Down
Loading