Skip to content

Studio: make Stop loading actually stop a model that is still downloading - #11727

Closed
NilayYadav wants to merge 4 commits into
unslothai:mainfrom
NilayYadav:chat-stop-gguf-download
Closed

NilayYadav wants to merge 4 commits into
unslothai:mainfrom
NilayYadav:chat-stop-gguf-download

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Clicking Stop in chat while a model is still downloading does not stop it. The download keeps going, the model loads into the GPU anyway, and picking another model gets refused with "Another model is already loading".

Now Stop cancels the download straight away.

pull Bot pushed a commit to pirica/unsloth that referenced this pull request Sep 23, 2026
…nslothai#11741)

* studiobench: compare a code fence one arm scrolled past on its text

The UI parity gate failed on backend-only pull requests (unslothai#11724, unslothai#11727,
and others on 2026-09-23) with differences like
msg15(assistant):1847269->2150610c on model_change, reasoning_toggle,
select_all_copy, settings and image_upload at r100K.

Those are not rendering differences. code-fence-defer.tsx (unslothai#9462, the
default since unslothai#9567) renders a fence as a plain shell until it first comes
within a viewport of the reader, then highlights it for the rest of the
mount. After reasoning_toggle the r100K film leaves the viewport either
near the tail (scrollTop ~50,740) or about 20,000px higher, at random per
cell on one build (78 of 172 cells across 43 recorded payloads), and the higher landing
latches the fences of msg11/13/15 until thread_reopen remounts them. A null
control whose cells all landed low measured those actions stable, so the
result's latch noise was scored as a regression. The same noise also made
a null that did see it excuse settings and model_change outright, which
hid real changes there.

scene/parity.js now reads, in the same walk that produces the unchanged
per-message digest, each fence's latch state, full digest and text digest
(whitespace dropped, since streamdown emits one span per line and the
shell one text node), plus the message with every fence replaced by a
marker. analysis/parity.fence_latch_residue treats a message as differing
only by latch when everything outside its fences matches, every fence
latched on both arms or neither matches in full, and every fence latched
on one arm only matches on its text. Nothing is excused when one arm
latched no fence anywhere, which is what a build whose fences never
upgrade looks like. A latch-only pair is a MATCH, counted and printed, so
it costs no coverage; payloads recorded before this carry no fence fields
and score exactly as before.

The selftest replays both failing runs from their recorded CI payloads,
shows they fail as recorded and pass once the latch is recorded, and
injects genuine differences (a message with no fences, a change outside a
latched message's fences, a highlighting change on a fence both arms
latched, fences that never upgrade) that must still fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studiobench: keep a fence's spacing and language in the latch comparison

The one-sided fence comparison dropped every whitespace character, so
`x = 1` and `x=1`, an indentation change or a space inside a string
read as the same fence, and it never looked at the language, so a fence
that changed language but kept its body read as latch-only too. Drop line
breaks only, the one thing that differs between the shell and the
highlighted form, keep the rest of the text as it is, and record and
compare each fence's data-language.

* studiobench: read a fence's text as lines, not a run of characters

Dropping every newline made a line break moved within the code, `a\nbc`
against `ab\nc`, read as the same fence. Read both forms as lines: the
shell's text split on newlines, and the highlighted fence one line per
element directly inside its <code>, a blank line's lone newline dropped.
Join them with one newline and drop trailing blank lines, which the shell
trims.

* studiobench: compare a fence's text as written, without prose placeholders

The time and id placeholders are there for UI prose. Applied to a one-sided
fence's source they made `"295ms"` against `"310ms"`, or two different
timestamp or id literals, read as the same code.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + UI evidence

Pinned head: c9950abd6f. Review converged; the last round found no issues.

Stop during an in-/load download, then pick another model. Real Studio in Chromium (1440×900). Before is the merge base f8bf9a3a8, after is this PR, on a CPU host with a separate HF cache per side. I opened a chat started on unsloth/Qwen3.5-9B-MTP-GGUF (Q4_K_M), clicked Switch back, pressed Cancel on the load toast once about 200–320 MB had landed, then used Switch back on a chat started on unsloth/gemma-3-1b-it-GGUF.

Before After
/unload answered after Stop 15.0 s 0.3 s
Target bytes written, 3 s / 30 s after Stop +128 MB / +1254 MB 0 MB / 0 MB
Second model pick "Another model is already loading" starts loading
Backend loading afterwards Qwen3.5-9B-MTP-GGUF (still going) gemma-3-1b-it-GGUF

PR 11727 before/after

Review fixes pushed

  • 2db6dacaa: a Stop that cancels a load which never became resident no longer records a lifecycle unload or clears resident sharers for a model that was never loaded.
  • 18753317e: the new cancel only stops the caller's own load in account-scoped installs, the same rule as the scoped cancel.
  • c9950abd6: that path still drops the GPU claim (release_chat_gpu_claim, which is idle-guarded) and the idle reload stash.
  • Each fix has a regression test. Each test fails on the commit before its fix and passes after it.

Rejected: a same-model load that is queued behind the Stop could be evicted. From the chat tab that can't happen, because Stop holds the model lifecycle lease until /unload answers. From another tab it behaves as it did before this PR.

CI: upstream 51/51 pass. The earlier "Parity verdict" red was harness noise, fixed by #11741 and #11772. Staged on fresh main with 17/17 workflows green (Linux, Windows, Mac, GGUF, UI, studiobench): NilayYadav/unsloth-staging#161. Related backend tests: 1037 passed. The 2 failures in that run also fail on the merge base or pass when run alone.

shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11741)

