From 151c241cd2cc22c3b10ba8735e44f83fb723a511 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Fri, 2 Oct 2026 23:11:24 -0500 Subject: [PATCH] fix(client-runtime): format subagent descriptions as display names (#14999) --- .../src/state/threadExecution.test.ts | 43 +++++++++++++++++++ .../src/state/threadExecution.ts | 9 +++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/packages/client-runtime/src/state/threadExecution.test.ts b/packages/client-runtime/src/state/threadExecution.test.ts index 70ed818cadc30c6f3f07409e74590c47830a9504..7ebd468400f8793b1ba5bdbb72d6771fd440887e 100644 --- a/packages/client-runtime/src/state/threadExecution.test.ts +++ b/packages/client-runtime/src/state/threadExecution.test.ts @@ -478,6 +478,49 @@ describe("threadRuntimeCanArchive", () => { }); describe("presentPendingBackgroundWork", () => { + it.each(["Subagent:", "Subagent: "])( + "falls back to the subagent noun when %s has no display name", + (description) => { + const presentation = presentPendingBackgroundWork([ + { taskId: "unnamed", kind: "subagent", description }, + ]); + + expect(presentation?.title).toBe("Waiting on a subagent"); + expect(presentation?.items[0]?.label).toBe("subagent"); + }, + ); + + it.each([ + "/root/luna_window_properties", + "Subagent: /root/luna_window_properties", + "/root/parent/luna_window_properties", + ])("uses the subagent display name for %s", (description) => { + const childThreadId = ThreadId.make("thread:luna"); + const presentation = presentPendingBackgroundWork([ + { taskId: "luna", kind: "subagent", description, childThreadId }, + ]); + + expect(presentation).toEqual({ + title: "Waiting on subagent Luna Window Properties", + items: [{ taskId: "luna", kind: "subagent", label: "Luna Window Properties", childThreadId }], + }); + }); + + it("formats subagent names in a mixed roster and preserves command descriptions", () => { + const presentation = presentPendingBackgroundWork([ + { taskId: "cmd", kind: "command", description: "/root/run_tests" }, + { taskId: "luna", kind: "subagent", description: "/root/luna_window_properties" }, + { taskId: "review", kind: "subagent", description: "Review src/math.ts" }, + ]); + + expect(presentation?.title).toBe("Waiting on 2 subagents and 1 command"); + expect(presentation?.items.map((item) => item.label)).toEqual([ + "Luna Window Properties", + "Review src/math.ts", + "/root/run_tests", + ]); + }); + it("names a single piece of work by kind", () => { expect( presentPendingBackgroundWork([ diff --git a/packages/client-runtime/src/state/threadExecution.ts b/packages/client-runtime/src/state/threadExecution.ts index 0893fadb62c25df68e98998149d847d28774e50d..5101acc062ef1f0a5ca0afc538122c0d72b77bbf 100644 --- a/packages/client-runtime/src/state/threadExecution.ts +++ b/packages/client-runtime/src/state/threadExecution.ts @@ -25,6 +25,7 @@ import { type ThreadRunSummary, type ThreadRuntimeSummary, } from "./models.ts"; +import { formatSubagentDisplayTitle } from "./subagentDisplay.ts"; const ACTIVITY_RUN_STATUSES = new Set(["preparing", "starting", "running", "waiting"]); const INTERRUPTIBLE_RUN_STATUSES = new Set(["preparing", "starting", "running"]); @@ -295,13 +296,17 @@ export function presentPendingBackgroundWork( const items = tasks .map((task): PendingBackgroundWorkItem => { const description = task.description?.trim(); + const label = + task.kind === "subagent" && description !== undefined + ? formatSubagentDisplayTitle(description).trim() + : description; return { taskId: task.taskId, kind: task.kind, label: - description === undefined || description.length === 0 + label === undefined || label.length === 0 ? BACKGROUND_WORK_KINDS[task.kind].singular - : description, + : label, childThreadId: task.kind === "subagent" ? task.childThreadId : undefined, }; }) -- 2.54.0