@devries-cameron20 / t3code-1 / commits / f6787e8537
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): reuse timeline rows while thinking and plans stream (#24121)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Batuhan1999 committed Nov 13, 2026 at 00:47 UTC f6787e8537b6773bd8089c9459726340f39b3266
5 files changed +484 -15
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+219 -1
@@ -18,7 +18,11 @@ import {
18 workEntryDisplayIndicatesToolFailure,
19 type TimelineEntry,
20 } from "../../session-logic";
21 -import { makeStreamingTimelineFixture } from "../../test-fixtures";
21 +import {
22 + makeStreamingTimelineFixture,
23 + makeStreamingWorkTimelineFixture,
24 + withStreamedText,
25 +} from "../../test-fixtures";
26 import type { TurnDiffSummary } from "../../types";
27 import { describe, expect, it } from "vite-plus/test";
28 import { MessageId, RunId } from "@t3tools/contracts";
@@ -3891,6 +3895,220 @@ describe("streaming v2 row projection", () => {
3895 })),
3896 });
3897 });
3898 +
3899 + it.each(["reasoning", "proposed_plan"] as const)(
3900 + "keeps every row not holding streaming %s text when it changes",
3901 + (kind) => {
3902 + const source = makeStreamingWorkTimelineFixture(kind);
3903 + const rowsInput = (timelineEntries: ReadonlyArray<TimelineEntry>) => ({
3904 + timelineEntries,
3905 + latestRun: {
3906 + runId: source.runId,
3907 + status: "running" as const,
3908 + startedAt: source.time(5),
3909 + completedAt: null,
3910 + },
3911 + runningRunId: source.runId,
3912 + isWorking: true,
3913 + activeTurnStartedAt: source.time(5),
3914 + turnDiffSummaries: [],
3915 + supportsConversationRollback: true,
3916 + });
3917 + let timelineInput = {
3918 + visibleTurnItems: withStreamedText(
3919 + source.visibleTurnItems,
3920 + source.streamingItemId,
3921 + "Let",
3922 + source.time(20),
3923 + ),
3924 + optimisticMessages: [],
3925 + };
3926 + let timeline = deriveTimelineEntriesFromVisibleTurnItemsWithState(timelineInput);
3927 + let projection = deriveMessagesTimelineRowsWithState(rowsInput(timeline.entries));
3928 + for (const [step, text] of ["Let me", "Let me check the tests"].entries()) {
3929 + timelineInput = {
3930 + visibleTurnItems: withStreamedText(
3931 + timelineInput.visibleTurnItems,
3932 + source.streamingItemId,
3933 + text,
3934 + source.time(21 + step),
3935 + ),
3936 + optimisticMessages: [],
3937 + };
3938 + const previous = projection;
3939 + timeline = deriveTimelineEntriesFromVisibleTurnItemsWithState(timelineInput, timeline);
3940 + projection = deriveMessagesTimelineRowsWithState(rowsInput(timeline.entries), previous);
3941 + expect(projection.rows).toEqual(
3942 + deriveMessagesTimelineRows(
3943 + rowsInput(deriveTimelineEntriesFromVisibleTurnItems(timelineInput)),
3944 + ),
3945 + );
3946 + expect(projection.rows).toHaveLength(previous.rows.length);
3947 + for (const [index, row] of previous.rows.entries()) {
3948 + const holdsItem =
3949 + row.id === source.streamingItemId ||
3950 + ((row.kind === "work" || row.kind === "work-live") &&
3951 + row.groupedEntries.some((entry) => entry.id === source.streamingItemId));
3952 + if (!holdsItem) expect(projection.rows[index]).toBe(row);
3953 + }
3954 + }
3955 + },
3956 + );
3957 +
3958 + it.each(["reasoning", "proposed_plan"] as const)(
3959 + "matches a full derivation when streaming %s text turns blank or completes",
3960 + (kind) => {
3961 + const source = makeStreamingWorkTimelineFixture(kind);
3962 + const rowsInput = (timelineEntries: ReadonlyArray<TimelineEntry>) => ({
3963 + timelineEntries,
3964 + latestRun: {
3965 + runId: source.runId,
3966 + status: "running" as const,
3967 + startedAt: source.time(5),
3968 + completedAt: null,
3969 + },
3970 + runningRunId: source.runId,
3971 + isWorking: true,
3972 + activeTurnStartedAt: source.time(5),
3973 + turnDiffSummaries: [],
3974 + supportsConversationRollback: true,
3975 + });
3976 + let visibleTurnItems = source.visibleTurnItems;
3977 + let timeline = deriveTimelineEntriesFromVisibleTurnItemsWithState({
3978 + visibleTurnItems,
3979 + optimisticMessages: [],
3980 + });
3981 + let projection = deriveMessagesTimelineRowsWithState(rowsInput(timeline.entries));
3982 + const steps = [
3983 + ...["Let", " ", "Let me"].map(
3984 + (text, step) => (rows: typeof visibleTurnItems) =>
3985 + withStreamedText(rows, source.streamingItemId, text, source.time(20 + step)),
3986 + ),
3987 + (rows: typeof visibleTurnItems) =>
3988 + rows.map((row) =>
3989 + row.item.id === source.streamingItemId &&
3990 + (row.item.type === "reasoning" || row.item.type === "proposed_plan")
3991 + ? {
3992 + ...row,
3993 + item: {
3994 + ...row.item,
3995 + status: "completed" as const,
3996 + streaming: false,
3997 + completedAt: DateTime.makeUnsafe(source.time(30)),
3998 + updatedAt: DateTime.makeUnsafe(source.time(30)),
3999 + },
4000 + }
4001 + : row,
4002 + ),
4003 + ];
4004 + for (const step of steps) {
4005 + visibleTurnItems = step(visibleTurnItems);
4006 + const timelineInput = { visibleTurnItems, optimisticMessages: [] };
4007 + timeline = deriveTimelineEntriesFromVisibleTurnItemsWithState(timelineInput, timeline);
4008 + expect(timeline.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(timelineInput));
4009 + projection = deriveMessagesTimelineRowsWithState(rowsInput(timeline.entries), projection);
4010 + expect(projection.rows).toEqual(
4011 + deriveMessagesTimelineRows(
4012 + rowsInput(deriveTimelineEntriesFromVisibleTurnItems(timelineInput)),
4013 + ),
4014 + );
4015 + }
4016 + },
4017 + );
4018 +
4019 + it.each([
4020 + "expanded live group",
4021 + "expanded live group followed by a hidden tool",
4022 + "thinking superseded by a running tool",
4023 + "settled turn",
4024 + ] as const)("matches a full derivation when streaming thinking sits in a %s", (scenario) => {
4025 + const source = makeStreamingWorkTimelineFixture("reasoning");
4026 + const running = scenario !== "settled turn";
4027 + const hiddenTool = scenario === "expanded live group followed by a hidden tool";
4028 + const rowsInput = (
4029 + timelineEntries: ReadonlyArray<TimelineEntry>,
4030 + expandedWorkGroupIds?: ReadonlySet<string>,
4031 + ) => ({
4032 + timelineEntries,
4033 + latestRun: {
4034 + runId: source.runId,
4035 + status: running ? ("running" as const) : ("completed" as const),
4036 + startedAt: source.time(5),
4037 + completedAt: running ? null : source.time(40),
4038 + },
4039 + runningRunId: running ? source.runId : null,
4040 + isWorking: running,
4041 + activeTurnStartedAt: source.time(5),
4042 + turnDiffSummaries: [],
4043 + supportsConversationRollback: true,
4044 + ...(expandedWorkGroupIds ? { expandedWorkGroupIds } : {}),
4045 + ...(running ? {} : { expandedRunIds: new Set([source.runId]) }),
4046 + ...(hiddenTool ? { toolCallVisibility: "hideAll" as const } : {}),
4047 + });
4048 + const tool = source.visibleTurnItems.find((row) => row.item.id === "live-work")!;
4049 + const laterTool = (status: "running" | "completed") => ({
4050 + ...tool,
4051 + position: source.visibleTurnItems.length,
4052 + sourceItemId: TurnItemId.make("live-later-tool"),
4053 + item: {
4054 + ...tool.item,
4055 + id: TurnItemId.make("live-later-tool"),
4056 + ordinal: 8,
4057 + status,
4058 + ...(status === "running" ? { completedAt: null } : {}),
4059 + },
4060 + });
4061 + let visibleTurnItems =
4062 + scenario === "thinking superseded by a running tool" || hiddenTool
4063 + ? [...source.visibleTurnItems, laterTool(hiddenTool ? "completed" : "running")]
4064 + : // Alone in a settled group, the thought's text becomes the group summary.
4065 + source.visibleTurnItems.filter((row) => running || row !== tool);
4066 + visibleTurnItems = withStreamedText(
4067 + visibleTurnItems,
4068 + source.streamingItemId,
4069 + "Let",
4070 + source.time(20),
4071 + );
4072 + let timeline = deriveTimelineEntriesFromVisibleTurnItemsWithState({
4073 + visibleTurnItems,
4074 + optimisticMessages: [],
4075 + });
4076 + const liveRow = deriveMessagesTimelineRows(rowsInput(timeline.entries)).find(
4077 + (row) => row.kind === "work-live",
4078 + );
4079 + const expanded =
4080 + scenario.startsWith("expanded live group") && liveRow?.kind === "work-live"
4081 + ? new Set([liveRow.groupId])
4082 + : undefined;
4083 + let projection = deriveMessagesTimelineRowsWithState(rowsInput(timeline.entries, expanded));
4084 + for (const [step, text] of ["Let me", "Let me check the tests"].entries()) {
4085 + visibleTurnItems = withStreamedText(
4086 + visibleTurnItems,
4087 + source.streamingItemId,
4088 + text,
4089 + source.time(21 + step),
4090 + );
4091 + const timelineInput = { visibleTurnItems, optimisticMessages: [] };
4092 + const previous = projection;
4093 + timeline = deriveTimelineEntriesFromVisibleTurnItemsWithState(timelineInput, timeline);
4094 + projection = deriveMessagesTimelineRowsWithState(
4095 + rowsInput(timeline.entries, expanded),
4096 + previous,
4097 + );
4098 + expect(projection.rows).toEqual(
4099 + deriveMessagesTimelineRows(
4100 + rowsInput(deriveTimelineEntriesFromVisibleTurnItems(timelineInput), expanded),
4101 + ),
4102 + );
4103 + if (!running) continue;
4104 + for (const [index, row] of previous.rows.entries()) {
4105 + const holdsItem =
4106 + (row.kind === "work" || row.kind === "work-live") &&
4107 + row.groupedEntries.some((entry) => entry.id === source.streamingItemId);
4108 + if (!holdsItem) expect(projection.rows[index]).toBe(row);
4109 + }
4110 + }
4111 + });
4112 });
4113
4114 describe("linked timeline resources", () => {
apps/web/src/components/chat/MessagesTimeline.logic.ts
+97 -4
@@ -2481,19 +2481,33 @@ function replaceStreamingMessageRows(
2481 return null;
2482 }
2483 const replacements = new Map<ChatMessage, Extract<TimelineEntry, { kind: "message" }>>();
2484 + const thoughts = new Map<string, WorkLogEntry>();
2485 + const plans = new Map<string, ProposedPlan>();
2486 for (let index = 0; index < timelineEntries.length; index += 1) {
2487 const entry = timelineEntries[index]!;
2488 const previousEntry = previousEntries[index]!;
2489 if (entry === previousEntry) continue;
2490 if (
2489 - entry.kind !== "message" ||
2490 - previousEntry.kind !== "message" ||
2491 + entry.kind !== previousEntry.kind ||
2492 entry.id !== previousEntry.id ||
2493 entry.createdAt !== previousEntry.createdAt ||
2494 entry.attempt !== previousEntry.attempt
2495 ) {
2496 return null;
2497 }
2498 + if (entry.kind === "work" && previousEntry.kind === "work") {
2499 + if (!isStreamingThoughtUpdate(previousEntry.entry, entry.entry)) return null;
2500 + thoughts.set(entry.id, entry.entry);
2501 + continue;
2502 + }
2503 + if (entry.kind === "proposed-plan" && previousEntry.kind === "proposed-plan") {
2504 + const { planMarkdown: _before, updatedAt: _beforeAt, ...before } = previousEntry.proposedPlan;
2505 + const { planMarkdown: _after, updatedAt: _afterAt, ...after } = entry.proposedPlan;
2506 + if (!shallow(before, after)) return null;
2507 + plans.set(entry.id, entry.proposedPlan);
2508 + continue;
2509 + }
2510 + if (entry.kind !== "message" || previousEntry.kind !== "message") return null;
2511 if (
2512 entry.projectedItem !== previousEntry.projectedItem &&
2513 (entry.projectedItem === undefined ||
@@ -2510,8 +2524,54 @@ function replaceStreamingMessageRows(
2524 if (!isStreamingMessageTextUpdate(previousEntry.message, entry.message)) return null;
2525 replacements.set(previousEntry.message, entry);
2526 }
2513 - if (replacements.size === 0) return previous.rows;
2514 - return previous.rows.map((row) => {
2527 + if (replacements.size === 0 && thoughts.size === 0 && plans.size === 0) return previous.rows;
2528 + // Rows settle superseded thinking after tool visibility filtering, which these entries
2529 + // have not seen; the fast path keeps item status, so the row's settled status still holds.
2530 + const patchedThoughts = new Map<WorkLogEntry, WorkLogEntry>();
2531 + const patchThought = (entry: WorkLogEntry) => {
2532 + const thought = thoughts.get(entry.id);
2533 + if (!thought) return entry;
2534 + let patched = patchedThoughts.get(entry);
2535 + if (!patched) {
2536 + patched =
2537 + entry.toolLifecycleStatus === thought.toolLifecycleStatus ||
2538 + entry.toolLifecycleStatus === undefined
2539 + ? thought
2540 + : { ...thought, toolLifecycleStatus: entry.toolLifecycleStatus };
2541 + patchedThoughts.set(entry, patched);
2542 + }
2543 + return patched;
2544 + };
2545 + const patchedGroups = new Map<WorkLogEntry[], WorkLogEntry[]>();
2546 + const patchGroup = (group: WorkLogEntry[]) => {
2547 + if (!group.some((entry) => thoughts.has(entry.id))) return group;
2548 + const patched = patchedGroups.get(group) ?? group.map(patchThought);
2549 + patchedGroups.set(group, patched);
2550 + return patched;
2551 + };
2552 + const patchedLiveThoughtIds = new Set<string>();
2553 + const rows = previous.rows.map((row): MessagesTimelineRow => {
2554 + if (row.kind === "proposed-plan") {
2555 + const proposedPlan = plans.get(row.id);
2556 + return proposedPlan ? { ...row, proposedPlan } : row;
2557 + }
2558 + if (row.kind === "work-live") {
2559 + const groupedEntries = patchGroup(row.groupedEntries);
2560 + if (groupedEntries === row.groupedEntries) return row;
2561 + for (const entry of groupedEntries) {
2562 + if (thoughts.has(entry.id)) patchedLiveThoughtIds.add(entry.id);
2563 + }
2564 + return {
2565 + ...row,
2566 + entry: patchThought(row.entry),
2567 + groupedEntries,
2568 + ...(row.thought ? { thought: patchThought(row.thought) } : {}),
2569 + };
2570 + }
2571 + if (row.kind === "work") {
2572 + const groupedEntries = patchGroup(row.groupedEntries);
2573 + return groupedEntries === row.groupedEntries ? row : { ...row, groupedEntries };
2574 + }
2575 if (row.kind !== "message" && row.kind !== "assistant-meta") return row;
2576 const entry = replacements.get(row.message);
2577 return entry
@@ -2522,6 +2582,39 @@ function replaceStreamingMessageRows(
2582 }
2583 : row;
2584 });
2585 + // Only a live row holds thinking without deriving a label from its text. Settled
2586 + // groups, folded turns, and work toggles summarize it, so they need the full rebuild.
2587 + for (const id of thoughts.keys()) if (!patchedLiveThoughtIds.has(id)) return null;
2588 + return rows;
2589 +}
2590 +
2591 +/**
2592 + * Rows read a thought's text only through its blankness (visibility, the live
2593 + * thought line) and through labels that live rows do not store.
2594 + */
2595 +function isStreamingThoughtUpdate(previous: WorkLogEntry, next: WorkLogEntry): boolean {
2596 + if (
2597 + previous.itemType !== "reasoning" ||
2598 + previous.projectedItem === undefined ||
2599 + next.projectedItem === undefined ||
2600 + !isStreamingTurnItemTextUpdate(previous.projectedItem, next.projectedItem) ||
2601 + Boolean(previous.detail?.trim()) !== Boolean(next.detail?.trim())
2602 + ) {
2603 + return false;
2604 + }
2605 + const {
2606 + detail: _before,
2607 + structuredPayload: _beforeItem,
2608 + projectedItem: _beforeRow,
2609 + ...rest
2610 + } = previous;
2611 + const {
2612 + detail: _after,
2613 + structuredPayload: _afterItem,
2614 + projectedItem: _afterRow,
2615 + ...nextRest
2616 + } = next;
2617 + return shallow(rest, nextRest);
2618 }
2619
2620 export function deriveMessagesTimelineRowsWithState(
apps/web/src/session-logic.test.ts
+83 -1
@@ -12,6 +12,7 @@ import {
12 ScheduledTaskId,
13 ThreadId,
14 TurnItemId,
15 + type OrchestrationV2PlanArtifact,
16 type OrchestrationV2ProjectedTurnItem,
17 type OrchestrationV2ExecutionNode,
18 type OrchestrationV2RunAttempt,
@@ -38,9 +39,30 @@ import {
39 workEntryDisplayIndicatesToolFailure,
40 workEntryIndicatesToolSuccess,
41 } from "./session-logic";
41 -import { makeStreamingTimelineFixture, makeThreadProjectionFixture } from "./test-fixtures";
42 +import {
43 + makeStreamingTimelineFixture,
44 + makeStreamingWorkTimelineFixture,
45 + makeThreadProjectionFixture,
46 + withStreamedText,
47 +} from "./test-fixtures";
48 import type { ChatMessage } from "./types";
49
50 +function streamingPlanArtifact(
51 + fixture: ReturnType<typeof makeStreamingWorkTimelineFixture>,
52 + markdown: string,
53 + status: "active" | "superseded",
54 +): OrchestrationV2PlanArtifact {
55 + return {
56 + id: PlanId.make("live-plan"),
57 + threadId: fixture.threadId,
58 + runId: fixture.runId,
59 + nodeId: NodeId.make("live-node"),
60 + kind: "proposed_plan",
61 + markdown,
62 + status,
63 + };
64 +}
65 +
66 describe("V2 session presentation", () => {
67 it("uses run status as the settlement boundary", () => {
68 const runId = RunId.make("run-1");
@@ -1700,6 +1722,66 @@ describe("incremental v2 timeline entries", () => {
1722 "live-assistant",
1723 ]);
1724 });
1725 +
1726 + it("keeps every other entry when streaming plan text changes", () => {
1727 + const fixture = makeStreamingWorkTimelineFixture("proposed_plan");
1728 + // Codex emits `plan.updated` with each delta, so the artifact array is rebuilt too.
1729 + const plans = (markdown: string) => [streamingPlanArtifact(fixture, markdown, "active")];
1730 + let input = {
1731 + visibleTurnItems: withStreamedText(
1732 + fixture.visibleTurnItems,
1733 + fixture.streamingItemId,
1734 + "Let",
1735 + fixture.time(20),
1736 + ),
1737 + optimisticMessages: [],
1738 + plans: plans("Let"),
1739 + };
1740 + let projection = deriveTimelineEntriesFromVisibleTurnItemsWithState(input);
1741 + for (const [step, text] of ["Let me", "Let me check the tests"].entries()) {
1742 + input = {
1743 + visibleTurnItems: withStreamedText(
1744 + input.visibleTurnItems,
1745 + fixture.streamingItemId,
1746 + text,
1747 + fixture.time(21 + step),
1748 + ),
1749 + optimisticMessages: [],
1750 + plans: plans(text),
1751 + };
1752 + const previous = projection;
1753 + projection = deriveTimelineEntriesFromVisibleTurnItemsWithState(input, previous);
1754 + expect(projection.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(input));
1755 + for (const [index, entry] of previous.entries.entries()) {
1756 + if (entry.id !== fixture.streamingItemId) expect(projection.entries[index]).toBe(entry);
1757 + }
1758 + }
1759 + });
1760 +
1761 + it("rebuilds the plan entry when only its artifact status changes", () => {
1762 + const fixture = makeStreamingWorkTimelineFixture("proposed_plan");
1763 + const visibleTurnItems = withStreamedText(
1764 + fixture.visibleTurnItems,
1765 + fixture.streamingItemId,
1766 + "Plan",
1767 + fixture.time(20),
1768 + );
1769 + const previous = deriveTimelineEntriesFromVisibleTurnItemsWithState({
1770 + visibleTurnItems,
1771 + optimisticMessages: [],
1772 + plans: [streamingPlanArtifact(fixture, "Plan", "active")],
1773 + });
1774 + const input = {
1775 + visibleTurnItems,
1776 + optimisticMessages: [],
1777 + plans: [streamingPlanArtifact(fixture, "Plan", "superseded")],
1778 + };
1779 + const next = deriveTimelineEntriesFromVisibleTurnItemsWithState(input, previous);
1780 + expect(next.entries).toEqual(deriveTimelineEntriesFromVisibleTurnItems(input));
1781 + expect(next.entries.find((entry) => entry.kind === "proposed-plan")).toMatchObject({
1782 + proposedPlan: { status: "superseded" },
1783 + });
1784 + });
1785 });
1786
1787 describe("image asset requests", () => {
apps/web/src/session-logic.ts
+35 -8
@@ -822,24 +822,34 @@ export function isStreamingMessageTextUpdate(previous: ChatMessage, next: ChatMe
822 return shallow(previousMetadata, nextMetadata);
823 }
824
825 +function streamedTextMetadata(item: OrchestrationV2TurnItem) {
826 + if (item.type === "proposed_plan" && item.streaming) {
827 + const { markdown: _markdown, updatedAt: _updatedAt, ...metadata } = item;
828 + return metadata;
829 + }
830 + if ((item.type === "assistant_message" || item.type === "reasoning") && item.streaming) {
831 + const { text: _text, updatedAt: _updatedAt, ...metadata } = item;
832 + return metadata;
833 + }
834 + return null;
835 +}
836 +
837 export function isStreamingTurnItemTextUpdate(
838 previous: OrchestrationV2ProjectedTurnItem,
839 next: OrchestrationV2ProjectedTurnItem,
840 ): boolean {
841 const { item: previousItem, ...previousSource } = previous;
842 const { item: nextItem, ...nextSource } = next;
843 + const previousMetadata = streamedTextMetadata(previousItem);
844 + const nextMetadata = streamedTextMetadata(nextItem);
845 if (
832 - previousItem.type !== "assistant_message" ||
833 - nextItem.type !== "assistant_message" ||
834 - !previousItem.streaming ||
835 - !nextItem.streaming ||
846 + previousMetadata === null ||
847 + nextMetadata === null ||
848 !shallow(previousSource, nextSource) ||
849 projectedItemCreatedAt(previous) !== projectedItemCreatedAt(next)
850 ) {
851 return false;
852 }
841 - const { text: _previousText, updatedAt: _previousUpdatedAt, ...previousMetadata } = previousItem;
842 - const { text: _nextText, updatedAt: _nextUpdatedAt, ...nextMetadata } = nextItem;
853 // Wire decoding recreates timestamps and attachments; compare only the changed item's metadata.
854 return Equal.equals(previousMetadata, nextMetadata);
855 }
@@ -865,6 +875,19 @@ function canRederiveInPlace(
875 );
876 }
877
878 +/** Entries read only each plan's status; streaming plans rebuild artifacts with every delta. */
879 +function samePlanStatuses(
880 + next: TimelineEntriesInput["plans"],
881 + previous: TimelineEntriesInput["plans"],
882 +): boolean {
883 + if (next === previous) return true;
884 + if (next === undefined || previous === undefined || next.length !== previous.length) return false;
885 + return next.every((plan, index) => {
886 + const before = previous[index]!;
887 + return plan.id === before.id && plan.kind === before.kind && plan.status === before.status;
888 + });
889 +}
890 +
891 function reuseTimelineEntries(
892 input: TimelineEntriesInput,
893 previous: TimelineEntriesProjection,
@@ -877,7 +900,7 @@ function reuseTimelineEntries(
900 !shallow(input.attachmentUrlById, before.attachmentUrlById) ||
901 !shallow(input.attempts, before.attempts) ||
902 !shallow(input.nodes, before.nodes) ||
880 - !shallow(input.plans, before.plans)
903 + !samePlanStatuses(input.plans, before.plans)
904 ) {
905 return null;
906 }
@@ -910,7 +933,11 @@ function reuseTimelineEntries(
933 const previousItem = before.visibleTurnItems[index]!;
934 const item = input.visibleTurnItems[index]!;
935 if (item === previousItem) continue;
913 - if (isStreamingTurnItemTextUpdate(previousItem, item)) {
936 + // Reasoning and plan text re-derive below; only assistant text patches the message.
937 + if (
938 + item.item.type === "assistant_message" &&
939 + isStreamingTurnItemTextUpdate(previousItem, item)
940 + ) {
941 replacements.set(previousItem, item);
942 continue;
943 }
apps/web/src/test-fixtures.ts
+50 -1
@@ -2,6 +2,7 @@ import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
2 import {
3 EnvironmentId,
4 MessageId,
5 + PlanId,
6 RunId,
7 TurnItemId,
8 type OrchestrationV2ProjectedTurnItem,
@@ -219,5 +220,53 @@ export function makeStreamingTimelineFixture(text = "") {
220 sourceItemId: item.id,
221 item,
222 }));
222 - return { threadId, runId, historyRunId, visibleTurnItems, time };
223 + return { threadId, runId, historyRunId, visibleTurnItems, time, base };
224 +}
225 +
226 +/** The streaming fixture, ending in streaming thinking or a streaming plan instead of assistant text. */
227 +export function makeStreamingWorkTimelineFixture(kind: "reasoning" | "proposed_plan") {
228 + const fixture = makeStreamingTimelineFixture();
229 + const live = {
230 + ...fixture.base("live-streaming", fixture.runId, 7),
231 + status: "running" as const,
232 + completedAt: null,
233 + };
234 + const streamingItem: OrchestrationV2TurnItem =
235 + kind === "proposed_plan"
236 + ? {
237 + ...live,
238 + type: "proposed_plan",
239 + planId: PlanId.make("live-plan"),
240 + markdown: "",
241 + streaming: true,
242 + }
243 + : { ...live, type: "reasoning", text: "", streaming: true };
244 + const visibleTurnItems = fixture.visibleTurnItems.map((row) =>
245 + row.item.id === "live-assistant-item"
246 + ? { ...row, sourceItemId: streamingItem.id, item: streamingItem }
247 + : row,
248 + );
249 + return { ...fixture, visibleTurnItems, streamingItemId: streamingItem.id };
250 +}
251 +
252 +/** One coalesced provider flush: only the streamed text and `updatedAt` change. */
253 +export function withStreamedText(
254 + rows: ReadonlyArray<OrchestrationV2ProjectedTurnItem>,
255 + itemId: string,
256 + text: string,
257 + updatedAt: string,
258 +): OrchestrationV2ProjectedTurnItem[] {
259 + return rows.map((row) => {
260 + if (row.item.id !== itemId) return row;
261 + const updated = DateTime.makeUnsafe(updatedAt);
262 + return {
263 + ...row,
264 + item:
265 + row.item.type === "proposed_plan"
266 + ? { ...row.item, markdown: text, updatedAt: updated }
267 + : row.item.type === "reasoning"
268 + ? { ...row.item, text, updatedAt: updated }
269 + : row.item,
270 + };
271 + });
272 }