Skip to content

feat: configurable chat history scrollback (avoid losing older messages) #422

@amanthanvi

Description

@amanthanvi

Problem

In long-running threads, older chat history becomes inaccessible in the UI: as a conversation grows, the beginning of the thread disappears from the scrollback.

This makes it hard to recover context in longer chats and power-user sessions.

Current behavior

  • The UI retains only a small window of conversation items per thread.
  • As more items arrive (streaming deltas, tool output, etc.), earlier items are dropped locally.

Root cause (code)

The frontend unconditionally limits thread items via prepareThreadItems():

  • src/utils/threadItems.ts has MAX_ITEMS_PER_THREAD = 200.
  • prepareThreadItems() slices to the last 200 items (normalized.slice(-MAX_ITEMS_PER_THREAD)).
  • Reducers call prepareThreadItems(...) during normal thread updates, so the cap applies continuously.

Proposal

Add an app-wide setting to configure thread history scrollback retention:

  • Default stays 200 items (no behavior change for most users).
  • Allow power users to increase to higher values (e.g. 500/1000/2000/5000).
  • Optional Unlimited mode (stores all items returned by thread/resume + live items).

UX

Settings: Settings -> Display & Sound (or similar)

  • Toggle: Unlimited chat history
  • Number input: Max items per thread (disabled when Unlimited is on)
  • Presets: 200 / 500 / 1000 / 2000 / 5000
  • Help text warning about performance/memory costs for large values.

Note: existing thread context menu already has “Sync from server”; after increasing scrollback, users can sync to pull additional older history.

Performance considerations

Increasing retention can increase memory/DOM/render cost. To mitigate:

  • Virtualize the message list (@tanstack/react-virtual is already in the repo and used elsewhere).
  • Virtualize at the grouped-item level (tool groups + items), with ResizeObserver measurement like GitDiffViewer.

Acceptance criteria

  • Default remains last-200 behavior.
  • Setting persists and applies to new and existing threads.
  • Higher limits retain more items; Unlimited retains all items received.
  • No major regressions in scroll/auto-scroll behavior.
  • Tests cover retention logic (default/custom/unlimited) and settings normalization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions