Skip to content

Commit 4c169ed

Browse files
shivamhwpclaude
andcommitted
fix(web): correct agent phase and result state
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 372120a commit 4c169ed

4 files changed

Lines changed: 63 additions & 2 deletions

File tree

apps/web/src/components/AgentsPanelV2.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ describe("AgentsPanelV2", () => {
7878
expect(markup).toContain("Research");
7979
});
8080

81+
it("shows the final result instead of stale progress for a settled agent", () => {
82+
const markup = renderPanel([
83+
agent("settled-agent", {
84+
status: "idle",
85+
progress: "Still working on the old step",
86+
result: "Final answer from the agent",
87+
}),
88+
]);
89+
90+
expect(markup).toContain("Final answer from the agent");
91+
expect(markup).not.toContain("Still working on the old step");
92+
});
93+
8194
it("renders workflow members under their phase", () => {
8295
const markup = renderPanel([
8396
agent("workflow-1", {

apps/web/src/components/AgentsPanelV2.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
deriveOrchestrationV2SubagentPanelState,
33
formatSubagentTokenCount,
4+
isSettledOrchestrationV2Subagent,
45
} from "@t3tools/client-runtime/state/orchestration-v2-subagents";
56
import type {
67
OrchestrationV2Subagent,
@@ -69,7 +70,9 @@ function AgentCard(props: {
6970
activations: ReadonlyArray<OrchestrationV2SubagentActivation>;
7071
}) {
7172
const { agent } = props;
72-
const detail = agent.progress?.trim() || agent.result?.trim() || agent.prompt.trim();
73+
const detail = isSettledOrchestrationV2Subagent(agent)
74+
? agent.result?.trim() || agent.progress?.trim() || agent.prompt.trim()
75+
: agent.progress?.trim() || agent.result?.trim() || agent.prompt.trim();
7376
const usage = usageSummary(agent);
7477
const activities = keyedActivities(agent);
7578
return (

packages/client-runtime/src/state/orchestrationV2Subagents.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,49 @@ describe("deriveOrchestrationV2SubagentPanelState", () => {
137137
expect(result.activationsBySubagentId.get(researcher.id)).toEqual(activations);
138138
});
139139

140+
it("keeps future all-pending workflow phases pending", () => {
141+
const workflow = agent("workflow-1", {
142+
kind: "workflow",
143+
workflow: {
144+
phases: [
145+
{ index: 0, title: "Empty" },
146+
{ index: 1, title: "Queued" },
147+
{ index: 2, title: "Active" },
148+
{ index: 3, title: "Settled" },
149+
],
150+
},
151+
});
152+
const member = (id: string, phaseIndex: number, status: OrchestrationV2Subagent["status"]) =>
153+
agent(id, {
154+
kind: "workflow_agent",
155+
status,
156+
workflowMembership: {
157+
workflowSubagentId: workflowId,
158+
agentIndex: phaseIndex,
159+
phaseIndex,
160+
attempt: 1,
161+
},
162+
});
163+
164+
const result = deriveOrchestrationV2SubagentPanelState({
165+
subagents: [
166+
workflow,
167+
member("queued-a", 1, "pending"),
168+
member("queued-b", 1, "pending"),
169+
member("active", 2, "waiting"),
170+
member("settled", 3, "completed"),
171+
],
172+
activations: [],
173+
});
174+
175+
expect(result.groups[0]?.phases.map((phase) => phase.status)).toEqual([
176+
"pending",
177+
"pending",
178+
"running",
179+
"done",
180+
]);
181+
});
182+
140183
it("distinguishes unavailable usage from a reported zero", () => {
141184
const unavailable = deriveOrchestrationV2SubagentPanelState({
142185
subagents: [agent("unreported")],

packages/client-runtime/src/state/orchestrationV2Subagents.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ const phaseStatus = (agents: ReadonlyArray<OrchestrationV2Subagent>) =>
4040
? ("pending" as const)
4141
: agents.every(isSettledOrchestrationV2Subagent)
4242
? ("done" as const)
43-
: ("running" as const);
43+
: agents.every((agent) => agent.status === "pending")
44+
? ("pending" as const)
45+
: ("running" as const);
4446

4547
export function deriveOrchestrationV2SubagentPanelState(input: {
4648
readonly subagents: ReadonlyArray<OrchestrationV2Subagent>;

0 commit comments

Comments
 (0)