Skip to content

Commit f012fa2

Browse files
authored
fix(web): back-to-back messages from you stack as one burst with a single steer label (#27305)
1 parent e4ecaf6 commit f012fa2

4 files changed

Lines changed: 118 additions & 17 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,74 @@ describe("deriveMessagesTimelineRows", () => {
13901390
]);
13911391
});
13921392

1393+
it("stacks back-to-back steers as one burst with a single steer label", () => {
1394+
const runId = RunId.make("double-steer-run");
1395+
const time = (second: number) => new Date(Date.UTC(2026, 0, 1, 0, 0, second)).toISOString();
1396+
const message = (
1397+
id: string,
1398+
second: number,
1399+
role: "user" | "assistant",
1400+
inputIntent?: "turn_start" | "steer",
1401+
): TimelineEntry => ({
1402+
kind: "message",
1403+
id,
1404+
createdAt: time(second),
1405+
message: {
1406+
id: MessageId.make(id),
1407+
role,
1408+
text: id,
1409+
runId,
1410+
...(inputIntent ? { inputIntent } : {}),
1411+
createdAt: time(second),
1412+
updatedAt: time(second),
1413+
streaming: false,
1414+
},
1415+
});
1416+
const prompt = message("prompt", 0, "user", "turn_start");
1417+
const work: TimelineEntry = {
1418+
kind: "work",
1419+
id: "work",
1420+
createdAt: time(4),
1421+
entry: { id: "work", createdAt: time(4), runId, label: "Ran command", tone: "tool" },
1422+
};
1423+
const firstSteer = message("first-steer", 10, "user", "steer");
1424+
const deriveRows = (timelineEntries: TimelineEntry[]) =>
1425+
deriveMessagesTimelineRows({
1426+
timelineEntries,
1427+
latestRun: { runId, status: "completed", startedAt: time(0), completedAt: time(30) },
1428+
isWorking: false,
1429+
expandedRunIds: new Set(),
1430+
turnDiffSummaries: [],
1431+
supportsConversationRollback: false,
1432+
});
1433+
// The second steer arrives while the first message object is reused, as live updates do.
1434+
const before = computeStableMessagesTimelineRows(deriveRows([prompt, work, firstSteer]), {
1435+
result: [],
1436+
byId: new Map(),
1437+
});
1438+
const rows = computeStableMessagesTimelineRows(
1439+
deriveRows([
1440+
prompt,
1441+
work,
1442+
firstSteer,
1443+
message("second-steer", 12, "user", "steer"),
1444+
message("final", 30, "assistant"),
1445+
]),
1446+
before,
1447+
).result;
1448+
1449+
const byId = new Map(rows.map((row) => [row.id, row]));
1450+
expect(byId.get("prompt")).not.toHaveProperty("groupedWithNext");
1451+
expect(byId.get("first-steer")).toMatchObject({
1452+
groupedWithNext: true,
1453+
continuesSteer: false,
1454+
});
1455+
expect(byId.get("second-steer")).toMatchObject({
1456+
groupedWithNext: false,
1457+
continuesSteer: true,
1458+
});
1459+
});
1460+
13931461
it("keeps the previous turn folded while a newly sent message awaits its turn", () => {
13941462
const rows = deriveMessagesTimelineRows({
13951463
timelineEntries: [

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
2+
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
23
import { isLiveSubagentTurnItem } from "@t3tools/client-runtime/state/subagentRuntime";
34
import * as DateTime from "effect/DateTime";
45
import * as Equal from "effect/Equal";
@@ -594,6 +595,10 @@ type MessagesTimelineRowContent =
594595
assistantCopyStreaming: boolean;
595596
assistantTurnDiffSummary?: TurnDiffSummary | undefined;
596597
revertTurnCount?: number | undefined;
598+
/** Another of your messages follows directly, so the two sit closer together. */
599+
groupedWithNext?: boolean;
600+
/** Set when the message above is a steer too, so the label shows once. */
601+
continuesSteer?: boolean;
597602
}
598603
| {
599604
kind: "assistant-meta";
@@ -2134,13 +2139,36 @@ export function deriveMessagesTimelineRows(input: {
21342139
const result = attachTrailingToolGroupsToAssistant(
21352140
attachCreatedThreadSummaries(nextRows, timelineEntries, collapsedFoldMemberIds),
21362141
);
2137-
return result.map((row, index) =>
2138-
timelineRowIsWorkLog(row) && timelineRowIsWorkLog(result[index + 1])
2139-
? { ...row, continuesWorkLog: true }
2140-
: row,
2142+
return result.map((row, index) => {
2143+
if (timelineRowIsWorkLog(row) && timelineRowIsWorkLog(result[index + 1])) {
2144+
return { ...row, continuesWorkLog: true };
2145+
}
2146+
if (!timelineRowIsOwnUserMessage(row)) return row;
2147+
const previous = result[index - 1];
2148+
const groupedWithNext = timelineRowIsOwnUserMessage(result[index + 1]);
2149+
const continuesSteer =
2150+
timelineRowIsOwnUserMessage(previous) &&
2151+
messageIsSteer(row.message) &&
2152+
messageIsSteer(previous.message);
2153+
if (!groupedWithNext && !continuesSteer) return row;
2154+
return { ...row, groupedWithNext, continuesSteer };
2155+
});
2156+
}
2157+
2158+
function timelineRowIsOwnUserMessage(
2159+
row: MessagesTimelineRow | undefined,
2160+
): row is Extract<MessagesTimelineRow, { kind: "message" }> {
2161+
return (
2162+
row?.kind === "message" &&
2163+
row.message.role === "user" &&
2164+
resolveUserMessagePresentation(row.message).attribution === null
21412165
);
21422166
}
21432167

2168+
function messageIsSteer(message: ChatMessage): boolean {
2169+
return message.inputIntent === "steer" || message.inputIntent === "promoted_queued_to_steer";
2170+
}
2171+
21442172
function timelineRowIsWorkLog(row: MessagesTimelineRow | undefined): boolean {
21452173
return (
21462174
row !== undefined &&
@@ -2478,7 +2506,9 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
24782506
a.showAssistantCopyButton === bm.showAssistantCopyButton &&
24792507
a.assistantCopyStreaming === bm.assistantCopyStreaming &&
24802508
a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary &&
2481-
a.revertTurnCount === bm.revertTurnCount
2509+
a.revertTurnCount === bm.revertTurnCount &&
2510+
a.groupedWithNext === bm.groupedWithNext &&
2511+
a.continuesSteer === bm.continuesSteer
24822512
);
24832513
}
24842514
}

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,16 +1441,18 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
14411441
? undefined
14421442
: row.kind === "turn-fold" || row.kind === "working"
14431443
? "pb-1.5"
1444-
: (row.kind === "message" &&
1445-
row.message.role === "assistant" &&
1446-
!row.showAssistantMeta) ||
1447-
row.kind === "worktree-setup" ||
1448-
row.kind === "event" ||
1449-
row.kind === "attempt-fold" ||
1450-
row.kind === "html-render" ||
1451-
row.kind === "mcp-app"
1452-
? "pb-2"
1453-
: "pb-4",
1444+
: row.kind === "message" && row.groupedWithNext
1445+
? "pb-1"
1446+
: (row.kind === "message" &&
1447+
row.message.role === "assistant" &&
1448+
!row.showAssistantMeta) ||
1449+
row.kind === "worktree-setup" ||
1450+
row.kind === "event" ||
1451+
row.kind === "attempt-fold" ||
1452+
row.kind === "html-render" ||
1453+
row.kind === "mcp-app"
1454+
? "pb-2"
1455+
: "pb-4",
14541456
(row.kind === "message" && row.message.role === "assistant") ||
14551457
row.kind === "assistant-meta"
14561458
? "group/assistant"

‎apps/web/src/components/chat/TimelineUserMessageRow.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
484484
<GuestMessageName name={userMessage.guestName} />
485485
</div>
486486
) : null}
487-
{row.message.inputIntent === "steer" ||
488-
row.message.inputIntent === "promoted_queued_to_steer" ? (
487+
{(row.message.inputIntent === "steer" ||
488+
row.message.inputIntent === "promoted_queued_to_steer") &&
489+
!row.continuesSteer ? (
489490
<UserMessageIntentMarker intent={row.message.inputIntent} />
490491
) : null}
491492
<div

0 commit comments

Comments
 (0)