The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 23:30 UTC
fix(clients): collapsed turns show one context-compacted divider (#34177)
Bin Jamshid committed
Nov 11, 2026 at 23:52 UTC
ddc3cefbc450a737b83672209db0e777bd54e09a
4 files changed
+102
-2
apps/mobile/src/lib/threadActivity.test.ts
+37
@@ -248,6 +248,43 @@ it.each(["/compact", "Continue"])(
248
},
249
);
250
251
+it("keeps only the latest compaction divider visible when a turn that compacted twice folds", () => {
252
+ const compaction = (id: string, ordinal: number, beforeTokenCount: number) => ({
253
+ ...base(id, "2026-06-20T00:00:03.000Z", ordinal),
254
+ type: "compaction" as const,
255
+ driver: ProviderDriverKind.make("claude"),
256
+ status: "completed" as const,
257
+ beforeTokenCount,
258
+ afterTokenCount: 20_000,
259
+ });
260
+ const feed = buildThreadFeed([
261
+ projected(userMessage(), 0),
262
+ projected(compaction("first-compaction", 1, 100_000), 1),
263
+ projected(command(), 2),
264
+ projected(compaction("second-compaction", 3, 90_000), 3),
265
+ ]);
266
+ const latestRun = {
267
+ runId,
268
+ status: "completed" as const,
269
+ startedAt: "2026-06-20T00:00:01.000Z",
270
+ completedAt: "2026-06-20T00:00:03.000Z",
271
+ };
272
+ const compactionsIn = (rows: ReadonlyArray<ThreadFeedEntry>) =>
273
+ rows.flatMap((entry) =>
274
+ entry.type === "activity-group"
275
+ ? entry.activities.flatMap(({ projectedItem: { item } }) =>
276
+ item.type === "compaction" ? [item.beforeTokenCount] : [],
277
+ )
278
+ : [],
279
+ );
280
+ const collapsed = deriveThreadFeedPresentation(feed, latestRun, new Set());
281
+ expect(collapsed.filter((entry) => entry.type === "run-fold")).toHaveLength(1);
282
+ expect(compactionsIn(collapsed)).toEqual([90_000]);
283
+ expect(compactionsIn(deriveThreadFeedPresentation(feed, latestRun, new Set([runId])))).toEqual([
284
+ 100_000, 90_000,
285
+ ]);
286
+});
287
+
288
it("binds a persisted resume answer only to the next compaction in its run", () => {
289
const requestId = RuntimeRequestId.make("resume-compaction");
290
const question = projected(
apps/mobile/src/lib/threadActivity.ts
+5
-1
@@ -1161,6 +1161,10 @@ function deriveThreadFeedRunFolds(
1161
continue;
1162
}
1163
const terminalAssistantId = terminalAssistantMessageIdByRun.get(runId);
1164
+ // Folded dividers lose their place in the turn, so only the latest stays visible.
1165
+ const visibleCompactionId = group.entries.findLast(
1166
+ (entry) => entry.type === "activity-group" && isContextCompactionActivityGroup(entry),
1167
+ )?.id;
1168
const hiddenEntryIds = new Set(
1169
group.entries
1170
.filter(
@@ -1168,7 +1172,7 @@ function deriveThreadFeedRunFolds(
1172
entry.id !== terminalAssistantId &&
1173
entry.type !== "html-render" &&
1174
entry.type !== "mcp-app" &&
1171
- !(entry.type === "activity-group" && isContextCompactionActivityGroup(entry)) &&
1175
+ entry.id !== visibleCompactionId &&
1176
!(
1177
entry.type === "activity-group" &&
1178
entry.activities.some(
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+57
@@ -768,6 +768,63 @@ describe("deriveMessagesTimelineRows", () => {
768
},
769
);
770
771
+ it("keeps only the latest compaction divider visible when a turn that compacted twice folds", () => {
772
+ const fixture = makeStreamingTimelineFixture();
773
+ const [, , , liveUser, liveWork, liveAssistant] = fixture.visibleTurnItems;
774
+ if (liveUser?.item.type !== "user_message" || liveAssistant?.item.type !== "assistant_message")
775
+ throw new Error("Expected live fixture items");
776
+ if (!liveWork) throw new Error("Expected live work");
777
+ const assistantItem = liveAssistant.item;
778
+ const compaction = (id: string, position: number, before: number, after: number) => ({
779
+ ...liveAssistant,
780
+ position,
781
+ sourceItemId: TurnItemId.make(id),
782
+ item: {
783
+ ...assistantItem,
784
+ id: TurnItemId.make(id),
785
+ type: "compaction" as const,
786
+ driver: null,
787
+ status: "completed" as const,
788
+ beforeTokenCount: before,
789
+ afterTokenCount: after,
790
+ },
791
+ });
792
+ const timelineEntries = deriveTimelineEntriesFromVisibleTurnItems({
793
+ visibleTurnItems: [
794
+ liveUser,
795
+ compaction("first-compaction", 4, 100_000, 20_000),
796
+ { ...liveWork, position: 5 },
797
+ compaction("second-compaction", 6, 90_000, 30_000),
798
+ ],
799
+ optimisticMessages: [],
800
+ });
801
+ const rowsFor = (expandedRunIds?: ReadonlySet<RunId>) =>
802
+ deriveMessagesTimelineRows({
803
+ timelineEntries,
804
+ isWorking: false,
805
+ latestRun: {
806
+ runId: fixture.runId,
807
+ status: "completed",
808
+ startedAt: fixture.time(5),
809
+ completedAt: fixture.time(8),
810
+ },
811
+ turnDiffSummaries: [],
812
+ supportsConversationRollback: false,
813
+ ...(expandedRunIds ? { expandedRunIds } : {}),
814
+ });
815
+ const collapsed = rowsFor();
816
+ expect(collapsed.filter((row) => row.kind === "turn-fold")).toHaveLength(1);
817
+ expect(collapsed.some((row) => row.kind === "work")).toBe(false);
818
+ expect(collapsed.filter((row) => row.kind === "context-compaction")).toMatchObject([
819
+ { tokenCounts: { before: "90K", after: "30K" } },
820
+ ]);
821
+ const expanded = rowsFor(new Set([fixture.runId]));
822
+ expect(expanded.filter((row) => row.kind === "context-compaction")).toMatchObject([
823
+ { tokenCounts: { before: "100K", after: "20K" } },
824
+ { tokenCounts: { before: "90K", after: "30K" } },
825
+ ]);
826
+ });
827
+
828
it("folds an answered compact-on-return question into its compaction row", () => {
829
const fixture = makeStreamingTimelineFixture();
830
const [history0, history1, history2, liveUser, liveWork, liveAssistant] =
apps/web/src/components/chat/MessagesTimeline.logic.ts
+3
-1
@@ -1137,6 +1137,8 @@ function deriveTurnFolds(input: {
1137
const terminalEntryIndex = group.terminalEntry
1138
? group.entries.findIndex((entry) => entry.id === group.terminalEntry?.id)
1139
: group.entries.length;
1140
+ // Folded dividers lose their place in the turn, so only the latest stays visible.
1141
+ const visibleCompactionId = group.entries.findLast(timelineEntryIsCompaction)?.id;
1142
for (const [index, entry] of group.entries.entries()) {
1143
if (entry.id === group.terminalEntry?.id) {
1144
continue;
@@ -1150,7 +1152,7 @@ function deriveTurnFolds(input: {
1152
continue;
1153
}
1154
if (
1153
- isCompaction ||
1155
+ entry.id === visibleCompactionId ||
1156
timelineEntryIsPersistentResourceCard(entry) ||
1157
input.liveSubagentEntryIds.has(entry.id) ||
1158
input.completeSupersededReplyEntryIds.has(entry.id)