Skip to content

Commit fc233ed

Browse files
t3dotggclaude
andcommitted
perf(mobile): a tools-only wake's group keeps its identity across feed builds
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 40bda83 commit fc233ed

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,23 +1946,27 @@ describe("response groups", () => {
19461946
});
19471947

19481948
it("folds runs before the first loaded prompt, and counts a tools-only wake's files", () => {
1949-
const feed = buildThreadFeed(
1950-
[
1951-
step("initial", "launch", 1),
1952-
answer("initial", "launched", 5),
1953-
wake("wake-a", "wake-a-notice", 20),
1954-
step("wake-a", "read-a", 21),
1955-
].map((item, position) => projected(item, position)),
1956-
{
1957-
checkpointSummaries: [
1958-
checkpoint("initial", 4, "launched", "a.ts"),
1959-
checkpoint("wake-a", 5, null, "b.ts"),
1960-
],
1961-
},
1962-
);
1949+
const feedItems = [
1950+
step("initial", "launch", 1),
1951+
answer("initial", "launched", 5),
1952+
wake("wake-a", "wake-a-notice", 20),
1953+
step("wake-a", "read-a", 21),
1954+
].map((item, position) => projected(item, position));
1955+
const feed = buildThreadFeed(feedItems, {
1956+
checkpointSummaries: [
1957+
checkpoint("initial", 4, "launched", "a.ts"),
1958+
checkpoint("wake-a", 5, null, "b.ts"),
1959+
],
1960+
});
19631961
const rows = deriveThreadFeedPresentation(feed, completed("wake-a", 20, 22), new Set());
19641962
expect(ids(rows)).toEqual(["run-fold:group:partial:start", "launched"]);
19651963
expect(messageFoldRunIds(feed, "launched")).toEqual(["initial", "group:partial:start"]);
1964+
// A rebuild keeps the checkpoint-carrying group's identity.
1965+
const rebuild = () =>
1966+
buildThreadFeed(feedItems, { checkpointSummaries: [checkpoint("wake-a", 5, null, "b.ts")] });
1967+
const first = rebuild();
1968+
const second = rebuild();
1969+
expect(second.at(-1)).toBe(first.at(-1));
19661970
expect(rows[0]).toMatchObject({
19671971
label: "Worked · 1 update",
19681972
checkpointSummary: {

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ const presentedActivityGroupsCache = new WeakMap<
351351
}
352352
>();
353353
type RunFoldRow = Extract<ThreadFeedEntry, { readonly type: "run-fold" }>;
354+
const runCheckpointGroupsCache = new WeakMap<
355+
ThreadFeedEntry,
356+
Extract<ThreadFeedEntry, { readonly type: "activity-group" }>
357+
>();
354358
const runFoldRowsCache = new WeakMap<ThreadFeedEntry, RunFoldRow>();
355359
// A response group's row and its first run's row can share an anchor entry.
356360
const groupFoldRowsCache = new WeakMap<ThreadFeedEntry, RunFoldRow>();
@@ -2726,7 +2730,20 @@ export function buildThreadFeed(
27262730
: undefined;
27272731
if (entry.type !== "activity-group" || runCheckpoint === undefined) continue;
27282732
answerlessCheckpointByRun.delete(runCheckpoint.runId);
2729-
grouped[index] = { ...entry, runCheckpoint };
2733+
// Keep the group's identity across builds: caches and restarts compare by reference.
2734+
const cached = runCheckpointGroupsCache.get(entry);
2735+
if (
2736+
cached !== undefined &&
2737+
cached.runCheckpoint?.checkpointRef === runCheckpoint.checkpointRef &&
2738+
cached.runCheckpoint.status === runCheckpoint.status &&
2739+
cached.runCheckpoint.files.length === runCheckpoint.files.length
2740+
) {
2741+
grouped[index] = cached;
2742+
continue;
2743+
}
2744+
const withCheckpoint = { ...entry, runCheckpoint };
2745+
runCheckpointGroupsCache.set(entry, withCheckpoint);
2746+
grouped[index] = withCheckpoint;
27302747
}
27312748
const feed = prefix.length === 0 ? grouped : prefix.concat(grouped);
27322749
if (cache) {

0 commit comments

Comments
 (0)