Skip to content

Commit 0e563b8

Browse files
saphidclaude
andcommitted
fix(mobile): idle Agents pill follows the latest turn and never calls held work done
An earlier turn's background agent finishing late no longer swaps the idle roster away from the latest turn's agents, and a roster with held (idle) agents shows a neutral count instead of "done". Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1eea1f8 commit 0e563b8

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,39 @@ describe("deriveThreadTurnSubagents", () => {
230230
expect(resolveSubagentPillSegment(turn)?.label).toBe("1 done");
231231
});
232232

233+
it("keeps the latest turn's agents when an earlier turn's background agent finishes later", () => {
234+
const turn = deriveThreadTurnSubagents({
235+
runs: [finishedRun, run("run-2", "completed")],
236+
subagents: [
237+
subagent({ id: "late", status: "completed", updatedAt: at("2026-06-20T00:00:09.000Z") }),
238+
subagent({
239+
id: "latest",
240+
runId: RunId.make("run-2"),
241+
status: "completed",
242+
updatedAt: at("2026-06-20T00:00:05.000Z"),
243+
}),
244+
],
245+
});
246+
247+
expect(turn?.subagents.map((entry) => entry.id)).toEqual(["latest"]);
248+
expect(resolveSubagentPillSegment(turn)?.label).toBe("1 done");
249+
});
250+
251+
it("does not call held agents done", () => {
252+
const turn = deriveThreadTurnSubagents({
253+
runs: [finishedRun],
254+
subagents: [
255+
subagent({ id: "a", status: "completed" }),
256+
subagent({ id: "b", status: "idle" }),
257+
],
258+
});
259+
260+
expect(resolveSubagentPillSegment(turn)).toEqual({
261+
label: "2 agents",
262+
accessibilityLabel: "2 agents",
263+
});
264+
});
265+
233266
it("counts idle as neither working nor done", () => {
234267
const turn = deriveThreadTurnSubagents({
235268
runs: [activeRun],

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function orderKey(subagent: Subagent): number {
2929
}
3030

3131
/**
32-
* The pill and sheet include the active run's agents, or the most recently updated agent's run when idle.
32+
* The pill and sheet include the active run's agents. When idle they use the latest started run's
33+
* agents, or else the most recently updated agent's run.
3334
* Include agents still working from other runs so background work stays counted and reachable.
3435
* Exclude rolled-back runs, matching the Waiting strip.
3536
*/
@@ -52,7 +53,6 @@ export function deriveThreadTurnSubagents(
5253
: latest,
5354
first,
5455
);
55-
const runId = activeRun?.id ?? latestUpdated.runId;
5656
// Ordinal, not array position: a reordered queue can leave the projection's runs out of order.
5757
// Queued and never-started runs have not replaced anything yet.
5858
const latestStartedRun = projection.runs.reduce<Projection["runs"][number] | null>(
@@ -64,6 +64,11 @@ export function deriveThreadTurnSubagents(
6464
: latest,
6565
null,
6666
);
67+
const latestStartedRunHasAgents =
68+
latestStartedRun !== null &&
69+
eligible.some((subagent) => subagent.runId === latestStartedRun.id);
70+
const runId =
71+
activeRun?.id ?? (latestStartedRunHasAgents ? latestStartedRun.id : latestUpdated.runId);
6772
const subagents = copySorted(
6873
eligible.filter(
6974
(subagent) => subagent.runId === runId || isActiveSubagentStatus(subagent.status),
@@ -101,8 +106,8 @@ export function resolveSubagentPillSegment(
101106
accessibilityLabel: `${turn.liveCount} of ${total} agents working`,
102107
};
103108
}
104-
return {
105-
label: `${total} done`,
106-
accessibilityLabel: `${total} ${total === 1 ? "agent" : "agents"} done`,
107-
};
109+
const agents = `${total} ${total === 1 ? "agent" : "agents"}`;
110+
// Held (idle) agents have work outstanding, so only an all-terminal roster is "done".
111+
if (turn.settledCount < total) return { label: agents, accessibilityLabel: agents };
112+
return { label: `${total} done`, accessibilityLabel: `${agents} done` };
108113
}

0 commit comments

Comments
 (0)