Skip to content

Studio: Virtualize long chat histories for substantially lower memory use - #14001

Open
Griggelor wants to merge 1 commit into
unslothai:mainfrom
Griggelor:feature/studio-r6v3-agent-history-upstream
Open

Griggelor wants to merge 1 commit into
unslothai:mainfrom
Griggelor:feature/studio-r6v3-agent-history-upstream

Conversation

@Griggelor

@Griggelor Griggelor commented Oct 16, 2026 •

Copy link
Copy Markdown

Integration update — 11 Nov 2026. This existing PR is now at 47a963f, ported onto official Unsloth main at fcae458. It incorporates the feature behavior from the fork PR #43 specifically requested and independently tested by @Imagineer99, with later upstream changes retained. Dynamic remains opt-in; Off is the default. The updated branch is mergeable without conflicts. Fresh integration CI is running in fork QA PR #44; the Windows unsigned Tauri EXE build passed and its downloadable artifact is available (7-day retention through 18 Nov). The new commit must not be treated as fully integration-tested until the remaining checks finish. The previous branch head 3627aec is preserved on backup/r6v3-pr14001-before-20261111-update in the fork.

Why: long chats need bounded rendering

Long-running agents can extend beyond individual bounded model contexts via rolling/compaction, but the accumulated persistent conversation can make the browser/WebView2 chat renderer grow without bound. Even after existing improvements to mounted message work (#13059, #13255), retaining every historical message in the live React/DOM tree can substantially increase memory pressure and responsiveness problems. This PR windows historical mounted rows while retaining the authoritative transcript, assistant-ui runtime and stored messages. It does not enlarge the model context or change backend inference/persistence.

Modes and compatibility

Mode Behavior
Off (default) Keep existing ProgressiveMessages; the new virtual renderer is not eagerly loaded
Dynamic (opt-in) Reader-centred measured/estimated DOM-cost window, typically ~16 rows, up to 32
Fixed (opt-in) Viewport-covering row-bounded window with an estimated DOM-cost target

Global setting and per-chat Use global setting / Dynamic / Fixed / Off overrides; persisted legacy migration; all 25 locale files present in the current feature diff. A necessary exceptionally heavy tool row can exceed the DOM target by itself.

Screenshots

Global display setting:

Virtualized chat history global setting

Per-chat override:

Virtualized chat history per-chat setting

Observations — separate environments, not pooled benchmarks

  • Maintainer test, 11 Nov: @Imagineer99 tested the fork PR #43 implementation in Windows Edge using the same 740-message synthetic chat twice per mode: 740 mounted rows / 514–531 MiB with Off, versus 4 rows / 203–222 MiB with Dynamic (about 59% less memory). Median typing latency was ~6 ms in both modes after the chat had settled; this does not establish active-generation typing latency. See maintainer comment.
  • Contributor's Windows Desktop observations, 9–10 Nov: two screenshots of the same long Browser Use chat while generating showed the chat WebView2 renderer using 5,374.2 MB before versus 1,601.7 MB using the feature (−70.2%). These are individual real-use snapshots taken on different days, not a controlled Off/Dynamic A/B test on an identical build. See screenshots and details.
  • Earlier internal synthetic tests showed substantial DOM reduction. These are distinct from the maintainer's measurements and real Windows QA.

Architecture

  • Thread retains ProgressiveMessages for Off and lazy-loads AgentHistoryScrollMessages for opted-in modes.
  • Central preference policy determines the effective global/per-chat mode; existing selections survive migration.
  • Height and DOM-cost ledgers, staged range selection and observer correction bound the mounted rows while maintaining logical scroll geometry.
  • Intent-aware scrolling coordinates reader wheel, native scrollbar thumb, stream-follow, search navigation and anchor corrections.
  • Logical find-in-chat searches text in unmounted messages, and notification subscriptions are pruned when rows unmount.
  • No production Python backend or inference changes introduced by this feature.

Details: technical walkthrough.

Current integration and QA

  • Previous tested feature: fork PR #43 at 5b11178, based on upstream ed3eec6 (9 Nov).
  • Current integration: 47a963f, based on upstream fcae458 (11 Nov; 216 upstream commits after ed3eec6). All 65 feature-file changes ported; concurrently changed frontend/locale files were merged by focused patch application to preserve the latest upstream content rather than overwriting them wholesale.
  • Current isolated QA: fork PR #44, including 19 triggered workflows and Windows unsigned EXE workflow. The Windows EXE workflow has passed on this exact SHA, including frontend build, targeted Agent History tests, Tauri/Rust build, checksum and artifact upload. The resulting unsigned ZIP artifact is not an installer or official release (expires 18 Nov 2026 at 17:30 UTC). Other workflows remain pending; passing this one does not imply a full green CI suite.
  • Historical CI (ModuleNotFoundError: No module named 'unsloth' #43): 13 workflows succeeded and six did not. Several Windows failures occurred during installation with access denied on pydantic_core; newer upstream install scripts contain relevant fixes. The combined source and its CI results need independent confirmation; other Mac/Composer failures should not be silently counted as successful.

Known limitations and review gates

  • The logical finder covers historical text parts, not arbitrary unmounted non-text/HTML tool-card contents.
  • Native Select All / selection-copy cannot span unmounted rows; transcript export / Copy as Markdown remain separate facilities.
  • A single necessary heavy row can exceed target DOM cost. Historical heavy-wheel stress failures need fresh assessment; do not imply all stress scenarios passed.
  • Verify same-chat Off vs Dynamic while Browser Use is actively generating in Unsloth Windows Desktop/WebView2, including typing latency, scroll to older tool result, logical find, copy text, return to the live answer, and window/scrollbar behavior.
  • Final sign-off requires frontend build and tests, browser E2E, Windows binary and relevant integration checks on this exact SHA. No tests are disabled just to make CI green.

Development disclosure

Developed collaboratively with ChatGPT-6 Chat, including design, implementation, integration, debugging and QA; contributor performed separate Windows/WebView2 evaluation.

@Sneakr

Sneakr commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Hi, thanks for your contributions. This is a work in progress and a fix #13919 is already in the works. However, I did manually test your PR too and it has issues, I will close this as we are already working on it and should be fixed in the next patch. Appreciate your work and feel free to test the new fixes and let me know if my conclusions are incorrect or something missing. Thank you

Edit:
I'll leave this open for the memory benchmarks and assessing those as well.

Edit 2:
Just saw your comment in #12552 , I understand your focus is memory improvements as well, thank you, we will test further!

@Sneakr Sneakr closed this Oct 17, 2026
@Sneakr Sneakr reopened this Oct 17, 2026
@Griggelor

Copy link
Copy Markdown
Author

@Sneakr

ok, thank you.
If I can do anything to solve the occurring issues, let me know.

Yes, for me it improves RAM significantly, especially in long "night and day" agent runs.
In my runs I measured in normal mode up to 4,6gb RAM usage by the webview task.
This reduces to the range of 1gb with this PR.
I think this is the advantage since lags have been solved by your work before.

For me this is a big advantage as I use Q5 qwen flash next on 395+ and system is already well filled with this model.
It reduces memory pressure - every gig helps :)

@Sneakr

Sneakr commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

@Griggelor Yes, 100% very good idea, I will take a deeper look into this PR and your idea, thank you

@Griggelor

Copy link
Copy Markdown
Author

Hi @Sneakr,

did you have a chance to check the PR?

There are still issues with long, growing chats and typing/usability in front end in Windows. (#16656 and #16603 and my experience with unsloth 0.1.915)
Form my point of view this PR would fix it and save RAM.

Shall I update PR due to changes in main and occurring conflicts?

@Sneakr

Sneakr commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

@Griggelor Hi, I have forwarded the PR to the team to look into. Tagging here for visibility @Imagineer99 @wasimysaid

Edit: Sorry for the delay

@Griggelor

Griggelor commented Nov 10, 2026 •

Copy link
Copy Markdown
Author

Hi @Sneakr and Team @Imagineer99 @wasimysaid ,

working in long chats, especially with Browser Use, still causes significant UI lag. Over time, these conversations can become almost unusable. Since this is still an issue, I had ChatGPT update our proposed virtualization feature to the latest Unsloth mainline yesterday.

Yesterday, I was still experiencing the familiar typing lag and very high RAM usage in a long conversation with Browser Use.

Image Image

Both screenshots show the exact same chat, taken during active LLM generation. In both cases, memory usage drops by approximately 800 MB shortly after generation finishes.

Measurement Nov 9 (standard) Nov 10 (R6V3) Change
Chat renderer RAM 5,374.2 MB 1,601.7 MB −70.2%

On my system, the patch has been working flawlessly and reliably so far. The improvement in responsiveness is noticeable, especially in longer agent conversations.

For anyone interested in testing it, the quickest way to get a feel for the feature would be to use a Windows test installation and try the prebuilt frontend executable: Download artifact.

This is a major quality-of-life improvement.

Alongside the compaction issues, typing lag and general UI delays are currently among the most frustrating problems in long-running agent workflows.

I really hope we can get this feature into the official release.

If there's anything I can do to help move this forward, maybe preparing feature documentation, providing additional benchmarks, testing, or anything else, please let me know. I'd be happy to help!

@Imagineer99

Copy link
Copy Markdown
Member

Thanks @Griggelor for following up. Yes, could you update this PR with the version from your fork PR #43? That’s the version I tested.

I tried it in Windows Edge with the same 740-message synthetic chat, twice per mode. With virtualization off, all 740 messages were mounted and the renderer used 514–531 MiB. With Dynamic on, only 4 were mounted and it used 203–222 MiB, about 59% less. Median typing latency was around 6 ms in both modes once the chat had settled.

I’d lean toward keeping Dynamic opt-in initially. The most useful follow-up would be to compare typing with Dynamic off and on in the same long Browser Use chat while it’s generating in Unsloth Desktop. I’d also like to know how it feels to scroll back to an old tool result, find and copy the text you need, then return to the live reply. Happy to review the updated PR while you check that.

…n (2026-11-11)

Integrates fork QA #43 onto upstream fcae458 while preserving the newer frontend changes; retains default Off, with Dynamic/Fixed opt-in. Enables fork-only Windows QA build for the 2026-11-11 integration branch.

Copy link
Copy Markdown
Author

Hi @Imagineer99,

thank you very much for testing and for sharing your results! Great to see that your measurements confirm the significant memory savings.

ChatGPT has now updated the existing PR #14001 with the implementation from #43, integrated into the newer Unsloth mainline.

And yes, the exact usability points you mentioned have been particularly important to me during development and testing with real, long-running Browser Use conversations in Unsloth Desktop.

My experience with the previously tested R6V3 build:

  • Typing responsiveness: No noticeable input delay, even in very long chats. Typing feels significantly faster and smoother compared to the previous standard version. The severe typing delays I experienced with the standard version have completely disappeared.
  • During active Browser Use: Even while Browser Use is actively running and the model is generating, typing in the input field, scrolling through the chat and navigating remain smooth, without noticeable UI lag. The overall user experience is excellent.
  • Scrolling and navigation: Smooth scrolling up and down, jumping all the way back to the beginning of a long conversation, and returning to the latest messages without problems.
  • Older tool results: Finding and copying content from previous tool outputs and navigating back to the ongoing conversation works smoothly.

Regarding the default setting: Dynamic and Fixed are already opt-in. Virtualization is disabled by default, preserving the existing renderer. Both Dynamic and Fixed can be enabled globally or configured individually for each chat.

The new November 11 integration has already passed the targeted frontend and browser tests, and the Windows EXE build succeeded. I'll run regression tests tomorrow on my real Windows system, using the new EXE with Unsloth Desktop 0.1.917, and try to collect some comparative typing latency measurements with Dynamic off and on during active Browser Use generation.

Thanks again for taking the time to look into this! I hope we can get it into an official release for everyone.

@Imagineer99

Copy link
Copy Markdown
Member

Thanks, I missed that Dynamic was already opt-in. Glad to hear you could copy an old tool result and jump back to the live reply. I’d be interested to hear how typing feels with Dynamic on and off in tomorrow’s Windows test. Thanks for updating the PR!

@Griggelor

Copy link
Copy Markdown
Author

Hi @Imagineer99,

good news. In Unsloth 0.1.917 beta, there is no noticeable typing lag anymore, even in standard mode!

So the main benefit of virtualization is now again RAM usage. This has also noticeably improved in the latest standard Unsloth version.

One new minor issue I noticed in 0.1.917 standard and patched version: when opening a long chat, the text visibly shifts and jitters for about 10–20 seconds while the conversation loads. I didn't experience this with earlier versions.

Nevertheless, virtualization still significantly reduces RAM usage in longer, continuous 2–3 hour chats involving Browser Use, screenshots, and AI-assisted email work.

Unpatched Unsloth Desktop 0.1.917, in this use case:

grafik

Patched Unsloth Desktop 0.1.917, same use case (off):

grafik

Immediately after previous snapshot Patched Unsloth Desktop 0.1.917, same use case, same chat (dynamic):

grafik

Dynamic keeps the mounted DOM limited and reduces RAM usage. In this example, by roughly 40%.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants