Skip to content

Commit 2797dbb

Browse files
fix(clients): keep compaction dividers visible in folded turns
1 parent 0f65db5 commit 2797dbb

4 files changed

Lines changed: 98 additions & 0 deletions

File tree

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,51 @@ it("shows a compact command as one mobile divider before, during, and after comp
115115
}
116116
});
117117

118+
it.each(["/compact", "Continue"])(
119+
"keeps a completed compaction divider visible while other settled work folds for %s",
120+
(promptText) => {
121+
const rows = deriveThreadFeedPresentation(
122+
buildThreadFeed([
123+
projected({ ...userMessage(), text: promptText }, 0),
124+
projected(command(), 1),
125+
projected(
126+
{
127+
...base("compaction", "2026-06-20T00:00:03.000Z", 2),
128+
type: "compaction",
129+
driver: ProviderDriverKind.make("claude"),
130+
status: "completed",
131+
beforeTokenCount: 100_000,
132+
afterTokenCount: 20_000,
133+
},
134+
2,
135+
),
136+
]),
137+
{
138+
runId,
139+
status: "completed",
140+
startedAt: "2026-06-20T00:00:01.000Z",
141+
completedAt: "2026-06-20T00:00:03.000Z",
142+
},
143+
new Set(),
144+
);
145+
expect(rows.filter((entry) => entry.type === "run-fold")).toHaveLength(1);
146+
const activities = rows.flatMap((entry) =>
147+
entry.type === "activity-group" ? entry.activities : [],
148+
);
149+
expect(activities.map((activity) => activity.projectedItem.item)).toMatchObject([
150+
{
151+
type: "compaction",
152+
status: "completed",
153+
beforeTokenCount: 100_000,
154+
afterTokenCount: 20_000,
155+
},
156+
]);
157+
if (promptText === "/compact") {
158+
expect(rows.some((entry) => entry.type === "message")).toBe(false);
159+
}
160+
},
161+
);
162+
118163
it("binds a persisted resume answer only to the next compaction in its run", () => {
119164
const requestId = RuntimeRequestId.make("resume-compaction");
120165
const question = projected(

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ function deriveThreadFeedRunFolds(
12101210
entry.id !== terminalAssistantId &&
12111211
entry.type !== "html-render" &&
12121212
entry.type !== "mcp-app" &&
1213+
!(entry.type === "activity-group" && isContextCompactionActivityGroup(entry)) &&
12131214
!(
12141215
entry.type === "activity-group" &&
12151216
entry.activities.some(

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,57 @@ describe("deriveMessagesTimelineRows", () => {
630630
}
631631
});
632632

633+
it.each(["/compact", "Continue"])(
634+
"keeps a completed compaction divider visible while other settled work folds for %s",
635+
(promptText) => {
636+
const fixture = makeStreamingTimelineFixture();
637+
const [, , , liveUser, liveWork, liveAssistant] = fixture.visibleTurnItems;
638+
if (
639+
liveUser?.item.type !== "user_message" ||
640+
liveAssistant?.item.type !== "assistant_message" ||
641+
!liveWork
642+
)
643+
throw new Error("Expected live fixture items");
644+
const rows = deriveMessagesTimelineRows({
645+
timelineEntries: deriveTimelineEntriesFromVisibleTurnItems({
646+
visibleTurnItems: [
647+
{ ...liveUser, item: { ...liveUser.item, text: promptText } },
648+
liveWork,
649+
{
650+
...liveAssistant,
651+
item: {
652+
...liveAssistant.item,
653+
type: "compaction",
654+
driver: null,
655+
status: "completed",
656+
beforeTokenCount: 100_000,
657+
afterTokenCount: 20_000,
658+
},
659+
},
660+
],
661+
optimisticMessages: [],
662+
}),
663+
isWorking: false,
664+
latestRun: {
665+
runId: fixture.runId,
666+
status: "completed",
667+
startedAt: fixture.time(5),
668+
completedAt: fixture.time(8),
669+
},
670+
turnDiffSummaries: [],
671+
supportsConversationRollback: false,
672+
});
673+
expect(rows.filter((row) => row.kind === "turn-fold")).toHaveLength(1);
674+
expect(rows.some((row) => row.kind === "work")).toBe(false);
675+
expect(rows.filter((row) => row.kind === "context-compaction")).toMatchObject([
676+
{ active: false, tokenCounts: { before: "100K", after: "20K" } },
677+
]);
678+
if (promptText === "/compact") {
679+
expect(rows.some((row) => row.kind === "message")).toBe(false);
680+
}
681+
},
682+
);
683+
633684
it("folds an answered compact-on-return question into its compaction row", () => {
634685
const fixture = makeStreamingTimelineFixture();
635686
const [history0, history1, history2, liveUser, liveWork, liveAssistant] =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ function deriveTurnFolds(input: {
11561156
continue;
11571157
}
11581158
if (
1159+
isCompaction ||
11591160
timelineEntryIsPersistentResourceCard(entry) ||
11601161
input.liveSubagentEntryIds.has(entry.id) ||
11611162
input.completeSupersededReplyEntryIds.has(entry.id)

0 commit comments

Comments
 (0)