diff --git a/src/client/tasks-model.ts b/src/client/tasks-model.ts index 28610b7d..1e2ab2cf 100644 --- a/src/client/tasks-model.ts +++ b/src/client/tasks-model.ts @@ -364,7 +364,20 @@ export function buildTasksModel(input: TasksModelInput): TasksNode[] { // reports EVERY child with an explicit `running` flag, and a row keeps // its disclosure unless its own catalog is known-empty. const view = childLive(live, entry.id) - const activity: 'running' | 'inactive' = view?.running === true ? 'running' : 'inactive' + // …but that flag is SESSION RESIDENCY, not "an agent is running": the + // host's own field doc says it means "recursive catalog listing observed + // a resident Session … does not encode a durable outcome or guarantee + // continuation delivery". After a crash-restart, opening a child's + // history retains its session WITHOUT starting an agent, so residency + // reads `running` for a child nothing is driving (issue #800: the card + // showed 运行中 with a live preview line for an interrupted subagent). + // The session summary's `running` is the authoritative run bit — the root + // card below reads it, so does DSH's own subagent dropdown, and + // ./subagent-lineage.ts already counts descendants from it — so it wins + // whenever the host reports the field; the catalog flag stays the + // fallback for a deployment whose summaries do not carry it. + const running = summary?.running ?? (view?.running === true) + const activity: 'running' | 'inactive' = running ? 'running' : 'inactive' const state: TasksNodeState = activity === 'running' ? 'running' : team !== undefined ? teamState(team.status) : 'done' diff --git a/src/client/team-projection.ts b/src/client/team-projection.ts index ee5ebaab..358d6c22 100644 --- a/src/client/team-projection.ts +++ b/src/client/team-projection.ts @@ -117,6 +117,11 @@ function memberStatus( ): TeamMemberRow['status'] { if (member.phase === 'failed') return 'failed' if (member.phase === 'provisioning') return 'provisioning' - const running = live[member.id]?.running ?? byId[member.id]?.running + // The summary's `running` is the authoritative run bit; the live channel's + // flag is the catalog's RESIDENCY, which reads `running` for a retained + // session that no agent is driving (a crash-restart — issue #800). Same rule + // as the task tree: authoritative wins, the live flag only stands in when the + // host's summaries do not carry the field. + const running = byId[member.id]?.running ?? live[member.id]?.running return running === true ? 'running' : 'idle' } diff --git a/tests/tasks-page.spec.tsx b/tests/tasks-page.spec.tsx index 090427ff..6e43e24f 100644 --- a/tests/tasks-page.spec.tsx +++ b/tests/tasks-page.spec.tsx @@ -805,7 +805,12 @@ describe('Tasks page: the shared task window', () => { summary: { counts: [{ kind: 'read', count: 2 }], runningDetail: '' }, }, } - const store = makeStore(snapshotWithChildren(2)) + // A running child says so in BOTH channels: the live flag is the catalog's + // session RESIDENCY, the summary's `running` is the authoritative run bit + // (see the #800 case below for what residency alone means after a restart). + const snapshot = snapshotWithChildren(2) + snapshot.byId['child-0']!.running = true + const store = makeStore(snapshot) const { container, unmount } = renderRoot( createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }), ) @@ -825,6 +830,46 @@ describe('Tasks page: the shared task window', () => { unmount() }) + it('a retained-but-not-running child is NOT a running card (issue #800)', async () => { + // After a crash-restart, opening an interrupted child's history RETAINS its + // session without starting an agent: the catalog's `activity` — which the + // live channel reports as `running` — flips to running while the + // authoritative summary still says `running: false`. The card must follow + // the summary; the old reading showed 运行中 (with a live preview line) for a + // subagent nothing was driving. + livePayload = { 'child-0': { running: true, text: 'half-finished line' } } + const store = makeStore(snapshotWithChildren(2)) + const { container, unmount } = renderRoot( + createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }), + ) + await flushJobs() + // Both children are settled now, so the global fold holds them: unfold. + const foldToggle = container.querySelector('button[aria-label="展开已完成的节点"]') as HTMLButtonElement + await act(async () => { foldToggle.click() }) + const child = container.querySelector('[data-graph-node="child-0"]') as HTMLElement + expect(child).not.toBeNull() + const bar = child.querySelector('[data-card-bar]') as HTMLElement + expect(bar.getAttribute('data-running')).toBeNull() + expect(bar.textContent).toContain('已完成') + unmount() + }) + + it('falls back to the catalog flag when the host carries no summary running bit', async () => { + // Older hosts: the summary has no `running` field, so the live channel's + // flag is all there is — the pre-#800 reading must survive. + livePayload = { 'child-0': { running: true, summary: { counts: [], runningDetail: '' } } } + const snapshot = snapshotWithChildren(2) + delete snapshot.byId['child-0']!.running + const store = makeStore(snapshot) + const { container, unmount } = renderRoot( + createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }), + ) + await flushJobs() + const bar = container.querySelector('[data-graph-node="child-0"] [data-card-bar]') as HTMLElement + expect(bar.getAttribute('data-running')).toBe('true') + unmount() + }) + it('folds one settled card into the aggregate from its bar, and expands it back', async () => { const store = makeStore(snapshotWithChildren(3)) const { container, unmount } = renderRoot( @@ -936,7 +981,9 @@ describe('Tasks page: the shared task window', () => { it('offers no fold chevron on a running card or on the current session', async () => { livePayload = { 'child-0': { running: true, summary: { counts: [], runningDetail: '' } } } - const store = makeStore(snapshotWithChildren(2)) + const snapshot = snapshotWithChildren(2) + snapshot.byId['child-0']!.running = true + const store = makeStore(snapshot) const { container, unmount } = renderRoot( createElement(SubagentView, { sessionId: 'root', active: true, ctx: makeCtx(store) }), ) diff --git a/tests/team-projection.spec.ts b/tests/team-projection.spec.ts index f6350a47..5ce159eb 100644 --- a/tests/team-projection.spec.ts +++ b/tests/team-projection.spec.ts @@ -104,6 +104,21 @@ describe('teamMembersOf', () => { expect(failed[0]?.status).toBe('failed') }) + it('ignores the live channel residency when the summary says the agent is not running (issue #800)', () => { + // The live flag is the catalog's SESSION RESIDENCY: a retained session + // whose agent died in a crash-restart reads `running` there while the + // authoritative summary stays false. The summary wins. + const live: Record = { w: { running: true } } + const byId = { w: summary('w', { running: false }) } + expect(teamMembersOf(team(), live, byId)[0]?.status).toBe('idle') + }) + + it('takes the Summary running bit even when the live channel says otherwise', () => { + const live: Record = { w: { running: false } } + const byId = { w: summary('w', { running: true }) } + expect(teamMembersOf(team(), live, byId)[0]?.status).toBe('running') + }) + it('exposes the durable member error as the diagnostics list', () => { const rows = teamMembersOf( team({ members: [member({ phase: 'failed', error: 'spawn rejected' })] }),