fix(web): subagents sent a follow-up show as running in Lineage (#15334)
Co-authored-by: scratchyone <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
3 files changed
+72
-5
No files matched your search
@@ -5,7 +5,10 @@ import { CollapsibleSectionHeader, SectionHeaderStatus } from "../ui/collapsible
|
||||
import { SubagentTooltipContent } from "./SubagentTooltipContent";
|
||||
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
|
||||
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
|
||||
import { projectedSubagentsToRuntime } from "@t3tools/client-runtime/state/subagentRuntime";
|
||||
import {
|
||||
projectedSubagentsToRuntime,
|
||||
type RuntimeSubagent,
|
||||
} from "@t3tools/client-runtime/state/subagentRuntime";
|
||||
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
|
||||
import {
|
||||
deriveThreadRelationshipGraph,
|
||||
@@ -23,6 +26,7 @@ import {
|
||||
} from "@t3tools/client-runtime/state/thread-workflows";
|
||||
import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts";
|
||||
import { groupBy } from "effect/Array";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import {
|
||||
ArrowRightIcon,
|
||||
@@ -162,6 +166,30 @@ function relationshipThreadTitle(input: {
|
||||
return formatSubagentDisplayTitle(input.title);
|
||||
}
|
||||
|
||||
/**
|
||||
* A delegated task settles with its first run, but the parent can keep sending
|
||||
* the child follow-ups. While the child thread has a live run, the row's timer
|
||||
* and hover card follow that run instead of the settled task.
|
||||
*/
|
||||
function liveSubagent<Agent extends RuntimeSubagent>(
|
||||
agent: Agent | undefined,
|
||||
childThread: OrchestrationV2ThreadShell | null | undefined,
|
||||
): Agent | undefined {
|
||||
const liveStatus = childThread?.activityRunStatus;
|
||||
if (!agent || !liveStatus) return agent;
|
||||
const startedAt = childThread.activityRunStartedAt;
|
||||
return {
|
||||
...agent,
|
||||
status: liveStatus === "running" || liveStatus === "waiting" ? liveStatus : "pending",
|
||||
startedAt: startedAt ? DateTime.formatIso(startedAt) : null,
|
||||
completedAt: null,
|
||||
// The settled task's output belongs to its first run, not this one.
|
||||
progress: null,
|
||||
result: null,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function ThreadRelationshipsPanel(props: {
|
||||
readonly environmentId: EnvironmentId;
|
||||
readonly threadId: ThreadId;
|
||||
@@ -239,9 +267,11 @@ export function ThreadRelationshipsPanel(props: {
|
||||
{ id: "active", label: null, rows: active, expanded: true },
|
||||
{ id: "previous", label: "Previous agents", rows: previous, expanded: false },
|
||||
];
|
||||
// Subagents without a child thread yet have no row, so count them separately.
|
||||
const runningCount =
|
||||
projection?.subagents.filter((agent) => agent.status === "running").length ??
|
||||
active.filter(({ edge }) => edge.status === "running").length;
|
||||
(projection?.subagents.filter(
|
||||
(agent) => agent.childThreadId === null && agent.status === "running",
|
||||
).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
|
||||
|
||||
if (relationshipRows.length === 0 && runningCount === 0) {
|
||||
return null;
|
||||
@@ -330,7 +360,10 @@ export function ThreadRelationshipsPanel(props: {
|
||||
? BotIcon
|
||||
: GitForkIcon;
|
||||
const relationship = relationshipLabel(edge, props.threadId);
|
||||
const agent = isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
|
||||
const agent = liveSubagent(
|
||||
isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined,
|
||||
node?.thread,
|
||||
);
|
||||
const threadTitle = relationshipThreadTitle({
|
||||
title: node?.thread?.title ?? agent?.title ?? threadId,
|
||||
isSubagent,
|
||||
|
||||
@@ -187,6 +187,37 @@ describe("thread relationships", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["running", "running"],
|
||||
[null, "completed"],
|
||||
])(
|
||||
"shows a subagent whose child activity is %s as %s after its delegated task settled",
|
||||
(childActivity, expected) => {
|
||||
const parent = ThreadId.make("thread-parent");
|
||||
const child = ThreadId.make("thread-child");
|
||||
const graph = deriveThreadRelationshipGraph({
|
||||
threads: [
|
||||
{ id: parent, status: "completed", forkedFrom: null, lineage: { parentThreadId: null } },
|
||||
{
|
||||
id: child,
|
||||
status: childActivity ?? "completed",
|
||||
activityRunStatus: childActivity,
|
||||
forkedFrom: null,
|
||||
lineage: { parentThreadId: parent, relationshipToParent: "subagent" },
|
||||
},
|
||||
] as never,
|
||||
projection: {
|
||||
thread: { id: parent },
|
||||
subagents: [{ childThreadId: child, status: "completed" }],
|
||||
contextTransfers: [],
|
||||
} as never,
|
||||
});
|
||||
|
||||
const row = immediateThreadRelationships(graph, parent)[0]!;
|
||||
expect(threadRelationshipRowStatus(graph, row)).toBe(expected);
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps the live shell when an archived snapshot contains the same thread id", () => {
|
||||
const parent = ThreadId.make("thread-parent");
|
||||
const staleParent = ThreadId.make("thread-stale-parent");
|
||||
|
||||
@@ -92,11 +92,14 @@ export function deriveThreadRelationshipGraph(input: {
|
||||
const ownerThreadId = input.projection.thread.id;
|
||||
for (const subagent of input.projection.subagents) {
|
||||
if (subagent.childThreadId === null) continue;
|
||||
// The subagent record settles with the delegated task's first run, but the
|
||||
// parent can keep sending the child follow-ups. A live run on the child
|
||||
// thread outranks that settled status.
|
||||
addEdge({
|
||||
sourceThreadId: ownerThreadId,
|
||||
targetThreadId: subagent.childThreadId,
|
||||
kind: "subagent",
|
||||
status: subagent.status,
|
||||
status: threadsById.get(subagent.childThreadId)?.activityRunStatus ?? subagent.status,
|
||||
});
|
||||
}
|
||||
for (const transfer of input.projection.contextTransfers) {
|
||||
|
||||
Reference in new issue
Block a user