* studiobench: compare a code fence one arm scrolled past on its text

The UI parity gate failed on backend-only pull requests (unslothai#11724, unslothai#11727,
and others on 2026-09-23) with differences like
msg15(assistant):1847269->2150610c on model_change, reasoning_toggle,
select_all_copy, settings and image_upload at r100K.

Those are not rendering differences. code-fence-defer.tsx (unslothai#9462, the
default since unslothai#9567) renders a fence as a plain shell until it first comes
within a viewport of the reader, then highlights it for the rest of the
mount. After reasoning_toggle the r100K film leaves the viewport either
near the tail (scrollTop ~50,740) or about 20,000px higher, at random per
cell on one build (78 of 172 cells across 43 recorded payloads), and the higher landing
latches the fences of msg11/13/15 until thread_reopen remounts them. A null
control whose cells all landed low measured those actions stable, so the
result's latch noise was scored as a regression. The same noise also made
a null that did see it excuse settings and model_change outright, which
hid real changes there.

scene/parity.js now reads, in the same walk that produces the unchanged
per-message digest, each fence's latch state, full digest and text digest
(whitespace dropped, since streamdown emits one span per line and the
shell one text node), plus the message with every fence replaced by a
marker. analysis/parity.fence_latch_residue treats a message as differing
only by latch when everything outside its fences matches, every fence
latched on both arms or neither matches in full, and every fence latched
on one arm only matches on its text. Nothing is excused when one arm
latched no fence anywhere, which is what a build whose fences never
upgrade looks like. A latch-only pair is a MATCH, counted and printed, so
it costs no coverage; payloads recorded before this carry no fence fields
and score exactly as before.

The selftest replays both failing runs from their recorded CI payloads,
shows they fail as recorded and pass once the latch is recorded, and
injects genuine differences (a message with no fences, a change outside a
latched message's fences, a highlighting change on a fence both arms
latched, fences that never upgrade) that must still fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studiobench: keep a fence's spacing and language in the latch comparison

The one-sided fence comparison dropped every whitespace character, so
`x = 1` and `x=1`, an indentation change or a space inside a string
read as the same fence, and it never looked at the language, so a fence
that changed language but kept its body read as latch-only too. Drop line
breaks only, the one thing that differs between the shell and the
highlighted form, keep the rest of the text as it is, and record and
compare each fence's data-language.

* studiobench: read a fence's text as lines, not a run of characters

Dropping every newline made a line break moved within the code, `a\nbc`
against `ab\nc`, read as the same fence. Read both forms as lines: the
shell's text split on newlines, and the highlighted fence one line per
element directly inside its <code>, a blank line's lone newline dropped.
Join them with one newline and drop trailing blank lines, which the shell
trims.

* studiobench: compare a fence's text as written, without prose placeholders

The time and id placeholders are there for UI prose. Applied to a one-sided
fence's source they made `"295ms"` against `"310ms"`, or two different
timestamp or id literals, read as the same code.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@danielhanchen danielhanchen self-assigned this Sep 29, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thank you for the PR! Closing this as superseded by #11697.

When this PR was opened, Stop in chat sent a plain /unload naming only the model, which never reached a load that was still downloading. Since #11697, Stop sends /unload with cancel_load_request_id, and the existing scoped cancel path sets the running attempt's cancel_event (and cancel_complete) before the lifecycle gate, so the GGUF download stops right away. I confirmed this on current main with a scoped unload against a running attempt that has no llama-server yet: the load is cancelled and the gate is never entered.

The unscoped path this PR changes is now only reached by the Loaded Models and API Monitor unload buttons and external API clients. If that turns out to matter for a still-downloading model, it would be better as a small follow-up scoped to those callers.

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.

2 participants