From e38aa56fec3961adb0a514edd97e603858a5b8dd Mon Sep 17 00:00:00 2001 From: ZinChl <123862319+ZinChl@users.noreply.github.com> Date: Wed, 30 Sep 2026 02:24:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(tasks):=20=E4=BC=9A=E8=AF=9D=E3=80=8C?= =?UTF-8?q?=E9=A9=BB=E7=95=99=E3=80=8D=E4=B8=8D=E5=86=8D=E5=BD=93=E4=BD=9C?= =?UTF-8?q?=E3=80=8Cagent=20=E5=9C=A8=E8=B7=91=E3=80=8D=E2=80=94=E2=80=94?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=87=8D=E5=90=AF=E5=90=8E=E7=9A=84=E5=AD=90?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=8A=B6=E6=80=81=EF=BC=88#800=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 宿主目录行的 `activity` 是**会话驻留**而非运行态(宿主自己的字段注释: "recursive catalog listing observed a resident Session … does not encode a durable outcome or guarantee continuation delivery")。崩溃重启后,DSH 打开 被中断子会话的历史流会把它 prepare → retain → attach 成驻留 Session,但不会 启动 agent,于是 `activity === 'running'` 成立、卡片显示「运行中」并附带实时 预览行,而实际上没有任何东西在跑。 权威运行位其实早就在手边:会话摘要的 `running`(根卡片已经在用, `subagent-lineage` 统计后代也在用,DSH 官方子代理下拉同样用它)。改为 「摘要的 running 优先、目录标志兜底」: - `src/client/tasks-model.ts`:子节点 activity/state 由 `summary.running ?? (view.running === true)` 决定。摘要没有该字段的老宿主 继续走目录标志,行为不变。 - `src/client/team-projection.ts`:同一规则(原先恰好相反,优先了驻留标志)。 测试: - `tests/tasks-page.spec.tsx` 新增两条:驻留但未运行 → 不是 running 卡片 (旧代码下断言 `data-running` 为 null 会红);摘要无 running 字段 → 回落到 目录标志(旧行为保留)。同时把两条既有用例的 fixture 修正为两路一致 (原先 live 说 running、摘要说 false,本身自相矛盾)。 - `tests/team-projection.spec.ts` 新增两条:摘要 false + live true → idle; 摘要 true + live false → running。 --- src/client/tasks-model.ts | 15 ++++++++++- src/client/team-projection.ts | 7 ++++- tests/tasks-page.spec.tsx | 51 +++++++++++++++++++++++++++++++++-- tests/team-projection.spec.ts | 15 +++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-) 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' })] }),