feat(subagents): disclose projected results consistently (#3866)
Normalize subagent result disclosure across timeline rendering and collapsed/expanded states. Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
ed3a278ae1
commit
d3319df541
4 files changed
+344
-4
No files matched your search
@@ -68,6 +68,14 @@ export function assertSubagentOutput(
|
||||
assert.isNotNull(subagent.providerThreadId);
|
||||
assert.isNotNull(subagent.nativeTaskRef);
|
||||
assert.isNotNull(subagent.completedAt);
|
||||
const parentItem = projection.turnItems.find(
|
||||
(item) => item.type === "subagent" && item.subagentId === subagent.id,
|
||||
);
|
||||
assert.isDefined(parentItem);
|
||||
if (parentItem?.type !== "subagent") {
|
||||
throw new Error(`Missing parent lifecycle item for subagent ${subagent.id}`);
|
||||
}
|
||||
assert.equal(parentItem.result, subagent.result);
|
||||
if (subagent.childThreadId === null) {
|
||||
throw new Error(`Subagent ${subagent.id} is missing its child thread`);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,14 @@ export function assertSubagentV2Output(
|
||||
assert.isNotNull(subagent.providerThreadId);
|
||||
assert.isNotNull(subagent.nativeTaskRef);
|
||||
assert.isNotNull(subagent.completedAt);
|
||||
const parentItem = projection.turnItems.find(
|
||||
(item) => item.type === "subagent" && item.subagentId === subagent.id,
|
||||
);
|
||||
assert.isDefined(parentItem);
|
||||
if (parentItem?.type !== "subagent") {
|
||||
throw new Error(`Missing parent lifecycle item for subagent ${subagent.id}`);
|
||||
}
|
||||
assert.equal(parentItem.result, subagent.result);
|
||||
if (subagent.childThreadId === null) {
|
||||
throw new Error(`Subagent ${subagent.id} is missing its child thread`);
|
||||
}
|
||||
|
||||
@@ -882,9 +882,273 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain('aria-label="Open Package audit"');
|
||||
expect(markup).toContain("Reading src/index.ts");
|
||||
expect(markup).not.toContain("Inspect the package");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
expect(markup).not.toContain("Work Log");
|
||||
});
|
||||
|
||||
it("discloses the full Codex subagent result without projecting child events", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "codex-subagent-result",
|
||||
kind: "event",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
projectedItem: {
|
||||
position: 0,
|
||||
visibility: "local",
|
||||
sourceThreadId: "thread-1",
|
||||
sourceItemId: "codex-subagent-result",
|
||||
item: {
|
||||
id: "codex-subagent-result",
|
||||
threadId: "thread-1",
|
||||
runId: "run-1",
|
||||
nodeId: "node-subagent-1",
|
||||
providerThreadId: "provider-thread-1",
|
||||
providerTurnId: "provider-turn-1",
|
||||
nativeItemRef: null,
|
||||
parentItemId: null,
|
||||
ordinal: 1,
|
||||
status: "completed",
|
||||
title: "Isolation report",
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
updatedAt: {},
|
||||
type: "subagent",
|
||||
subagentId: "node-subagent-1",
|
||||
origin: "provider_native",
|
||||
driver: "codex",
|
||||
providerInstanceId: "codex",
|
||||
childThreadId: "thread-subagent-1",
|
||||
prompt: "Explain test isolation",
|
||||
result: "Tests should be isolated.\n\nResult: no shared state.",
|
||||
},
|
||||
} as never,
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain('data-v2-subagent-result-disclosure="true"');
|
||||
expect(markup).toContain('data-v2-subagent-result="true"');
|
||||
expect(markup).toContain('aria-label="Show full result for Isolation report"');
|
||||
expect(markup).toContain('aria-label="Open Isolation report"');
|
||||
expect(markup).toContain("Tests should be isolated.");
|
||||
expect(markup).toContain("Result: no shared state.");
|
||||
expect(markup).not.toContain("Explain test isolation");
|
||||
});
|
||||
|
||||
it("keeps live progress when a running subagent streams a partial result", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "subagent-partial-result",
|
||||
kind: "event",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
projectedItem: {
|
||||
position: 0,
|
||||
visibility: "local",
|
||||
sourceThreadId: "thread-1",
|
||||
sourceItemId: "subagent-partial-result",
|
||||
item: {
|
||||
id: "subagent-partial-result",
|
||||
threadId: "thread-1",
|
||||
runId: "run-1",
|
||||
nodeId: "node-subagent-1",
|
||||
providerThreadId: "provider-thread-1",
|
||||
providerTurnId: "provider-turn-1",
|
||||
nativeItemRef: null,
|
||||
parentItemId: null,
|
||||
ordinal: 1,
|
||||
status: "running",
|
||||
title: "Package audit",
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
updatedAt: {},
|
||||
type: "subagent",
|
||||
subagentId: "node-subagent-1",
|
||||
origin: "provider_native",
|
||||
driver: "codex",
|
||||
providerInstanceId: "codex",
|
||||
childThreadId: "thread-subagent-1",
|
||||
prompt: "Inspect the package",
|
||||
progress: "Reading src/index.ts",
|
||||
result: "Partial streamed answer so far",
|
||||
},
|
||||
} as never,
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain('aria-label="Open Package audit"');
|
||||
expect(markup).toContain("Reading src/index.ts");
|
||||
expect(markup).not.toContain("Partial streamed answer so far");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
});
|
||||
|
||||
it("shows the streamed result while a subagent runs without progress", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "subagent-streamed-result",
|
||||
kind: "event",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
projectedItem: {
|
||||
position: 0,
|
||||
visibility: "local",
|
||||
sourceThreadId: "thread-1",
|
||||
sourceItemId: "subagent-streamed-result",
|
||||
item: {
|
||||
id: "subagent-streamed-result",
|
||||
threadId: "thread-1",
|
||||
runId: "run-1",
|
||||
nodeId: "node-subagent-1",
|
||||
providerThreadId: "provider-thread-1",
|
||||
providerTurnId: "provider-turn-1",
|
||||
nativeItemRef: null,
|
||||
parentItemId: null,
|
||||
ordinal: 1,
|
||||
status: "running",
|
||||
title: "Package audit",
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
updatedAt: {},
|
||||
type: "subagent",
|
||||
subagentId: "node-subagent-1",
|
||||
origin: "provider_native",
|
||||
driver: "codex",
|
||||
providerInstanceId: "codex",
|
||||
childThreadId: "thread-subagent-1",
|
||||
prompt: "Inspect the package",
|
||||
progress: null,
|
||||
result: "Streaming answer so far",
|
||||
},
|
||||
} as never,
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain("Streaming answer so far");
|
||||
expect(markup).not.toContain("Inspect the package");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
});
|
||||
|
||||
it("treats a cancelled subagent result as partial output", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "subagent-cancelled-result",
|
||||
kind: "event",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
projectedItem: {
|
||||
position: 0,
|
||||
visibility: "local",
|
||||
sourceThreadId: "thread-1",
|
||||
sourceItemId: "subagent-cancelled-result",
|
||||
item: {
|
||||
id: "subagent-cancelled-result",
|
||||
threadId: "thread-1",
|
||||
runId: "run-1",
|
||||
nodeId: "node-subagent-1",
|
||||
providerThreadId: "provider-thread-1",
|
||||
providerTurnId: "provider-turn-1",
|
||||
nativeItemRef: null,
|
||||
parentItemId: null,
|
||||
ordinal: 1,
|
||||
status: "cancelled",
|
||||
title: "Package audit",
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
updatedAt: {},
|
||||
type: "subagent",
|
||||
subagentId: "node-subagent-1",
|
||||
origin: "provider_native",
|
||||
driver: "codex",
|
||||
providerInstanceId: "codex",
|
||||
childThreadId: "thread-subagent-1",
|
||||
prompt: "Inspect the package",
|
||||
progress: "Reading src/index.ts",
|
||||
result: "Partial output before cancel",
|
||||
},
|
||||
} as never,
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain("Partial output before cancel");
|
||||
expect(markup).not.toContain("Reading src/index.ts");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
});
|
||||
|
||||
it("falls back to progress when a completed subagent result is whitespace-only", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "subagent-blank-result",
|
||||
kind: "event",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
projectedItem: {
|
||||
position: 0,
|
||||
visibility: "local",
|
||||
sourceThreadId: "thread-1",
|
||||
sourceItemId: "subagent-blank-result",
|
||||
item: {
|
||||
id: "subagent-blank-result",
|
||||
threadId: "thread-1",
|
||||
runId: "run-1",
|
||||
nodeId: "node-subagent-1",
|
||||
providerThreadId: "provider-thread-1",
|
||||
providerTurnId: "provider-turn-1",
|
||||
nativeItemRef: null,
|
||||
parentItemId: null,
|
||||
ordinal: 1,
|
||||
status: "completed",
|
||||
title: "Package audit",
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
updatedAt: {},
|
||||
type: "subagent",
|
||||
subagentId: "node-subagent-1",
|
||||
origin: "provider_native",
|
||||
driver: "codex",
|
||||
providerInstanceId: "codex",
|
||||
childThreadId: "thread-subagent-1",
|
||||
prompt: "Inspect the package",
|
||||
progress: "Audited 12 packages",
|
||||
result: " \n\t ",
|
||||
},
|
||||
} as never,
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('data-v2-item-type="subagent"');
|
||||
expect(markup).toContain("Audited 12 packages");
|
||||
expect(markup).not.toContain('data-v2-subagent-result-disclosure="true"');
|
||||
});
|
||||
|
||||
it("renders V2 provider failures as standalone error rows", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { OrchestrationV2TurnItem, ThreadId } from "@t3tools/contracts";
|
||||
import type { TimestampFormat } from "@t3tools/contracts/settings";
|
||||
import {
|
||||
BotIcon,
|
||||
ChevronDownIcon,
|
||||
ExternalLinkIcon,
|
||||
GitForkIcon,
|
||||
MessageSquareIcon,
|
||||
@@ -28,6 +29,22 @@ export function isV2LifecycleItem(item: OrchestrationV2TurnItem): boolean {
|
||||
return LIFECYCLE_TYPES.has(item.type);
|
||||
}
|
||||
|
||||
// Aborted subagents (cancelled/interrupted) keep whatever result text had
|
||||
// streamed before the abort, so only completed/failed results are final.
|
||||
const FINAL_RESULT_SUBAGENT_STATUSES = new Set<OrchestrationV2TurnItem["status"]>([
|
||||
"completed",
|
||||
"failed",
|
||||
]);
|
||||
|
||||
// Once a subagent stops, its last streamed result says more than the stale
|
||||
// progress line; while it runs, live progress comes first.
|
||||
const TERMINAL_SUBAGENT_STATUSES = new Set<OrchestrationV2TurnItem["status"]>([
|
||||
"completed",
|
||||
"failed",
|
||||
"cancelled",
|
||||
"interrupted",
|
||||
]);
|
||||
|
||||
export function V2LifecycleRow(props: {
|
||||
readonly item: OrchestrationV2TurnItem;
|
||||
readonly createdAt: string;
|
||||
@@ -115,14 +132,20 @@ export function V2LifecycleRow(props: {
|
||||
);
|
||||
}
|
||||
if (item.type === "subagent") {
|
||||
const streamedResult = item.result?.trim() ? item.result : null;
|
||||
const finalResult = FINAL_RESULT_SUBAGENT_STATUSES.has(item.status) ? streamedResult : null;
|
||||
const detail = TERMINAL_SUBAGENT_STATUSES.has(item.status)
|
||||
? (streamedResult ?? item.progress ?? item.prompt)
|
||||
: (item.progress ?? streamedResult ?? item.prompt);
|
||||
return (
|
||||
<RelatedThreadCard
|
||||
itemType={item.type}
|
||||
icon={BotIcon}
|
||||
title={subagentDisplayTitle(item.title ?? "Subagent")}
|
||||
detail={item.result ?? item.progress ?? item.prompt}
|
||||
detail={detail}
|
||||
badge={item.status}
|
||||
threadId={item.childThreadId}
|
||||
expandedDetail={finalResult}
|
||||
onOpenThread={props.onOpenThread}
|
||||
/>
|
||||
);
|
||||
@@ -135,12 +158,14 @@ function RelatedThreadCard(props: {
|
||||
readonly icon: LucideIcon;
|
||||
readonly title: string;
|
||||
readonly detail: string;
|
||||
readonly expandedDetail?: string | null;
|
||||
readonly badge: string;
|
||||
readonly threadId: ThreadId | null;
|
||||
readonly onOpenThread: (threadId: ThreadId) => void;
|
||||
}) {
|
||||
const Icon = props.icon;
|
||||
const threadId = props.threadId;
|
||||
const expandedDetail = props.expandedDetail ?? null;
|
||||
const content = (
|
||||
<>
|
||||
<Icon className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
@@ -149,12 +174,46 @@ function RelatedThreadCard(props: {
|
||||
<span className="rounded-full border border-border/70 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground">
|
||||
{props.badge}
|
||||
</span>
|
||||
{threadId === null ? null : (
|
||||
<ExternalLinkIcon className="size-3 shrink-0 text-muted-foreground" aria-hidden="true" />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
if (expandedDetail !== null) {
|
||||
return (
|
||||
<div
|
||||
data-v2-item-type={props.itemType}
|
||||
className="relative min-w-0 overflow-hidden rounded-lg border border-border/60 bg-card/30"
|
||||
>
|
||||
<details className="group" data-v2-subagent-result-disclosure="true">
|
||||
<summary
|
||||
aria-label={`Show full result for ${props.title}`}
|
||||
className="flex min-w-0 cursor-pointer list-none items-center gap-2 px-3 py-2 pr-11 text-left transition-colors hover:bg-muted/50 [&::-webkit-details-marker]:hidden"
|
||||
>
|
||||
{content}
|
||||
<ChevronDownIcon
|
||||
className="size-3 shrink-0 text-muted-foreground transition-transform group-open:rotate-180"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</summary>
|
||||
<div className="border-border/60 border-t px-3 py-2" data-v2-subagent-result="true">
|
||||
<p className="max-h-64 overflow-auto whitespace-pre-wrap break-words text-xs leading-relaxed text-muted-foreground">
|
||||
{expandedDetail}
|
||||
</p>
|
||||
</div>
|
||||
</details>
|
||||
{threadId === null ? null : (
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Open ${props.title}`}
|
||||
onClick={() => props.onOpenThread(threadId)}
|
||||
className="absolute top-1.5 right-1.5 flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
|
||||
>
|
||||
<ExternalLinkIcon className="size-3" aria-hidden="true" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return threadId === null ? (
|
||||
<div
|
||||
data-v2-item-type={props.itemType}
|
||||
@@ -171,6 +230,7 @@ function RelatedThreadCard(props: {
|
||||
className="flex w-full min-w-0 items-center gap-2 rounded-lg border border-border/60 bg-card/30 px-3 py-2 text-left transition-colors hover:bg-muted/50"
|
||||
>
|
||||
{content}
|
||||
<ExternalLinkIcon className="size-3 shrink-0 text-muted-foreground" aria-hidden="true" />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user