Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4729,7 +4729,6 @@ function ChatViewContent(props: ChatViewProps) {
<MessagesTimeline
key={activeThread.id}
isWorking={isWorking}
activeTurnInProgress={isWorking || !latestTurnSettled}
activeTurnStartedAt={activeWorkStartedAt}
listRef={legendListRef}
timelineEntries={timelineEntries}
Expand Down
149 changes: 149 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,69 @@ describe("deriveMessagesTimelineRows", () => {
expect(assistantRow?.showAssistantMeta).toBe(false);
expect(assistantRow?.showAssistantCopyButton).toBe(false);
});

it("marks only the unsettled turn work row as in progress", () => {
const rows = deriveMessagesTimelineRows({
timelineEntries: [
{
id: "old-work-entry",
kind: "work",
createdAt: "2026-01-01T00:00:08Z",
entry: {
id: "old-work",
createdAt: "2026-01-01T00:00:08Z",
turnId: "turn-1" as never,
label: "Read files",
tone: "tool" as const,
},
},
{
id: "user-entry",
kind: "message",
createdAt: "2026-01-01T00:00:12Z",
message: {
id: "user-message" as never,
role: "user",
text: "Continue",
turnId: null,
createdAt: "2026-01-01T00:00:12Z",
updatedAt: "2026-01-01T00:00:12Z",
streaming: false,
},
},
{
id: "active-work-entry",
kind: "work",
createdAt: "2026-01-01T00:00:18Z",
entry: {
id: "active-work",
createdAt: "2026-01-01T00:00:18Z",
turnId: "turn-2" as never,
label: "Run tests",
tone: "tool" as const,
},
},
],
latestTurn: {
turnId: "turn-2" as never,
state: "running",
startedAt: "2026-01-01T00:00:16Z",
completedAt: null,
},
expandedTurnIds: new Set(["turn-1" as never]),
isWorking: false,
activeTurnStartedAt: null,
turnDiffSummaryByAssistantMessageId: new Map(),
revertTurnCountByUserMessageId: new Map(),
});

const workRows = rows.filter((row) => row.kind === "work");

expect(workRows.map((row) => [row.id, row.turnInProgress])).toEqual([
["old-work-entry", false],
["active-work-entry", true],
]);
});
});

describe("computeStableMessagesTimelineRows", () => {
Expand Down Expand Up @@ -987,6 +1050,92 @@ describe("computeStableMessagesTimelineRows", () => {
expect(repeated.result[0]).toBe(initial.result[0]);
});

it("reuses settled work rows when a different turn stops running", () => {
const timelineEntries = [
{
id: "old-work-entry",
kind: "work" as const,
createdAt: "2026-01-01T00:00:08Z",
entry: {
id: "old-work",
createdAt: "2026-01-01T00:00:08Z",
turnId: "turn-1" as never,
label: "Read files",
tone: "tool" as const,
},
},
{
id: "user-entry",
kind: "message" as const,
createdAt: "2026-01-01T00:00:12Z",
message: {
id: "user-message" as never,
role: "user" as const,
text: "Continue",
turnId: null,
createdAt: "2026-01-01T00:00:12Z",
updatedAt: "2026-01-01T00:00:12Z",
streaming: false,
},
},
{
id: "active-work-entry",
kind: "work" as const,
createdAt: "2026-01-01T00:00:18Z",
entry: {
id: "active-work",
createdAt: "2026-01-01T00:00:18Z",
turnId: "turn-2" as never,
label: "Run tests",
tone: "tool" as const,
},
},
];

const runningRows = deriveMessagesTimelineRows({
timelineEntries,
latestTurn: {
turnId: "turn-2" as never,
state: "running",
startedAt: "2026-01-01T00:00:16Z",
completedAt: null,
},
expandedTurnIds: new Set(["turn-1" as never, "turn-2" as never]),
isWorking: false,
activeTurnStartedAt: null,
turnDiffSummaryByAssistantMessageId: new Map(),
revertTurnCountByUserMessageId: new Map(),
});
const initial = computeStableMessagesTimelineRows(runningRows, {
byId: new Map(),
result: [],
});

const settledRows = deriveMessagesTimelineRows({
timelineEntries,
latestTurn: {
turnId: "turn-2" as never,
state: "completed",
startedAt: "2026-01-01T00:00:16Z",
completedAt: "2026-01-01T00:00:30Z",
},
expandedTurnIds: new Set(["turn-1" as never, "turn-2" as never]),
isWorking: false,
activeTurnStartedAt: null,
turnDiffSummaryByAssistantMessageId: new Map(),
revertTurnCountByUserMessageId: new Map(),
});

const repeated = computeStableMessagesTimelineRows(settledRows, initial);

expect(repeated.result.find((row) => row.id === "old-work-entry")).toBe(
initial.result.find((row) => row.id === "old-work-entry"),
);
expect(repeated.result.find((row) => row.id === "active-work-entry")).not.toBe(
initial.result.find((row) => row.id === "active-work-entry"),
);
});

it("returns a new result when row order changes without content changes", () => {
const firstUserMessage = {
id: "user-1" as never,
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type MessagesTimelineRow =
id: string;
createdAt: string;
groupedEntries: WorkLogEntry[];
turnInProgress: boolean;
}
| {
kind: "turn-fold";
Expand Down Expand Up @@ -361,6 +362,9 @@ export function deriveMessagesTimelineRows(input: {
id: timelineEntry.id,
createdAt: timelineEntry.createdAt,
groupedEntries,
turnInProgress:
unsettledTurnId !== null &&
groupedEntries.some((entry) => entry.turnId === unsettledTurnId),
});
index = cursor - 1;
continue;
Expand Down Expand Up @@ -460,7 +464,10 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
return a.proposedPlan === (b as typeof a).proposedPlan;

case "work":
return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);
return (
a.turnInProgress === (b as typeof a).turnInProgress &&
Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries)
);

case "message": {
const bm = b as typeof a;
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ const MESSAGE_CREATED_AT = "2026-03-17T19:12:28.000Z";
function buildProps() {
return {
isWorking: false,
activeTurnInProgress: false,
activeTurnStartedAt: null,
listRef: createRef<LegendListRef | null>(),
latestTurn: null,
Expand Down
Loading
Loading