Skip to content

TUI: right-panel (sidebar todo list) scrolling lags/hangs during active streaming when the list is long #3123

Closed

Description

@aheritier

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 (sidebarVertical mode)
  • Repro evidence: local screen recording (2026-06-15)

Steps to reproduce

  1. Run an agent whose config enables the builtin todo toolset.
  2. Have the agent create a large todo list (~50–150 items; long descriptions amplify the effect) via create_todos.
  3. Keep the left panel streaming (a long assistant response, or a long-running tool whose output streams) so the working spinner is animating.
  4. Maximize terminal height so the todo list overflows the viewport (forces the scrollbar / two-pass path).
  5. 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.go tickLocked() → 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 sets cacheDirty = true)
  • Two-pass O(n) rebuild on overflow: sidebar.go:921-945 (verticalView() calls renderSections() again when totalLines > m.height); renderSections at :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.go Render() → toolcommon.WrapLinesWords
  • Both panels recomposite every frame: pkg/tui/page/chat/chat.go View() → 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() hits renderFromCache() (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

Screen.Recording.2026-06-15.at.09.04.27.mov

Activity

  1. added
    area/tui
    area/tools
    on Jun 15, 2026
  2. added theissue type on Jun 15, 2026
  3. self-assigned this
    on Jun 15, 2026
  4. added a commit that references this issue on Jun 15, 2026
    b0c361b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/toolsarea/tui

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions