Skip to content
TypeScript

fix(web): show the result of the notified delegated task (#22141)

Alb11747f47700849e6f
diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
index 24e15957192..212f3e253ce 100644
--- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
@@ -1,25 +1,30 @@
import { AudioPreview } from "../files/AudioPreview";
-import { onTestFinished } from "vite-plus/test";
import { page } from "vite-plus/test/browser";
-import { stubGlobal } from "../../../test/render";
import {
ComposerContextId,
EnvironmentId,
MessageId,
+ NodeId,
+ ProviderDriverKind,
+ ProviderInstanceId,
RunAttemptId,
RunId,
RuntimeRequestId,
TurnItemId,
ScheduledTaskId,
ThreadId,
+ type OrchestrationV2Subagent,
} from "@t3tools/contracts";
import type { LegendListRef } from "@legendapp/list/react";
import { createRef, Profiler, StrictMode, type ComponentProps, type ReactElement } from "react";
-import { describe, expect, it, vi } from "vite-plus/test";
+import * as DateTime from "effect/DateTime";
+import { Atom } from "effect/reactivity";
+import { describe, expect, it, onTestFinished, vi } from "vite-plus/test";
import "~/index.css";
-import { act, fakeTimers, render } from "../../../test/render";
+import { environmentThreadDetails } from "../../state/threads";
+import { act, fakeTimers, render, stubGlobal } from "../../../test/render";
import { MessagesTimeline } from "./MessagesTimeline";
import { makeStreamingTimelineFixture } from "../../test-fixtures";
import {
@@ -128,6 +133,43 @@ function message(
};
}
+function work(id: string, entry: Record<string, unknown>): Entry {
+ return {
+ id,
+ kind: "work",
+ createdAt: CREATED_AT,
+ entry: { id, createdAt: CREATED_AT, ...entry },
+ } as Entry;
+}
+
+function v2Item(type: string, fields: Record<string, unknown>) {
+ const id = (fields.id as string | undefined) ?? type;
+ return {
+ position: 0,
+ visibility: "local",
+ sourceThreadId: "thread-1",
+ sourceItemId: id,
+ item: {
+ id,
+ threadId: "thread-1",
+ runId: "run-1",
+ nodeId: null,
+ providerThreadId: null,
+ providerTurnId: null,
+ nativeItemRef: null,
+ parentItemId: null,
+ ordinal: 0,
+ status: "completed",
+ title: null,
+ startedAt: null,
+ completedAt: null,
+ updatedAt: {},
+ type,
+ ...fields,
+ },
+ } as never;
+}
+
async function renderElement(element: ReactElement, options: { router?: false } = {}) {
const container = document.createElement("div");
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
const TASK_ID = ScheduledTaskId.make("task-1");
const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates.";
+describe("MessagesTimeline work rows", () => {
+ it.each(["delegated", "legacy", "missing"] as const)(
+ "uses the reported task for %s completion notifications",
+ async (source) => {
+ setup();
+ const now = DateTime.makeUnsafe(CREATED_AT);
+ const childThreadId = ThreadId.make("shared-child");
+ const task = (
+ id: string,
+ status: OrchestrationV2Subagent["status"],
+ result: string,
+ ): OrchestrationV2Subagent => ({
+ id: NodeId.make(id),
+ threadId: ThreadId.make("thread-1"),
+ runId: null,
+ parentNodeId: NodeId.make("parent-root"),
+ origin: "app_owned",
+ createdBy: "agent",
+ driver: ProviderDriverKind.make("claudeAgent"),
+ providerInstanceId: ProviderInstanceId.make("claudeAgent"),
+ providerThreadId: null,
+ childThreadId,
+ nativeTaskRef: null,
+ prompt: "Simplify delivery",
+ title: "Simplify delivery",
+ model: null,
+ status,
+ result,
+ startedAt: now,
+ completedAt: now,
+ updatedAt: now,
+ });
+ const tasks = [
+ task("original", "interrupted", "Old interrupted progress"),
+ task("continued", "completed", "Final implementation report"),
+ task("follow-up", "completed", "Follow-up explanation"),
+ ];
+ using _threadAtom = vi.spyOn(environmentThreadDetails, "threadAtom").mockReturnValue(
+ Atom.make({
+ projection: { subagents: tasks, turnItems: [], visibleTurnItems: [] },
+ }) as never,
+ );
+ const onOpenThread = vi.fn();
+ await using screen = await renderTimeline(
+ (source === "delegated" ? ["continued", "follow-up"] : [source]).map((id) =>
+ work(`notification-${id}`, {
+ label: "Notification fallback",
+ tone: "info",
+ itemType: "notification",
+ projectedItem: v2Item("notification", {
+ id: `notification-${id}`,
+ source:
+ source === "legacy"
+ ? { kind: "subagent", childThreadId }
+ : { kind: "delegated_task", childThreadId, taskIds: [NodeId.make(id)] },
+ outcome: "completed",
+ summary: "Notification fallback",
+ }),
+ }),
+ ),
+ { onOpenThread },
+ );
+ if (source === "delegated") {
+ expect(screen.text()).toContain("Final implementation report");
+ expect(screen.text()).toContain("Follow-up explanation");
+ expect(screen.text()).not.toContain("Old interrupted progress");
+ await click(screen.buttons("Open Simplify delivery")[0]!);
+ expect(onOpenThread).toHaveBeenCalledWith(childThreadId);
+ } else if (source === "legacy") {
+ expect(screen.text()).toContain("Old interrupted progress");
+ } else {
+ expect(screen.text()).toContain("Notification fallback");
+ expect(screen.text()).not.toContain("Old interrupted progress");
+ }
+ },
+ );
+});
+
describe("MessagesTimeline messages", () => {
it("settles when equally long messages have very different rendered heights", async () => {
const props = baseProps();
diff --git a/apps/web/src/components/chat/TimelineWorkEntryRow.tsx b/apps/web/src/components/chat/TimelineWorkEntryRow.tsx
index a8d5e3e68de..f485f62c9c3 100644
--- a/apps/web/src/components/chat/TimelineWorkEntryRow.tsx
+++ b/apps/web/src/components/chat/TimelineWorkEntryRow.tsx
@@ -160,6 +160,7 @@ export const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEn
<SubagentNotificationLink
parentRef={scopeThreadRef(ctx.activeThreadEnvironmentId, item.threadId)}
childThreadId={childThreadId}
+ taskIds={item.source.kind === "delegated_task" ? item.source.taskIds : undefined}
outcome={item.outcome}
createdAt={props.workEntry.createdAt}
timestampFormat={ctx.timestampFormat}
diff --git a/apps/web/src/components/chat/V2LifecycleRow.tsx b/apps/web/src/components/chat/V2LifecycleRow.tsx
index 42ab22fa5f3..aa6f7819ca0 100644
--- a/apps/web/src/components/chat/V2LifecycleRow.tsx
+++ b/apps/web/src/components/chat/V2LifecycleRow.tsx
@@ -311,17 +311,22 @@ const NOTIFICATION_OUTCOME_LABEL: Record<OrchestrationV2Notification["outcome"],
export function SubagentNotificationLink(props: {
readonly parentRef: ScopedThreadRef;
readonly childThreadId: ThreadId;
+ readonly taskIds?: ReadonlyArray<NodeId> | undefined;
readonly outcome: OrchestrationV2Notification["outcome"];
readonly createdAt: string;
readonly timestampFormat: TimestampFormat;
readonly onOpenThread: (threadId: ThreadId) => void;
readonly fallback: ReactNode;
}) {
+ // Follow-up tasks share a child conversation; this notice reports a particular task result.
const agent = useAtomValue(
environmentThreadDetails.threadAtom(props.parentRef),
(thread) =>
- thread?.projection.subagents.find((agent) => agent.childThreadId === props.childThreadId) ??
- null,
+ thread?.projection.subagents.find((agent) =>
+ props.taskIds === undefined
+ ? agent.childThreadId === props.childThreadId
+ : props.taskIds.includes(agent.id),
+ ) ?? null,
);
if (agent === null) return props.fallback;
const resumed =