Repository navigation
Description
Summary
When I regenerate a model response in Unsloth Studio, the app inserts a new copy of the preceding user message into the conversation instead of reusing the existing user message by id. Because the copy is a full deep copy, it also duplicates the message's attachments (large document attachments included). Doing this repeatedly — which is what "Regenerate" encourages — makes the same user turn appear multiple times in the conversation. This bloats the context sent to the model every turn and can push a chat past the model's context window, causing OOM / "context full" failures and wasted token budget.
Environment
- OS: Windows 11 Pro
- Unsloth Version: v0.1.804-beta
- Package Version: 2026.8.22
- Desktop App Version: 0.1.804-beta
- llama.cpp: b10679-mix-67dfc8b
- Reported via: local
studio.dbinspection
Steps to reproduce
- Start a chat in Unsloth Studio.
- Send a user message that includes one or more large
documentattachments (e.g. a Markdown/PDF file). - Generate a response.
- Use Regenerate (optionally more than once) on the response.
- Open the chat's conversation records (the
chat_messagesrows instudio.db).
Observed: the user message is present more than once, with identical content and identical attachments, both rows pointing at the same parent_id.
Actual behavior
Two or more rows in chat_messages hold the same user content and same attachment payload for what is logically one user turn.
Concrete example from the thread "DSP UIC Version Review" (thread_id = __LOCALID_KQtciuT):
message id |
role | parent_id | content | attachments |
|---|---|---|---|---|
SaKf868 |
user | cOfdER0 |
"Good, let me share with an improved version of the document v3.1 and the…" | PRF_PART_II-THEORY_(v3.1).md, OxAlpha_PartII_Consolidated_Issue_Register_v3.0.md |
oHXbD51 |
user | cOfdER0 |
"Good, let me share with an improved version of the document v3.1 and the…" | PRF_PART_II-THEORY_(v3.1).md, OxAlpha_PartII_Consolidated_Issue_Register_v3.0.md |
Both are role = user, identical content, identical document attachments, and the same parent_id (cOfdER0) — a duplicate of a single logical user turn.
The same pattern appears in other threads, e.g. "PRF 3.1 - Qwen3.8-27B" contains two separately-duplicated user messages.
Expected behavior
Regenerating a response should reuse the existing, already-persisted user message (by id/parent_id) and only replace/append the assistant output. The user turn — and its attachments — must not be re-inserted as a new row.
Impact
- Context bloat / token inflation. Each regenerate re-appends the full user message and its attachments. Over a long, heavily-regenerated conversation this can double/quadruple the fed-to-model context for what is logically one turn. In the reproduced thread the conversation grew to ~217k tokens, and un-trimmed it trends toward overflowing the model's context window.
- Higher token cost for API-connected models (charged per input token).
- Long-context instability / OOM: the inflated context increases the KV cache + prompt length, pushing local models past the window and into "context full" / OOM failures (see also existing issues about context-full breakage, e.g. Feedback & Bug Report: Unsloth Studio on Windows – KV Cache, UI & Performance issues #4821, [Bug] Chat thread is not created in sidebar until deleting a message; export returns empty or stale chat data #5250).
- Slower prefill (a non-linear, model-architecture-related cost) that grows with the duplicated context.
Root-cause hypothesis
On regenerate, the frontend/backend builds the turn by appending the user turn rather than linking to the existing user message, so each regenerate produces a new chat_messages row with a deep copy of the content + attachments. Likely a "regenerate = re-send last turn" implementation that does not check for an existing user message with the same parent_id.
Suggested fix
- Before inserting on regenerate, look up whether a user message already exists for the target
parent_id; if so, do not create a duplicate — only add/replace the assistant response. - Optionally: keep a stable
(thread_id, parent_id)identity for the user turn so attachments are stored once and referenced (not deep-copied). - Add a database-level guard (unique on
(thread_id, parent_id, role='user')) to prevent duplicates.
Additional note
Even the multi-version attachments the user genuinely uploads (e.g. a document's v2.0 and v3.0) are exacerbated by this — but the core defect above is the spontaneous duplication of an already-sent user turn on regenerate, independent of intentional versioning.
Report prepared from a local studio.db inspection of chat_messages / chat_threads on the environment listed above.
Activity
Studio: collapse duplicate user turns on chat sync (unslothai#9984)
test(studio): stub dedupe module in delete-thread-message cost tests
Studio: purge stored user clones even when attachment ids differ
fix(studio): reuse user message id on regenerate append (unslothai#9984)
Keep the runtime's message id on append, and test the tree invariant (u…
Seed the thread from the unslothai#9984 report as a fixture
Studio: test that a chat message keeps its identity (#9984) (#10064)
danielhanchen commentedon Sep 6, 2026
Regenerate doesn't insert a new user row, it's keyed on the message id and retry branches share the parent. What you saw are two real branched turns 26h apart. If you can reproduce a true duplicate on the current build please reopen!
To update: the desktop app updates itself (Settings > General), otherwise
unsloth studio update, or in Dockerdocker exec <container> unsloth-studio-update.