Skip to content

Commit dbcc777

Browse files
scratchyoneclaude
andcommitted
fix(web): subagents sent a follow-up show as running in Lineage
A delegated subagent's record settles when its first run ends. When the parent later sends the child thread a follow-up, the child runs again, but Lineage kept reading the settled record, so a working agent sat under "Previous agents" as "Done" with a frozen timer. Lineage now prefers the child thread's live run over the settled record for the row status, grouping, header running count, timer and hover card. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent f1dcd93 commit dbcc777

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { CollapsibleSectionHeader, SectionHeaderStatus } from "../ui/collapsible
55
import { SubagentTooltipContent } from "./SubagentTooltipContent";
66
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
77
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
8-
import { projectedSubagentsToRuntime } from "@t3tools/client-runtime/state/subagentRuntime";
8+
import {
9+
projectedSubagentsToRuntime,
10+
type RuntimeSubagent,
11+
} from "@t3tools/client-runtime/state/subagentRuntime";
912
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
1013
import {
1114
deriveThreadRelationshipGraph,
@@ -23,6 +26,7 @@ import {
2326
} from "@t3tools/client-runtime/state/thread-workflows";
2427
import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts";
2528
import { groupBy } from "effect/Array";
29+
import * as DateTime from "effect/DateTime";
2630
import { useNavigate } from "@tanstack/react-router";
2731
import {
2832
ArrowRightIcon,
@@ -162,6 +166,26 @@ function relationshipThreadTitle(input: {
162166
return formatSubagentDisplayTitle(input.title);
163167
}
164168

169+
/**
170+
* A delegated task settles with its first run, but the parent can keep sending
171+
* the child follow-ups. While the child thread has a live run, the row's timer
172+
* and hover card follow that run instead of the settled task.
173+
*/
174+
function liveSubagent<Agent extends RuntimeSubagent>(
175+
agent: Agent | undefined,
176+
childThread: OrchestrationV2ThreadShell | null | undefined,
177+
): Agent | undefined {
178+
const liveStatus = childThread?.activityRunStatus;
179+
if (!agent || !liveStatus) return agent;
180+
const startedAt = childThread.activityRunStartedAt;
181+
return {
182+
...agent,
183+
status: liveStatus === "running" || liveStatus === "waiting" ? liveStatus : "pending",
184+
startedAt: startedAt ? DateTime.formatIso(startedAt) : agent.startedAt,
185+
completedAt: null,
186+
};
187+
}
188+
165189
export function ThreadRelationshipsPanel(props: {
166190
readonly environmentId: EnvironmentId;
167191
readonly threadId: ThreadId;
@@ -239,9 +263,11 @@ export function ThreadRelationshipsPanel(props: {
239263
{ id: "active", label: null, rows: active, expanded: true },
240264
{ id: "previous", label: "Previous agents", rows: previous, expanded: false },
241265
];
266+
// Subagents without a child thread yet have no row, so count them separately.
242267
const runningCount =
243-
projection?.subagents.filter((agent) => agent.status === "running").length ??
244-
active.filter(({ edge }) => edge.status === "running").length;
268+
(projection?.subagents.filter(
269+
(agent) => agent.childThreadId === null && agent.status === "running",
270+
).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
245271

246272
if (relationshipRows.length === 0 && runningCount === 0) {
247273
return null;
@@ -330,7 +356,10 @@ export function ThreadRelationshipsPanel(props: {
330356
? BotIcon
331357
: GitForkIcon;
332358
const relationship = relationshipLabel(edge, props.threadId);
333-
const agent = isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
359+
const agent = liveSubagent(
360+
isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined,
361+
node?.thread,
362+
);
334363
const threadTitle = relationshipThreadTitle({
335364
title: node?.thread?.title ?? agent?.title ?? threadId,
336365
isSubagent,

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,37 @@ describe("thread relationships", () => {
187187
);
188188
});
189189

190+
it.each([
191+
["running", "running"],
192+
[null, "completed"],
193+
])(
194+
"shows a subagent whose child activity is %s as %s after its delegated task settled",
195+
(childActivity, expected) => {
196+
const parent = ThreadId.make("thread-parent");
197+
const child = ThreadId.make("thread-child");
198+
const graph = deriveThreadRelationshipGraph({
199+
threads: [
200+
{ id: parent, status: "completed", forkedFrom: null, lineage: { parentThreadId: null } },
201+
{
202+
id: child,
203+
status: childActivity ?? "completed",
204+
activityRunStatus: childActivity,
205+
forkedFrom: null,
206+
lineage: { parentThreadId: parent, relationshipToParent: "subagent" },
207+
},
208+
] as never,
209+
projection: {
210+
thread: { id: parent },
211+
subagents: [{ childThreadId: child, status: "completed" }],
212+
contextTransfers: [],
213+
} as never,
214+
});
215+
216+
const row = immediateThreadRelationships(graph, parent)[0]!;
217+
expect(threadRelationshipRowStatus(graph, row)).toBe(expected);
218+
},
219+
);
220+
190221
it("keeps the live shell when an archived snapshot contains the same thread id", () => {
191222
const parent = ThreadId.make("thread-parent");
192223
const staleParent = ThreadId.make("thread-stale-parent");

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ export function deriveThreadRelationshipGraph(input: {
9292
const ownerThreadId = input.projection.thread.id;
9393
for (const subagent of input.projection.subagents) {
9494
if (subagent.childThreadId === null) continue;
95+
// The subagent record settles with the delegated task's first run, but the
96+
// parent can keep sending the child follow-ups. A live run on the child
97+
// thread outranks that settled status.
9598
addEdge({
9699
sourceThreadId: ownerThreadId,
97100
targetThreadId: subagent.childThreadId,
98101
kind: "subagent",
99-
status: subagent.status,
102+
status: threadsById.get(subagent.childThreadId)?.activityRunStatus ?? subagent.status,
100103
});
101104
}
102105
for (const transfer of input.projection.contextTransfers) {

0 commit comments

Comments
 (0)