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

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

fix(web): steers split a finished turn's work instead of stacking under it (#22783)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 02:42 UTC a8bb769d65b3374314da545920c9f7ee027e2b4c
3 files changed +192 -22
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+110
@@ -1066,6 +1066,73 @@ describe("deriveMessagesTimelineRows", () => {
1066 },
1067 );
1068
1069 + it("splits a settled turn's work at each steer and keeps the total time on top", () => {
1070 + const runId = RunId.make("steered-run");
1071 + const time = (second: number) => new Date(Date.UTC(2026, 0, 1, 0, 0, second)).toISOString();
1072 + const message = (
1073 + id: string,
1074 + second: number,
1075 + role: "user" | "assistant",
1076 + inputIntent?: "turn_start" | "steer",
1077 + ): TimelineEntry => ({
1078 + kind: "message",
1079 + id,
1080 + createdAt: time(second),
1081 + message: {
1082 + id: MessageId.make(id),
1083 + role,
1084 + text: id,
1085 + runId,
1086 + ...(inputIntent ? { inputIntent } : {}),
1087 + createdAt: time(second),
1088 + updatedAt: time(second),
1089 + streaming: false,
1090 + },
1091 + });
1092 + const work = (id: string, second: number): TimelineEntry => ({
1093 + kind: "work",
1094 + id,
1095 + createdAt: time(second),
1096 + entry: { id, createdAt: time(second), runId, label: "Ran command", tone: "tool" },
1097 + });
1098 + const rows = (expandedRunIds: ReadonlySet<RunId>) =>
1099 + deriveMessagesTimelineRows({
1100 + timelineEntries: [
1101 + message("prompt", 0, "user", "turn_start"),
1102 + work("work-before-steer", 4),
1103 + message("steer", 10, "user", "steer"),
1104 + work("work-after-steer", 15),
1105 + message("final", 30, "assistant"),
1106 + ],
1107 + latestRun: { runId, status: "completed", startedAt: time(0), completedAt: time(30) },
1108 + isWorking: false,
1109 + expandedRunIds,
1110 + turnDiffSummaries: [],
1111 + supportsConversationRollback: false,
1112 + });
1113 +
1114 + const segmentKey = RunId.make(`${runId}:steer:steer`);
1115 + const collapsed = rows(new Set());
1116 + expect(collapsed.map((row) => row.id)).toEqual([
1117 + "prompt",
1118 + `turn-fold:${runId}`,
1119 + "steer",
1120 + `turn-fold:${segmentKey}`,
1121 + "final",
1122 + ]);
1123 + expect(collapsed[1]).toMatchObject({ label: "Worked for 30s" });
1124 + expect(collapsed[3]).toMatchObject({ label: "Continued for 20s", createdAt: time(10) });
1125 +
1126 + expect(rows(new Set([segmentKey])).map((row) => row.id)).toEqual([
1127 + "prompt",
1128 + `turn-fold:${runId}`,
1129 + "steer",
1130 + `turn-fold:${segmentKey}`,
1131 + "work-after-steer",
1132 + "final",
1133 + ]);
1134 + });
1135 +
1136 it("keeps the previous turn folded while a newly sent message awaits its turn", () => {
1137 const rows = deriveMessagesTimelineRows({
1138 timelineEntries: [
@@ -3160,6 +3227,49 @@ describe("linked timeline resources", () => {
3227 "assistant-meta:final",
3228 ]);
3229 });
3230 +
3231 + it("shows a created chat after a steer only when that steer's segment is open", () => {
3232 + const message = (id: string, role: "user" | "assistant", second: number) => ({
3233 + kind: "message" as const,
3234 + id,
3235 + createdAt: `2026-09-08T10:00:0${second}Z`,
3236 + message: {
3237 + id: MessageId.make(id),
3238 + role,
3239 + text: id,
3240 + runId,
3241 + ...(role === "user" ? { inputIntent: "steer" as const } : {}),
3242 + streaming: false,
3243 + createdAt: `2026-09-08T10:00:0${second}Z`,
3244 + updatedAt: `2026-09-08T10:00:0${second}Z`,
3245 + },
3246 + });
3247 + const timelineEntries = [
3248 + message("intro", "assistant", 0),
3249 + message("steer", "user", 1),
3250 + event("created", "thread_created"),
3251 + message("after-steer", "assistant", 3),
3252 + message("final", "assistant", 4),
3253 + ];
3254 + const segmentKey = RunId.make(`${runId}:steer:steer`);
3255 + const rowIds = (expanded: RunId[]) =>
3256 + deriveMessagesTimelineRows({
3257 + ...common,
3258 + timelineEntries,
3259 + expandedRunIds: new Set(expanded),
3260 + }).map((row) => row.id);
3261 + expect(rowIds([runId])).not.toContain("created");
3262 + expect(rowIds([segmentKey])).toEqual([
3263 + `turn-fold:${runId}`,
3264 + "steer",
3265 + `turn-fold:${segmentKey}`,
3266 + "created",
3267 + "after-steer",
3268 + "final",
3269 + "summary:created",
3270 + "assistant-meta:final",
3271 + ]);
3272 + });
3273 });
3274
3275 it.each([true, false])(
apps/web/src/components/chat/MessagesTimeline.logic.ts
+81 -21
@@ -732,6 +732,8 @@ interface TurnFold {
732 anchorEntryId: string;
733 createdAt: string;
734 hiddenEntryIds: ReadonlySet<string>;
735 + /** Every entry in the segment, including the cards a fold never hides. */
736 + entryIds: ReadonlySet<string>;
737 label: string;
738 }
739
@@ -903,16 +905,30 @@ function timelineEntryFoldRunId(entry: TimelineEntry, runlessKey: RunId | null):
905 return null;
906 }
907
908 +function timelineEntryIsSteer(entry: TimelineEntry): boolean {
909 + return (
910 + entry.kind === "message" &&
911 + entry.message.role === "user" &&
912 + (entry.message.inputIntent === "steer" ||
913 + entry.message.inputIntent === "promoted_queued_to_steer")
914 + );
915 +}
916 +
917 function timelineEntryStartsResponse(entry: TimelineEntry): boolean {
918 return (
908 - (entry.kind === "message" &&
909 - entry.message.role === "user" &&
910 - entry.message.inputIntent !== "steer" &&
911 - entry.message.inputIntent !== "promoted_queued_to_steer") ||
919 + (entry.kind === "message" && entry.message.role === "user" && !timelineEntryIsSteer(entry)) ||
920 (entry.kind === "work" && entry.entry.itemType === "notification")
921 );
922 }
923
924 +function timelineEntryEnd(entry: TimelineEntry): string {
925 + return entry.kind === "message" ? entry.message.updatedAt : entry.createdAt;
926 +}
927 +
928 +function timelineEntryIsCompaction(entry: TimelineEntry): boolean {
929 + return entry.kind === "work" && entry.entry.sourceActivityKind === "context-compaction";
930 +}
931 +
932 function responseBoundaryRunId(entry: TimelineEntry): RunId | null {
933 if (entry.kind === "message") return entry.message.runId ?? null;
934 if (entry.kind === "work") return entry.entry.runId ?? null;
@@ -1019,6 +1035,11 @@ function deriveTurnFolds(input: {
1035 */
1036 startBoundary: string | null;
1037 anchorEntryId: string;
1038 + /**
1039 + * Each steer after the turn has produced output starts a new segment at
1040 + * this index into `entries`, so the steer sits between the work it split.
1041 + */
1042 + steerSegments: Array<{ startIndex: number; steer: TimelineEntry }>;
1043 }
1044 const groupsByRunId = new Map<RunId, TurnGroup>();
1045 const runlessFailedKeys = new Set<RunId>();
@@ -1040,6 +1061,18 @@ function deriveTurnFolds(input: {
1061 responseKey = boundaryRunId ?? runlessKey;
1062 continue;
1063 }
1064 + if (entry.kind === "message" && timelineEntryIsSteer(entry)) {
1065 + const steerRunId = entry.message.runId ?? responseKey;
1066 + const group = steerRunId === null ? undefined : groupsByRunId.get(steerRunId);
1067 + if (group !== undefined && group.entries.length > 0) {
1068 + // Back-to-back steers split once, after the last of them.
1069 + if (group.steerSegments.at(-1)?.startIndex === group.entries.length) {
1070 + group.steerSegments.pop();
1071 + }
1072 + group.steerSegments.push({ startIndex: group.entries.length, steer: entry });
1073 + }
1074 + continue;
1075 + }
1076 const ownRunId = timelineEntryFoldRunId(entry, runlessKey);
1077 if (!ownRunId) {
1078 continue;
@@ -1062,6 +1095,7 @@ function deriveTurnFolds(input: {
1095 hasStreamingMessage: false,
1096 startBoundary: pendingBoundary?.createdAt ?? null,
1097 anchorEntryId: pendingBoundary?.anchorEntryId ?? entry.id,
1098 + steerSegments: [],
1099 };
1100 pendingBoundary = null;
1101 groupsByRunId.set(runId, group);
@@ -1098,8 +1132,7 @@ function deriveTurnFolds(input: {
1132 if (entry.id === group.terminalEntry?.id) {
1133 continue;
1134 }
1101 - const isCompaction =
1102 - entry.kind === "work" && entry.entry.sourceActivityKind === "context-compaction";
1135 + const isCompaction = timelineEntryIsCompaction(entry);
1136 const isFoldableTrailingActivity =
1137 entry.kind === "work" &&
1138 entry.entry.toolLifecycleStatus !== "inProgress" &&
@@ -1122,12 +1155,9 @@ function deriveTurnFolds(input: {
1155 if (hiddenEntryIds.size === 0) {
1156 continue;
1157 }
1125 - const hidesNonCompactionWork = group.entries.some(
1126 - (entry) =>
1127 - hiddenEntryIds.has(entry.id) &&
1128 - !(entry.kind === "work" && entry.entry.sourceActivityKind === "context-compaction"),
1129 - );
1130 - if (!hidesNonCompactionWork) {
1158 + const hidesNonCompactionWork = (entries: ReadonlyArray<TimelineEntry>) =>
1159 + entries.some((entry) => hiddenEntryIds.has(entry.id) && !timelineEntryIsCompaction(entry));
1160 + if (!hidesNonCompactionWork(group.entries)) {
1161 continue;
1162 }
1163
@@ -1141,8 +1171,7 @@ function deriveTurnFolds(input: {
1171 input.latestRun?.runId === runId && input.latestRun.status === "interrupted";
1172 // A turn cut short by a steer leaves trailing work entries behind its
1173 // terminal message — take whichever ended last.
1144 - const lastEntryEnd =
1145 - lastEntry.kind === "message" ? lastEntry.message.updatedAt : lastEntry.createdAt;
1174 + const lastEntryEnd = timelineEntryEnd(lastEntry);
1175 const elapsedMs =
1176 input.latestRun?.runId === runId && input.latestRun.startedAt && input.latestRun.completedAt
1177 ? computeElapsedMs(input.latestRun.startedAt, input.latestRun.completedAt)
@@ -1160,13 +1189,38 @@ function deriveTurnFolds(input: {
1189 ? `Worked for ${duration}`
1190 : "Worked";
1191
1192 + // The top row keeps the whole turn's time, steers included. Work after a
1193 + // steer folds under its own row below that steer, keyed apart from the run
1194 + // so each segment opens on its own.
1195 + const segmentHiddenIds = (entries: ReadonlyArray<TimelineEntry>) =>
1196 + new Set(entries.flatMap((entry) => (hiddenEntryIds.has(entry.id) ? [entry.id] : [])));
1197 + const firstSegment = group.entries.slice(0, group.steerSegments[0]?.startIndex);
1198 foldsByAnchorEntryId.set(group.anchorEntryId, {
1199 runId,
1200 anchorEntryId: group.anchorEntryId,
1201 createdAt: group.startBoundary ?? firstEntry.createdAt,
1167 - hiddenEntryIds,
1202 + hiddenEntryIds: segmentHiddenIds(firstSegment),
1203 + entryIds: new Set(firstSegment.map((entry) => entry.id)),
1204 label,
1205 });
1206 + for (const [index, { startIndex, steer }] of group.steerSegments.entries()) {
1207 + const entries = group.entries.slice(startIndex, group.steerSegments[index + 1]?.startIndex);
1208 + const anchorEntry = entries[0];
1209 + if (anchorEntry === undefined || !hidesNonCompactionWork(entries)) continue;
1210 + const segmentMs = computeElapsedMs(
1211 + steer.createdAt,
1212 + entries.map(timelineEntryEnd).reduce<string | null>(maxIsoTimestamp, null) ??
1213 + steer.createdAt,
1214 + );
1215 + foldsByAnchorEntryId.set(anchorEntry.id, {
1216 + runId: RunId.make(`${runId}:steer:${steer.id}`),
1217 + anchorEntryId: anchorEntry.id,
1218 + createdAt: steer.createdAt,
1219 + hiddenEntryIds: segmentHiddenIds(entries),
1220 + entryIds: new Set(entries.map((entry) => entry.id)),
1221 + label: segmentMs !== null ? `Continued for ${formatDuration(segmentMs)}` : "Continued",
1222 + });
1223 + }
1224 }
1225 return foldsByAnchorEntryId;
1226 }
@@ -1414,11 +1468,15 @@ export function deriveMessagesTimelineRows(input: {
1468 completeSupersededReplyEntryIds: completeSupersededReplyIds,
1469 });
1470 const collapsedEntryIds = new Set<string>();
1471 + const collapsedFoldMemberIds = new Set<string>();
1472 for (const fold of foldsByAnchorEntryId.values()) {
1473 if (!input.expandedRunIds?.has(fold.runId)) {
1474 for (const entryId of fold.hiddenEntryIds) {
1475 collapsedEntryIds.add(entryId);
1476 }
1477 + for (const entryId of fold.entryIds) {
1478 + collapsedFoldMemberIds.add(entryId);
1479 + }
1480 }
1481 }
1482 const collapsedSupersededEntryIds = new Set<string>();
@@ -1943,7 +2001,7 @@ export function deriveMessagesTimelineRows(input: {
2001 }
2002
2003 const result = attachTrailingToolGroupsToAssistant(
1946 - attachCreatedThreadSummaries(nextRows, timelineEntries),
2004 + attachCreatedThreadSummaries(nextRows, timelineEntries, collapsedFoldMemberIds),
2005 );
2006 return result.map((row, index) =>
2007 timelineRowIsWorkLog(row) && timelineRowIsWorkLog(result[index + 1])
@@ -1965,15 +2023,14 @@ function timelineRowIsWorkLog(row: MessagesTimelineRow | undefined): boolean {
2023 function attachCreatedThreadSummaries(
2024 rows: MessagesTimelineRow[],
2025 timelineEntries: ReadonlyArray<TimelineEntry>,
2026 + collapsedFoldMemberIds: ReadonlySet<string>,
2027 ): MessagesTimelineRow[] {
2028 const terminalIndexes = new Map<RunId, number>();
1970 - const collapsedRuns = new Set<RunId>();
2029 const createdByRun = new Map<RunId, Array<Extract<MessagesTimelineRow, { kind: "event" }>>>();
2030 for (const [index, row] of rows.entries()) {
2031 if (row.kind === "message" && row.showAssistantMeta && row.message.runId) {
2032 terminalIndexes.set(row.message.runId, index);
2033 }
1976 - if (row.kind === "turn-fold" && !row.expanded) collapsedRuns.add(row.runId);
2034 }
2035 for (const entry of timelineEntries) {
2036 const projectedItem =
@@ -1993,7 +2050,10 @@ function attachCreatedThreadSummaries(
2050 if (row.kind === "event" && row.projectedItem.item.type === "thread_created") {
2051 const runId = row.projectedItem.item.runId;
2052 const terminalIndex = runId === null ? undefined : terminalIndexes.get(runId);
1996 - if (terminalIndex !== undefined && (collapsedRuns.has(runId!) || index > terminalIndex))
2053 + if (
2054 + terminalIndex !== undefined &&
2055 + (collapsedFoldMemberIds.has(row.id) || index > terminalIndex)
2056 + )
2057 return [];
2058 }
2059 if (row.kind === "message" && row.showAssistantMeta && row.message.runId) {
@@ -2020,8 +2080,8 @@ export interface MessagesTimelineRowsProjection {
2080 }
2081
2082 /**
2023 - * Runless (imported V1) turns fold under a synthetic key, so the entry's own
2024 - * run id is not enough to open them.
2083 + * Runless (imported V1) turns and work after a steer fold under synthetic
2084 + * keys, so the entry's own run id is not enough to open them.
2085 */
2086 export function timelineEntryTurnFoldRunId(
2087 input: Pick<
apps/web/src/components/chat/MessagesTimeline.tsx
+1 -1
@@ -540,7 +540,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
540 });
541 }, [latestRun, listIdentityKey]);
542
543 - // Imported turns fold under synthetic keys rather than the entries' own run ids.
543 + // Imported turns and post-steer work fold under synthetic keys, not the entries' run ids.
544 const findFoldRunIds = findActive
545 ? timelineTurnFoldRunIdsByEntryId({
546 timelineEntries,