Skip to content
Closed
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
37 changes: 37 additions & 0 deletions apps/desktop/src/store/subagents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,41 @@ describe('subagent store', () => {
.sort()
).toEqual(['c', 'd'])
})

// Regression test for #73728: backend terminal statuses like `timeout` and
// `error` were normalised to `running`, making timed-out subagents immortal
// in the active status stack. `cancelled`/`canceled` must also map to
// `interrupted`.
it('normalises backend terminal statuses to recognised SubagentStatus values', () => {
upsertSubagent('s1', { goal: 'a', status: 'running', subagent_id: 'a', task_index: 0 })
upsertSubagent('s1', { goal: 'b', status: 'running', subagent_id: 'b', task_index: 1 })
upsertSubagent('s1', { goal: 'c', status: 'running', subagent_id: 'c', task_index: 2 })
upsertSubagent('s1', { goal: 'd', status: 'running', subagent_id: 'd', task_index: 3 })

// Emit terminal events with backend-native status strings
upsertSubagent('s1', { status: 'timeout', subagent_id: 'a', task_index: 0, summary: 'timed out' }, false, 'subagent.complete')
upsertSubagent('s1', { status: 'error', subagent_id: 'b', task_index: 1, summary: 'errored' }, false, 'subagent.complete')
upsertSubagent('s1', { status: 'cancelled', subagent_id: 'c', task_index: 2 }, false, 'subagent.complete')
upsertSubagent('s1', { status: 'canceled', subagent_id: 'd', task_index: 3 }, false, 'subagent.complete')

const items = listFor('s1')
const byId = Object.fromEntries(items.map(i => [i.id, i]))

// timeout → failed
expect(byId['a']?.status).toBe('failed')
expect(byId['a']?.currentTool).toBeUndefined()

// error → failed
expect(byId['b']?.status).toBe('failed')

// cancelled → interrupted
expect(byId['c']?.status).toBe('interrupted')

// canceled → interrupted
expect(byId['d']?.status).toBe('interrupted')

// All four are terminal — prune should remove them all
pruneFinishedSessionSubagents('s1')
expect(listFor('s1')).toHaveLength(0)
})
})
8 changes: 6 additions & 2 deletions apps/desktop/src/store/subagents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ const str = (v: unknown) => (isStr(v) ? v : '')
const num = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined)
const strList = (v: unknown) => (Array.isArray(v) ? v.filter(isStr) : [])

const asStatus = (v: unknown): SubagentStatus =>
v === 'completed' || v === 'failed' || v === 'interrupted' || v === 'queued' ? v : 'running'
const asStatus = (v: unknown): SubagentStatus => {
if (v === 'completed' || v === 'failed' || v === 'interrupted' || v === 'queued') return v
if (v === 'timeout' || v === 'error') return 'failed'
if (v === 'cancelled' || v === 'canceled') return 'interrupted'
return 'running'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

asStatus() cannot distinguish a progress update from subagent.complete. Please map an unknown value on a completion event to failed (and test pruning it), while keeping unknown nonterminal events as running; otherwise a future terminal backend status recreates the stuck-active-row bug.

}

const compact = (text: string, max = PREVIEW_MAX) => {
const line = text.replace(/\s+/g, ' ').trim()
Expand Down