feat: optimize subagent list children query

This commit is contained in:
imccyu
2026-08-01 14:30:36 +08:00
committed by Tianyi Cui
parent 5d56019d22
commit 8c9cd4c15d
28 changed files with 261 additions and 86 deletions
@@ -28,7 +28,10 @@ function bench(options: {
options.parentLive !== false && id === PARENT ? parent : undefined)
const listChildren = vi.fn(() => options.listError === undefined
? Promise.resolve(options.entries ?? [
{ kind: 'child', id: CHILD, mode: 'continuable', label: 'worker', activity: 'inactive' },
{
kind: 'child', id: CHILD, mode: 'continuable', label: 'worker',
activity: 'inactive', hasChildren: false,
},
])
: Promise.reject(options.listError))
const followup = vi.fn((
@@ -63,8 +66,14 @@ function bench(options: {
describe('subagent gateway', () => {
it('lists the complete catalog and reports exact live-parent availability', async () => {
const { api, listChildren } = bench({ parentLive: false, entries: [
{ kind: 'child', id: CHILD, mode: 'continuable', label: 'worker', activity: 'inactive' },
{ kind: 'child', id: sid('one-shot'), mode: 'one-shot', activity: 'inactive' },
{
kind: 'child', id: CHILD, mode: 'continuable', label: 'worker',
activity: 'inactive', hasChildren: true,
},
{
kind: 'child', id: sid('one-shot'), mode: 'one-shot',
activity: 'inactive', hasChildren: false,
},
{ kind: 'diagnostic', id: sid('bad'), reason: 'corrupt' },
] })
const response = await api.subagents.list(request({ parentSessionId: PARENT }))
@@ -98,7 +107,8 @@ describe('subagent gateway', () => {
it('reads one-shot history and rejects an address with the wrong mode', async () => {
const oneShot = {
kind: 'child', id: CHILD, mode: 'one-shot', label: 'batch', activity: 'inactive',
kind: 'child', id: CHILD, mode: 'one-shot', label: 'batch',
activity: 'inactive', hasChildren: false,
}
const { api, readSession } = bench({ entries: [oneShot] })
expect((await api.subagents.history(request({