Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/web/src/session-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,7 @@ describe("session activity performance", () => {
expect(appendedEntries[1]).toBe(initialEntries[1]);
});

it("updates 20,000 ordered tool activities within 100 ms", () => {
it("updates 20,000 ordered tool activities within 250 ms", () => {
const activities = Array.from({ length: 20_000 }, (_, index) =>
makeActivity({
id: `benchmark-tool-${index}`,
Expand Down Expand Up @@ -2663,6 +2663,8 @@ describe("session activity performance", () => {

const startedAt = performance.now();
expect(deriveWorkLogEntries(updatedActivities)).toHaveLength(20_001);
expect(performance.now() - startedAt).toBeLessThan(100);
// GitHub-hosted CI has seen the 100ms #8006 budget fail at ~139ms on the
// same tree that passed PR CI. 250ms still fails a quadratic rebuild.
expect(performance.now() - startedAt).toBeLessThan(250);
});
});
14 changes: 13 additions & 1 deletion apps/web/src/session-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,10 +1029,22 @@ function isAgentInternalActivity(activity: OrchestrationThreadActivity): boolean
return typeof payload.agentId === "string" && payload.agentId.trim().length > 0;
}

/** Streaming appends are already ordered; skip the n log n copy+sort on that path. */
function orderActivities(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): ReadonlyArray<OrchestrationThreadActivity> {
for (let index = 1; index < activities.length; index++) {
if (compareActivitiesByOrder(activities[index - 1]!, activities[index]!) > 0) {
return activities.toSorted(compareActivitiesByOrder);
}
}
return activities;
}

export function deriveWorkLogEntries(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): WorkLogEntry[] {
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const ordered = orderActivities(activities);
const entries: DerivedWorkLogEntry[] = [];
// Answers arrive in a separate activity from the questions; fold them back
// into the entry that asked, so one round trip renders as one Q&A card.
Expand Down
Loading