Skip to content

[Bug] Unsloth Studio duplicates the preceding user message (and its attachments) every time a response is regenerated, inflating context and token count #9984

Closed

Description

@Iory1998

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.db inspection

Steps to reproduce

  1. Start a chat in Unsloth Studio.
  2. Send a user message that includes one or more large document attachments (e.g. a Markdown/PDF file).
  3. Generate a response.
  4. Use Regenerate (optionally more than once) on the response.
  5. Open the chat's conversation records (the chat_messages rows in studio.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

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

  1. added
    feature request
    on Aug 29, 2026
  2. self-assigned this
    on Aug 31, 2026
  3. danielhanchen commented on Sep 6, 2026

    @danielhanchen
    Member

    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 Docker docker exec <container> unsloth-studio-update.

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

Metadata

Metadata

Assignees

Labels

bugfeature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions