Skip to content

The agent that grows with you

fix(desktop): keep newest turn outside history budget

Victor Nogueirac1af9c649428
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.test.ts b/apps/desktop/src/components/assistant-ui/thread/list.test.ts
index a3b11469000..d95764126f9 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.test.ts
+++ b/apps/desktop/src/components/assistant-ui/thread/list.test.ts
@@ -274,10 +274,19 @@ describe('firstVisibleGroupIndex', () => {
expect(firstVisibleGroupIndex(grown, 60, 0, 1)).toBe(1)
})
- it('charges a completed tail to the budget as before', () => {
- const groups = [group('old', 50), group('recent', 30), group('completed', 5_000)]
+ it('keeps the cut stable when the tail completes', () => {
+ // With the newest group always unbudgeted, a heavy tail that finishes
+ // streaming does not advance the cut — the completion transition cannot
+ // change firstVisibleGroupIndex.
+ const groups = [group('old', 50), group('recent', 30), group('tail', 5_000)]
- expect(firstVisibleGroupIndex(groups, 60)).toBe(2)
+ expect(firstVisibleGroupIndex(groups, 60, 0, 1)).toBe(0)
+ })
+
+ it('exempts exactly one newest group while older history stays budgeted', () => {
+ const groups = [group('a', 200), group('b', 50), group('c', 50), group('d', 50), group('e', 10_000)]
+
+ expect(firstVisibleGroupIndex(groups, 60, 0, 1)).toBe(2)
})
})
diff --git a/apps/desktop/src/components/assistant-ui/thread/list.tsx b/apps/desktop/src/components/assistant-ui/thread/list.tsx
index 252e7cb9e56..7ebee104526 100644
--- a/apps/desktop/src/components/assistant-ui/thread/list.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/list.tsx
@@ -453,8 +453,6 @@ const ThreadMessageListInner: FC<ThreadMessageListProps> = ({
s.thread.messages.map(message => messagePaintWeight(message.content)).join(',')
)
- const threadRunning = useAuiState(s => s.thread.isRunning)
-
const { t } = useI18n()
// Row structure is memoized on the STRUCTURAL signature only, so streaming
// part-appends can't churn group identity (that would defeat the rows memo
@@ -598,12 +596,11 @@ const ThreadMessageListInner: FC<ThreadMessageListProps> = ({
weightedGroups,
renderBudget,
renderBudget >= paneBudget ? MIN_VISIBLE_GROUPS : 0,
- // The active turn has to stay mounted regardless of size. Charging its
- // growing weight to the history budget made this cut advance mid-stream:
- // old rows unmounted, scrollHeight shrank, and the browser clamp looked
- // like a user scroll-up to use-stick-to-bottom. Budget the history around
- // the live turn instead, so token flushes cannot move the cut boundary.
- threadRunning ? 1 : 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
)
// Memoized for IDENTITY, not to save the slice: `rows` below keys off this