Skip to content

Commit d2612c0

Browse files
Alb11747codex
andcommitted
fix(web): show the result of the notified delegated task
Match delegated completion cards by the notification's task IDs. Follow-up tasks reuse their child conversation, so a child-thread lookup can display the original task's interrupted result on every later completion card. Keep child-thread lookup for legacy notifications and generic rendering when the referenced task is unavailable. Cover repeated child tasks, navigation, legacy notifications, and unavailable task identities in Chromium. Co-Authored-By: GPT-6.1 Sol at high effort <[email protected]> Co-Authored-By: GPT-6.1 Sol at medium effort, investigation subagents <[email protected]> Co-Authored-By: GPT-6.1 Sol at xhigh effort, independent review subagents <[email protected]>
1 parent 64a76c8 commit d2612c0

3 files changed

Lines changed: 91 additions & 2 deletions

File tree

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import {
44
CheckpointRef,
55
EnvironmentId,
66
MessageId,
7+
NodeId,
8+
ProviderDriverKind,
9+
ProviderInstanceId,
710
RunId,
811
ThreadId,
12+
type OrchestrationV2Subagent,
913
} from "@t3tools/contracts";
14+
import * as DateTime from "effect/DateTime";
15+
import { Atom } from "effect/reactivity";
1016
import type { LegendListRef } from "@legendapp/list/react";
1117
import { act, createRef, Profiler, useState, type ComponentProps, type ReactElement } from "react";
1218
import { createRoot, type Root } from "react-dom/client";
@@ -16,6 +22,7 @@ import { userEvent } from "vite-plus/test/browser";
1622
import "~/index.css";
1723

1824
import { serverEnvironment } from "../../state/server";
25+
import { environmentThreadDetails } from "../../state/threads";
1926
import { PullRequestLinkPreview } from "../pullRequest/PullRequestLinkPreview";
2027
import { Tooltip, TooltipPopup, TooltipScrollDismissArea, TooltipTrigger } from "../ui/tooltip";
2128
import { MessagesTimeline, remarkThoughtPreview } from "./MessagesTimeline";
@@ -156,6 +163,7 @@ afterEach(async () => {
156163
for (const root of roots.splice(0)) await act(async () => root.unmount());
157164
document.body.replaceChildren();
158165
vi.unstubAllGlobals();
166+
vi.restoreAllMocks();
159167
});
160168

161169
async function renderElement(element: ReactElement) {
@@ -195,6 +203,81 @@ async function click(element: HTMLElement) {
195203
}
196204

197205
describe("MessagesTimeline work rows", () => {
206+
it.each(["delegated", "legacy", "missing"] as const)(
207+
"uses the reported task for %s completion notifications",
208+
async (source) => {
209+
const now = DateTime.makeUnsafe(CREATED_AT);
210+
const childThreadId = ThreadId.make("shared-child");
211+
const task = (
212+
id: string,
213+
status: OrchestrationV2Subagent["status"],
214+
result: string,
215+
): OrchestrationV2Subagent => ({
216+
id: NodeId.make(id),
217+
threadId: ThreadId.make("thread-1"),
218+
runId: null,
219+
parentNodeId: NodeId.make("parent-root"),
220+
origin: "app_owned",
221+
createdBy: "agent",
222+
driver: ProviderDriverKind.make("claudeAgent"),
223+
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
224+
providerThreadId: null,
225+
childThreadId,
226+
nativeTaskRef: null,
227+
prompt: "Simplify delivery",
228+
title: "Simplify delivery",
229+
model: null,
230+
status,
231+
result,
232+
startedAt: now,
233+
completedAt: now,
234+
updatedAt: now,
235+
});
236+
const tasks = [
237+
task("original", "interrupted", "Old interrupted progress"),
238+
task("continued", "completed", "Final implementation report"),
239+
task("follow-up", "completed", "Follow-up explanation"),
240+
];
241+
vi.spyOn(environmentThreadDetails, "threadAtom").mockReturnValue(
242+
Atom.make({
243+
projection: { subagents: tasks, turnItems: [], visibleTurnItems: [] },
244+
}) as never,
245+
);
246+
const onOpenThread = vi.fn();
247+
await renderTimeline(
248+
(source === "delegated" ? ["continued", "follow-up"] : [source]).map((id) =>
249+
work(`notification-${id}`, {
250+
label: "Notification fallback",
251+
tone: "info",
252+
itemType: "notification",
253+
projectedItem: v2Item("notification", {
254+
id: `notification-${id}`,
255+
source:
256+
source === "legacy"
257+
? { kind: "subagent", childThreadId }
258+
: { kind: "delegated_task", childThreadId, taskIds: [NodeId.make(id)] },
259+
outcome: "completed",
260+
summary: "Notification fallback",
261+
}),
262+
}),
263+
),
264+
{ onOpenThread },
265+
);
266+
if (source === "delegated") {
267+
expect(text()).toContain("Final implementation report");
268+
expect(text()).toContain("Follow-up explanation");
269+
expect(text()).not.toContain("Old interrupted progress");
270+
await click(buttons("Open Simplify delivery")[0]!);
271+
expect(onOpenThread).toHaveBeenCalledWith(childThreadId);
272+
} else if (source === "legacy") {
273+
expect(text()).toContain("Old interrupted progress");
274+
} else {
275+
expect(text()).toContain("Notification fallback");
276+
expect(text()).not.toContain("Old interrupted progress");
277+
}
278+
},
279+
);
280+
198281
it.each([
199282
["Enter", "{Enter}"],
200283
["Space", " "],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5297,6 +5297,7 @@ const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEntryRowP
52975297
<SubagentNotificationLink
52985298
parentRef={scopeThreadRef(ctx.activeThreadEnvironmentId, item.threadId)}
52995299
childThreadId={childThreadId}
5300+
taskIds={item.source.kind === "delegated_task" ? item.source.taskIds : undefined}
53005301
outcome={item.outcome}
53015302
createdAt={props.workEntry.createdAt}
53025303
timestampFormat={ctx.timestampFormat}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,22 @@ const NOTIFICATION_OUTCOME_LABEL: Record<OrchestrationV2Notification["outcome"],
350350
export function SubagentNotificationLink(props: {
351351
readonly parentRef: ScopedThreadRef;
352352
readonly childThreadId: ThreadId;
353+
readonly taskIds?: ReadonlyArray<NodeId> | undefined;
353354
readonly outcome: OrchestrationV2Notification["outcome"];
354355
readonly createdAt: string;
355356
readonly timestampFormat: TimestampFormat;
356357
readonly onOpenThread: (threadId: ThreadId) => void;
357358
readonly fallback: ReactNode;
358359
}) {
360+
// Follow-up tasks share a child conversation; this notice reports a particular task result.
359361
const agent = useAtomValue(
360362
environmentThreadDetails.threadAtom(props.parentRef),
361363
(thread) =>
362-
thread?.projection.subagents.find((agent) => agent.childThreadId === props.childThreadId) ??
363-
null,
364+
thread?.projection.subagents.find((agent) =>
365+
props.taskIds === undefined
366+
? agent.childThreadId === props.childThreadId
367+
: props.taskIds.includes(agent.id),
368+
) ?? null,
364369
);
365370
if (agent === null) return props.fallback;
366371
// A subagent resumed since this notification shows its live status, not the outcome reported then.

0 commit comments

Comments
 (0)