fix(web): stop marking mixed tool runs as failed (#7893)
This commit is contained in:
1 parent
11f051373e
commit
ce91284f83
7 files changed
+230
-6
No files matched your search
@@ -342,11 +342,17 @@ export function projectActivityPayload(
|
||||
return activity;
|
||||
}
|
||||
|
||||
const itemStatus = asRecord(data.item)?.status;
|
||||
const projectedPayload =
|
||||
payload.status === "completed" && (itemStatus === "failed" || itemStatus === "declined")
|
||||
? { ...payload, status: itemStatus }
|
||||
: payload;
|
||||
|
||||
if (payload.itemType === "mcp_tool_call") {
|
||||
return {
|
||||
...activity,
|
||||
payload: {
|
||||
...payload,
|
||||
...projectedPayload,
|
||||
data: projectMcpToolCallData(data),
|
||||
},
|
||||
};
|
||||
@@ -384,7 +390,7 @@ export function projectActivityPayload(
|
||||
return {
|
||||
...activity,
|
||||
payload: {
|
||||
...payload,
|
||||
...projectedPayload,
|
||||
data: projectedData,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -614,6 +614,66 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("preserves failed and declined outcomes on completed tool items", () =>
|
||||
Effect.gen(function* () {
|
||||
const { adapter, runtime } = yield* startLifecycleRuntime();
|
||||
const items = [
|
||||
{
|
||||
type: "commandExecution",
|
||||
id: "failed-command",
|
||||
command: "vp test run",
|
||||
commandActions: [],
|
||||
cwd: "/tmp",
|
||||
exitCode: 1,
|
||||
status: "failed",
|
||||
},
|
||||
{
|
||||
type: "mcpToolCall",
|
||||
id: "failed-mcp",
|
||||
server: "simulator",
|
||||
tool: "build",
|
||||
arguments: {},
|
||||
error: { message: "Build failed" },
|
||||
status: "failed",
|
||||
},
|
||||
{
|
||||
type: "fileChange",
|
||||
id: "declined-change",
|
||||
changes: [],
|
||||
status: "declined",
|
||||
},
|
||||
] as const;
|
||||
|
||||
for (const item of items) {
|
||||
const firstEventFiber = yield* Stream.runHead(adapter.streamEvents).pipe(Effect.forkChild);
|
||||
|
||||
yield* runtime.emit({
|
||||
id: asEventId(`evt-${item.id}`),
|
||||
kind: "notification",
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
method: "item/completed",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-1"),
|
||||
itemId: asItemId(item.id),
|
||||
payload: {
|
||||
completedAtMs: 1_778_000_000_000,
|
||||
threadId: "thread-1",
|
||||
turnId: "turn-1",
|
||||
item,
|
||||
},
|
||||
});
|
||||
|
||||
const firstEvent = yield* Fiber.join(firstEventFiber);
|
||||
NodeAssert.equal(firstEvent._tag, "Some");
|
||||
if (firstEvent._tag !== "Some" || firstEvent.value.type !== "item.completed") {
|
||||
return;
|
||||
}
|
||||
NodeAssert.equal(firstEvent.value.payload.status, item.status);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("maps completed plan items to canonical proposed-plan completion events", () =>
|
||||
Effect.gen(function* () {
|
||||
const { adapter, runtime } = yield* startLifecycleRuntime();
|
||||
|
||||
@@ -480,7 +480,9 @@ function mapItemLifecycle(
|
||||
lifecycle === "item.started"
|
||||
? "inProgress"
|
||||
: lifecycle === "item.completed"
|
||||
? "completed"
|
||||
? "status" in item && (item.status === "failed" || item.status === "declined")
|
||||
? item.status
|
||||
: "completed"
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
|
||||
@@ -220,6 +220,40 @@ describe("projectActivityPayload", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves failed stored tool outcomes for web and mobile clients", () => {
|
||||
const activities = [
|
||||
makeActivity("failed-command", "command_execution", {
|
||||
item: {
|
||||
command: "vp test run",
|
||||
exitCode: 1,
|
||||
status: "failed",
|
||||
},
|
||||
}),
|
||||
makeActivity("failed-mcp", "mcp_tool_call", {
|
||||
item: {
|
||||
server: "simulator",
|
||||
tool: "build",
|
||||
arguments: {},
|
||||
status: "failed",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
for (const activity of activities) {
|
||||
const projected = projectActivityPayload(activity);
|
||||
expect(projected.payload).toMatchObject({ status: "failed" });
|
||||
|
||||
const [webEntry] = deriveWorkLogEntries([projected]);
|
||||
expect(webEntry?.toolLifecycleStatus).toBe("failed");
|
||||
|
||||
const [mobileGroup] = buildThreadFeed(makeThread([projected]));
|
||||
expect(mobileGroup).toMatchObject({ type: "activity-group" });
|
||||
if (mobileGroup?.type === "activity-group") {
|
||||
expect(mobileGroup.activities[0]?.status).toBe("failure");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("projects snapshot and event transports without mutating their sources", () => {
|
||||
const activity = fixtures[0]!;
|
||||
const thread = makeThread([activity]);
|
||||
|
||||
@@ -1374,6 +1374,91 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expanded: true,
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["recovered", ["failed", "completed"], false],
|
||||
["ending in failure", ["completed", "failed"], true],
|
||||
["failed", ["failed", "failed"], true],
|
||||
] as const)("uses the final call for %s tool groups", (_, statuses, hasFailure) => {
|
||||
const timelineEntries = statuses.map((status, index) => ({
|
||||
id: `work-entry-${index}`,
|
||||
kind: "work" as const,
|
||||
createdAt: `2026-01-01T00:00:0${index}Z`,
|
||||
entry: {
|
||||
id: `work-${index}`,
|
||||
createdAt: `2026-01-01T00:00:0${index}Z`,
|
||||
label: "Ran command",
|
||||
tone: "tool" as const,
|
||||
itemType: "command_execution" as const,
|
||||
toolLifecycleStatus: status,
|
||||
},
|
||||
}));
|
||||
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries,
|
||||
isWorking: false,
|
||||
activeTurnStartedAt: null,
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.find((row) => row.kind === "work-toggle")).toMatchObject({
|
||||
hiddenCount: 2,
|
||||
hasFailure,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps a failure visible when other hidden entries succeeded", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "failed-work-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "failed-work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
label: "Ran command",
|
||||
tone: "tool",
|
||||
toolLifecycleStatus: "failed",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "completed-work-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
entry: {
|
||||
id: "completed-work",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
label: "Ran command",
|
||||
tone: "tool",
|
||||
toolLifecycleStatus: "completed",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "visible-info-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
entry: {
|
||||
id: "visible-info",
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
label: "Status updated",
|
||||
tone: "info",
|
||||
},
|
||||
},
|
||||
],
|
||||
isWorking: false,
|
||||
activeTurnStartedAt: null,
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.find((row) => row.kind === "work-toggle")).toMatchObject({
|
||||
hiddenCount: 2,
|
||||
summary: null,
|
||||
hasFailure: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("computeStableMessagesTimelineRows", () => {
|
||||
|
||||
@@ -894,9 +894,7 @@ export function deriveMessagesTimelineRows(input: {
|
||||
onlyToolEntries: true,
|
||||
summary: summarizeToolGroup(visibleGroupedEntries),
|
||||
summaryKind,
|
||||
hasFailure: visibleGroupedEntries.some((entry) =>
|
||||
workEntryDisplayIndicatesToolFailure(entry),
|
||||
),
|
||||
hasFailure: workEntryDisplayIndicatesToolFailure(visibleGroupedEntries.at(-1)!),
|
||||
});
|
||||
if (expanded) {
|
||||
for (const [entryIndex, workEntry] of visibleGroupedEntries.entries()) {
|
||||
|
||||
@@ -813,6 +813,45 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
|
||||
});
|
||||
|
||||
it("keeps mixed-success tool groups neutral", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "entry-failed",
|
||||
kind: "work",
|
||||
createdAt: "2026-03-17T19:12:28.000Z",
|
||||
entry: {
|
||||
id: "work-failed",
|
||||
createdAt: "2026-03-17T19:12:28.000Z",
|
||||
label: "Run search",
|
||||
tone: "tool",
|
||||
itemType: "command_execution",
|
||||
toolLifecycleStatus: "failed",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "entry-completed",
|
||||
kind: "work",
|
||||
createdAt: "2026-03-17T19:12:29.000Z",
|
||||
entry: {
|
||||
id: "work-completed",
|
||||
createdAt: "2026-03-17T19:12:29.000Z",
|
||||
label: "Run tests",
|
||||
tone: "tool",
|
||||
itemType: "command_execution",
|
||||
toolLifecycleStatus: "completed",
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("Ran 2 commands");
|
||||
expect(markup).not.toContain('aria-label="Tool call failed"');
|
||||
});
|
||||
|
||||
it("shows the animated one-line label for a live tool group", () => {
|
||||
const turnId = TurnId.make("turn-live");
|
||||
const markup = renderToStaticMarkup(
|
||||
|
||||
Reference in new issue
Block a user