Skip to content

Commit 6dcaf6c

Browse files
t3dotggclaude
andauthored
fix(web): remote subagents no longer split from the lineage list (#29285)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 9899b47 commit 6dcaf6c

2 files changed

Lines changed: 65 additions & 38 deletions

File tree

‎apps/web/src/components/chat/ThreadRelationshipsControl.browser.test.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ it("shows a remote subagent's full title in its tooltip even when its environmen
310310
{ router: "/environment/fork" },
311311
);
312312

313+
// A finished remote task sits with the other finished agents, not in its own list.
314+
await expect
315+
.element(screen.getByRole("button", { name: new RegExp(longTitle) }))
316+
.not.toBeInTheDocument();
317+
await screen.getByRole("button", { name: /Previous agents/ }).click();
313318
const row = screen.getByRole("button", { name: new RegExp(longTitle) });
314319
await userEvent.hover(row);
315320
await vi.waitFor(() =>

‎apps/web/src/components/chat/ThreadRelationshipsControl.tsx‎

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,32 @@ function ThreadLineageRowList(props: {
136136
);
137137
}
138138

139-
function ThreadLineageGroup(props: {
139+
type RemoteSubagent = OrchestrationV2Subagent & {
140+
readonly remoteChild: OrchestrationV2RemoteTaskChild;
141+
};
142+
143+
/** A task delegated to a linked environment has no thread here, so it gets its own row kind. */
144+
type LineageRow = ThreadRelationshipWalkRow | { readonly remote: RemoteSubagent };
145+
146+
const lineageRowStatus = (row: LineageRow) =>
147+
"remote" in row ? row.remote.status : row.edge.status;
148+
149+
const isFinishedAgentStatus = (status: string | null | undefined) =>
150+
["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(status ?? "");
151+
152+
function ThreadLineageGroup<Row extends LineageRow>(props: {
140153
readonly label: string | null;
141-
readonly rows: ReadonlyArray<ThreadRelationshipWalkRow>;
154+
readonly rows: ReadonlyArray<Row>;
142155
readonly expanded: boolean;
143-
readonly children: (rows: ReadonlyArray<ThreadRelationshipWalkRow>) => ReactNode;
156+
readonly children: (rows: ReadonlyArray<Row>) => ReactNode;
144157
}) {
145158
const [expanded, setExpanded] = useState(props.expanded);
146159
const [visibleCount, setVisibleCount] = useState(THREAD_LINEAGE_INITIAL_COUNT);
147160
const { visibleRows, hiddenCount } = resolveThreadLineageWindow(props.rows, visibleCount);
148-
const failedCount = props.rows.filter(
149-
({ edge }) => edge.status === "failed" || edge.status === "error",
150-
).length;
161+
const failedCount = props.rows.filter((row) => {
162+
const status = lineageRowStatus(row);
163+
return status === "failed" || status === "error";
164+
}).length;
151165
if (props.rows.length === 0) return null;
152166
return (
153167
<div>
@@ -247,9 +261,7 @@ function currentSubagent<Agent extends RuntimeSubagent>(
247261
* the thread there, when this client is connected to that environment.
248262
*/
249263
function RemoteSubagentRow(props: {
250-
readonly agent: OrchestrationV2Subagent & {
251-
readonly remoteChild: OrchestrationV2RemoteTaskChild;
252-
};
264+
readonly agent: RemoteSubagent;
253265
readonly provider: ServerProvider | undefined;
254266
}) {
255267
const navigate = useNavigate();
@@ -537,22 +549,29 @@ export function ThreadRelationshipsPanel(props: {
537549
if (!isParent && graph.nodes.get(threadId)?.thread?.lineage.sideChat === true)
538550
return "sideChats";
539551
if (edge.kind !== "subagent" || isParent) return "related";
540-
return ["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(
541-
edge.status ?? "",
542-
)
543-
? "previous"
544-
: "active";
552+
return isFinishedAgentStatus(edge.status) ? "previous" : "active";
545553
});
546-
const groups = [
554+
const { remoteActive = [], remotePrevious = [] } = groupBy(
555+
(projection?.subagents ?? [])
556+
.filter((agent): agent is RemoteSubagent => agent.remoteChild !== undefined)
557+
.map((remote) => ({ remote })),
558+
({ remote }) => (isFinishedAgentStatus(remote.status) ? "remotePrevious" : "remoteActive"),
559+
);
560+
const groups: ReadonlyArray<{
561+
id: string;
562+
label: string | null;
563+
rows: ReadonlyArray<LineageRow>;
564+
expanded: boolean;
565+
}> = [
547566
{ id: "related", label: null, rows: related, expanded: true },
548-
{ id: "active", label: null, rows: active, expanded: true },
549-
{ id: "previous", label: "Previous agents", rows: previous, expanded: false },
567+
{ id: "active", label: null, rows: [...active, ...remoteActive], expanded: true },
568+
{
569+
id: "previous",
570+
label: "Previous agents",
571+
rows: [...previous, ...remotePrevious],
572+
expanded: false,
573+
},
550574
];
551-
// Tasks running in a linked environment have no thread here; they get their own rows.
552-
const remoteSubagents = (projection?.subagents ?? []).filter(
553-
(agent): agent is OrchestrationV2Subagent & { remoteChild: OrchestrationV2RemoteTaskChild } =>
554-
agent.remoteChild !== undefined,
555-
);
556575
const runningCount =
557576
(projection?.subagents.filter(
558577
(agent) => agent.childThreadId === null && agent.status === "running",
@@ -567,7 +586,8 @@ export function ThreadRelationshipsPanel(props: {
567586
active.length > 0 ||
568587
previous.length > 0 ||
569588
runningCount > 0 ||
570-
remoteSubagents.length > 0 ||
589+
remoteActive.length > 0 ||
590+
remotePrevious.length > 0 ||
571591
delegatedFrom !== undefined ||
572592
// Disconnect lives in this heading, so a thread with only side chats still shows it.
573593
(canDetach && sideChats.length > 0));
@@ -929,6 +949,7 @@ export function ThreadRelationshipsPanel(props: {
929949
canDetach ||
930950
related.length > 0 ||
931951
active.length > 0 ||
952+
remoteActive.length > 0 ||
932953
delegatedFrom !== undefined
933954
}
934955
data-thread-relationships-panel
@@ -968,23 +989,24 @@ export function ThreadRelationshipsPanel(props: {
968989
)}
969990
{groups.map((group) => (
970991
<ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
971-
{(visibleRows) => visibleRows.map(renderRelationshipRow)}
992+
{(visibleRows) =>
993+
visibleRows.map((row) =>
994+
"remote" in row ? (
995+
<RemoteSubagentRow
996+
key={row.remote.id}
997+
agent={row.remote}
998+
// Its provider instance belongs to the environment it runs in.
999+
provider={providersByEnvironment
1000+
.get(row.remote.remoteChild.environmentId)
1001+
?.find((entry) => entry.instanceId === row.remote.providerInstanceId)}
1002+
/>
1003+
) : (
1004+
renderRelationshipRow(row)
1005+
),
1006+
)
1007+
}
9721008
</ThreadLineageGroup>
9731009
))}
974-
{remoteSubagents.length > 0 ? (
975-
<ThreadLineageRowList hiddenCount={0} onShowMore={() => {}}>
976-
{remoteSubagents.map((agent) => (
977-
<RemoteSubagentRow
978-
key={agent.id}
979-
agent={agent}
980-
// Its provider instance belongs to the environment it runs in.
981-
provider={providersByEnvironment
982-
.get(agent.remoteChild.environmentId)
983-
?.find((entry) => entry.instanceId === agent.providerInstanceId)}
984-
/>
985-
))}
986-
</ThreadLineageRowList>
987-
) : null}
9881010
</ThreadDetailsSection>
9891011
) : null}
9901012
{sideChatsVisible ? (

0 commit comments

Comments
 (0)