Skip to content

Commit f477008

Browse files
Alb11747codexmaria-rcks
authored
fix(web): show the result of the notified delegated task (#22141)
Co-authored-by: GPT-6.1 Sol at high effort <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 2b77a05 commit f477008

3 files changed

Lines changed: 132 additions & 6 deletions

File tree

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

Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
import { AudioPreview } from "../files/AudioPreview";
2-
import { onTestFinished } from "vite-plus/test";
32
import { page } from "vite-plus/test/browser";
4-
import { stubGlobal } from "../../../test/render";
53
import {
64
ComposerContextId,
75
EnvironmentId,
86
MessageId,
7+
NodeId,
8+
ProviderDriverKind,
9+
ProviderInstanceId,
910
RunAttemptId,
1011
RunId,
1112
RuntimeRequestId,
1213
TurnItemId,
1314
ScheduledTaskId,
1415
ThreadId,
16+
type OrchestrationV2Subagent,
1517
} from "@t3tools/contracts";
1618
import type { LegendListRef } from "@legendapp/list/react";
1719
import { createRef, Profiler, StrictMode, type ComponentProps, type ReactElement } from "react";
18-
import { describe, expect, it, vi } from "vite-plus/test";
20+
import * as DateTime from "effect/DateTime";
21+
import { Atom } from "effect/reactivity";
22+
import { describe, expect, it, onTestFinished, vi } from "vite-plus/test";
1923

2024
import "~/index.css";
2125

22-
import { act, fakeTimers, render } from "../../../test/render";
26+
import { environmentThreadDetails } from "../../state/threads";
27+
import { act, fakeTimers, render, stubGlobal } from "../../../test/render";
2328
import { MessagesTimeline } from "./MessagesTimeline";
2429
import { makeStreamingTimelineFixture } from "../../test-fixtures";
2530
import {
@@ -128,6 +133,43 @@ function message(
128133
};
129134
}
130135

136+
function work(id: string, entry: Record<string, unknown>): Entry {
137+
return {
138+
id,
139+
kind: "work",
140+
createdAt: CREATED_AT,
141+
entry: { id, createdAt: CREATED_AT, ...entry },
142+
} as Entry;
143+
}
144+
145+
function v2Item(type: string, fields: Record<string, unknown>) {
146+
const id = (fields.id as string | undefined) ?? type;
147+
return {
148+
position: 0,
149+
visibility: "local",
150+
sourceThreadId: "thread-1",
151+
sourceItemId: id,
152+
item: {
153+
id,
154+
threadId: "thread-1",
155+
runId: "run-1",
156+
nodeId: null,
157+
providerThreadId: null,
158+
providerTurnId: null,
159+
nativeItemRef: null,
160+
parentItemId: null,
161+
ordinal: 0,
162+
status: "completed",
163+
title: null,
164+
startedAt: null,
165+
completedAt: null,
166+
updatedAt: {},
167+
type,
168+
...fields,
169+
},
170+
} as never;
171+
}
172+
131173
async function renderElement(element: ReactElement, options: { router?: false } = {}) {
132174
const container = document.createElement("div");
133175
container.style.cssText = "height: 1200px; width: 900px; display: flex; flex-direction: column;";
@@ -165,6 +207,84 @@ function setup({ scheduledTasks = [] as ReadonlyArray<{ id: string; title: strin
165207
const TASK_ID = ScheduledTaskId.make("task-1");
166208
const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates.";
167209

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEn
160160
<SubagentNotificationLink
161161
parentRef={scopeThreadRef(ctx.activeThreadEnvironmentId, item.threadId)}
162162
childThreadId={childThreadId}
163+
taskIds={item.source.kind === "delegated_task" ? item.source.taskIds : undefined}
163164
outcome={item.outcome}
164165
createdAt={props.workEntry.createdAt}
165166
timestampFormat={ctx.timestampFormat}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,22 @@ const NOTIFICATION_OUTCOME_LABEL: Record<OrchestrationV2Notification["outcome"],
311311
export function SubagentNotificationLink(props: {
312312
readonly parentRef: ScopedThreadRef;
313313
readonly childThreadId: ThreadId;
314+
readonly taskIds?: ReadonlyArray<NodeId> | undefined;
314315
readonly outcome: OrchestrationV2Notification["outcome"];
315316
readonly createdAt: string;
316317
readonly timestampFormat: TimestampFormat;
317318
readonly onOpenThread: (threadId: ThreadId) => void;
318319
readonly fallback: ReactNode;
319320
}) {
321+
// Follow-up tasks share a child conversation; this notice reports a particular task result.
320322
const agent = useAtomValue(
321323
environmentThreadDetails.threadAtom(props.parentRef),
322324
(thread) =>
323-
thread?.projection.subagents.find((agent) => agent.childThreadId === props.childThreadId) ??
324-
null,
325+
thread?.projection.subagents.find((agent) =>
326+
props.taskIds === undefined
327+
? agent.childThreadId === props.childThreadId
328+
: props.taskIds.includes(agent.id),
329+
) ?? null,
325330
);
326331
if (agent === null) return props.fallback;
327332
const resumed =

0 commit comments

Comments
 (0)