Repository navigation
Description
Summary
When the right-hand sidebar is long because it is rendering a large todo list, scrolling it becomes laggy/janky/unresponsive while the left-hand chat transcript is actively streaming (agent is "working"). Short lists are unaffected; the longer the todo list, the worse the lag. Scrolling becomes smooth again once the turn ends.
Environment
- Component: TUI (
docker-agent run, default Bubble Tea v2 TUI) - Layout: wide window, vertical sidebar on the right (
sidebarVerticalmode) - Repro evidence: local screen recording (2026-06-15)
Steps to reproduce
- Run an agent whose config enables the builtin
todotoolset. - Have the agent create a large todo list (~50–150 items; long descriptions amplify the effect) via
create_todos. - Keep the left panel streaming (a long assistant response, or a long-running tool whose output streams) so the working spinner is animating.
- Maximize terminal height so the todo list overflows the viewport (forces the scrollbar / two-pass path).
- Scroll the sidebar with the mouse wheel and by dragging the scrollbar.
Expected: sidebar scrolling stays smooth regardless of streaming activity.
Actual: scrolling lags/janks; worse the longer the list; smooth again once the agent stops working.
Root cause (verified against current code)
The sidebar render cache is defeated during streaming. The single global animation coordinator emits a 14 FPS tick while any spinner is active, and the sidebar invalidates its entire render cache on every tick during a working turn — then fully rebuilds all sections (including the whole todo list) twice when the list overflows (two-pass scrollbar rendering). All of this runs on Bubble Tea's single Update/View goroutine, so coalesced scroll deltas only surface after each full rebuild lands.
Key evidence (file:line):
- 14 FPS tick:
pkg/tui/animation/coordinator.gotickLocked()→tea.Tick(time.Second/14, …) - Tick invalidates the whole sidebar cache while working:
pkg/tui/components/sidebar/sidebar.go:810-833(default:branch —m.workingAgent != "" …→needsInvalidate→invalidateCache()at:229, which setscacheDirty = true) - Two-pass O(n) rebuild on overflow:
sidebar.go:921-945(verticalView()callsrenderSections()again whentotalLines > m.height);renderSectionsat:966; todo render at:986-987 - Todo list rendered O(n) with per-item word-wrap and no virtualization:
pkg/tui/components/tool/todotool/sidebar.goRender()→toolcommon.WrapLinesWords - Both panels recomposite every frame:
pkg/tui/page/chat/chat.goView()→lipgloss.JoinHorizontal(…, chatView, toggleCol, sidebarView) - Extra invalidations stack on top:
sidebar.go:287(SetTokenUsage) and tool-call events:641-737
Asymmetry
The left (messages) panel is already virtualized + cached — pkg/tui/components/messages/messages.go: an LRU of rendered items (cap 500), renderDirty-gated rebuild, animation.TickMsg only dirties when hasAnimatedContent(), and View() slices only the visible window. The right (sidebar) panel does none of this for its build stage.
Notes / nuances
- The rebuild rate is frame-rate-bounded (~14/sec), not per streamed token; between ticks
sidebar.View()hitsrenderFromCache()(cheap). Token-usage/tool events add invalidations on top, so heavy tool activity can push it above the 14 Hz floor. - Scrolling itself is cheap (the scrollview slices already-cached lines); the lag is contention on the single render goroutine, not input backpressure — wheel events are already coalesced at 16 ms in
pkg/tui/input/wheel_coalescer.go. - Magnitude (mild lag vs. true "hang") is not yet quantified. A
verticalView()micro-benchmark across todo counts is the recommended confirming measurement.
Suggested fix directions (not yet implemented)
- Decouple the spinner animation from full sidebar cache invalidation (render the spinner glyph as a small standalone region, or cache static sections separately from the 1-line working indicator). Lowest-risk symptom fix.
- Coalesce/throttle sidebar rebuilds below the 14 FPS animation cadence (rebuild only when underlying data actually changes).
- Drop the redundant second render pass (predict whether a scrollbar is needed from the line count instead of re-rendering at a narrower width).
- Durable scalability: build-stage virtualization of the todo list (render only the visible window) plus per-todo memoization (cache each todo's wrapped+styled lines).
Screenshot
Here is a demo where I try to scroll the right panel on a long session and it's sometimes completely hanging or very slow
Activity
fix(tui): cache sidebar todo render to stop scroll lag while streaming