Skip to content

Commit 9193b6e

Browse files
saphidclaude
andcommitted
fix(mobile): finished subagents stay reachable from the Agents pill
The Agents pill hid as soon as a turn ended, so a thread's subagents had no entry point once their work finished. Keep showing "N done" until a later turn replaces that roster. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0712398 commit 9193b6e

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎packages/client-runtime/src/state/threadSubagents.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,36 @@ describe("deriveThreadTurnSubagents", () => {
168168
expect(resolveSubagentPillSegment(turn)?.label).toBe("1/2");
169169
});
170170

171+
it("keeps the finished agents reachable while their turn is the latest", () => {
172+
const turn = deriveThreadTurnSubagents({
173+
runs: [finishedRun],
174+
subagents: [
175+
subagent({ id: "a", status: "completed" }),
176+
subagent({ id: "b", status: "failed" }),
177+
],
178+
});
179+
180+
expect(resolveSubagentPillSegment(turn)?.label).toBe("2 done");
181+
});
182+
183+
it("drops finished agents from the pill once a later turn ran without any", () => {
184+
const turn = deriveThreadTurnSubagents({
185+
runs: [finishedRun, run("run-2", "completed")],
186+
subagents: [subagent({ id: "a", status: "completed" })],
187+
});
188+
189+
expect(resolveSubagentPillSegment(turn)).toBeNull();
190+
});
191+
192+
it("shows finished agents again when the later turn was rolled back", () => {
193+
const turn = deriveThreadTurnSubagents({
194+
runs: [finishedRun, run("run-2", "rolled_back")],
195+
subagents: [subagent({ id: "a", status: "completed" })],
196+
});
197+
198+
expect(resolveSubagentPillSegment(turn)?.label).toBe("1 done");
199+
});
200+
171201
it("counts idle as neither working nor done", () => {
172202
const turn = deriveThreadTurnSubagents({
173203
runs: [activeRun],

‎packages/client-runtime/src/state/threadSubagents.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type RunId = Projection["runs"][number]["id"];
1212
export interface ThreadTurnSubagents {
1313
readonly runId: RunId | null;
1414
readonly turnActive: boolean;
15+
/** No later turn has run since these agents' turn. */
16+
readonly latestTurn: boolean;
1517
readonly subagents: ReadonlyArray<Subagent>;
1618
readonly liveCount: number;
1719
readonly settledCount: number;
@@ -51,6 +53,7 @@ export function deriveThreadTurnSubagents(
5153
first,
5254
);
5355
const runId = activeRun?.id ?? latestUpdated.runId;
56+
const latestRunId = projection.runs.findLast((run) => !rolledBackRunIds.has(run.id))?.id ?? null;
5457
const subagents = copySorted(
5558
eligible.filter(
5659
(subagent) => subagent.runId === runId || isActiveSubagentStatus(subagent.status),
@@ -65,14 +68,22 @@ export function deriveThreadTurnSubagents(
6568
if (isActiveSubagentStatus(subagent.status)) liveCount += 1;
6669
else if (isTerminalSubagentStatus(subagent.status)) settledCount += 1;
6770
}
68-
return { runId, turnActive: activeRun !== null, subagents, liveCount, settledCount };
71+
return {
72+
runId,
73+
turnActive: activeRun !== null,
74+
latestTurn: runId === null || runId === latestRunId,
75+
subagents,
76+
liveCount,
77+
settledCount,
78+
};
6979
}
7080

7181
export function resolveSubagentPillSegment(
7282
turn: ThreadTurnSubagents | null,
7383
): SubagentPillSegment | null {
7484
if (turn === null) return null;
75-
if (!turn.turnActive && turn.liveCount === 0) return null;
85+
// Finished agents stay reachable until a later turn replaces them.
86+
if (!turn.turnActive && !turn.latestTurn && turn.liveCount === 0) return null;
7687
const total = turn.subagents.length;
7788
if (turn.liveCount > 0) {
7889
return {

0 commit comments

Comments
 (0)