Skip to content

The agent that grows with you

fix(desktop): exempt the newest turn from the budget on a real page only

kshitijk4poorbdcda7e37e97
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.tsx b/apps/desktop/src/components/assistant-ui/thread/list.tsx
index 7ebee104526..6df0182e0dd 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/list.tsx
@@ -280,21 +280,20 @@ export function buildGroups(signature: string): MessageGroup[] {
// Walk turns newest-first, summing their render weights until the budget is met;
// everything before the first kept turn is hidden. `minVisible` turns are kept
-// regardless of weight. Returns the index of that first visible group.
+// regardless of weight; the newest `unbudgetedTail` turns are kept AND left out
+// of the sum, so a turn whose weight is still changing cannot move the cut.
+// Returns the index of that first visible group.
export function firstVisibleGroupIndex(
groups: readonly MessageGroup[],
budget: number,
minVisible = 0,
unbudgetedTail = 0
): number {
- let firstVisible = groups.length
const budgetedEnd = Math.max(0, groups.length - unbudgetedTail)
+ let firstVisible = budgetedEnd
- for (let i = groups.length - 1, weight = 0; i >= 0; i--) {
- if (i < budgetedEnd) {
- weight += groups[i].weight
- }
-
+ for (let i = budgetedEnd - 1, weight = 0; i >= 0; i--) {
+ weight += groups[i].weight
firstVisible = i
if (weight >= budget) {
@@ -588,19 +587,23 @@ const ThreadMessageListInner: FC<ThreadMessageListProps> = ({
}))
}, [groups, weightSignature])
- // The turn floor applies to a real page only. During the first-paint budget
- // the point is a small synchronous commit; forcing 8 turns into it would put
- // back exactly the freeze FIRST_PAINT_BUDGET exists to avoid, and the rAF
- // backfill a frame later fills them in anyway.
+ // The turn floor and the newest-turn exemption apply to a real page only.
+ // During the first-paint budget the point is a small synchronous commit;
+ // forcing 8 turns into it — or a whole extra turn behind an unbudgeted
+ // newest one — would put back exactly the freeze FIRST_PAINT_BUDGET exists
+ // to avoid, and the rAF backfill a frame later fills them in anyway.
+ //
+ // On a real page the newest turn is exempt from the history budget so its
+ // growing — then completed — weight never advances the cut boundary. A
+ // moving cut unmounts older rows, shrinks scrollHeight, and the browser
+ // clamp looks like a user scroll-up to use-stick-to-bottom.
+ const fullPage = renderBudget >= paneBudget
+
const hiddenCount = firstVisibleGroupIndex(
weightedGroups,
renderBudget,
- renderBudget >= paneBudget ? MIN_VISIBLE_GROUPS : 0,
- // The newest turn is always exempt from the history render budget so its
- // growing — then completed — weight never advances the cut boundary. A
- // moving cut unmounts older rows, shrinks scrollHeight, and the browser
- // clamp looks like a user scroll-up to use-stick-to-bottom.
- 1
+ fullPage ? MIN_VISIBLE_GROUPS : 0,
+ fullPage ? 1 : 0
)
// Memoized for IDENTITY, not to save the slice: `rows` below keys off this