Skip to content

fix(studio): support preserve thinking for llama.cpp connections - #11706

Merged
Lyxot merged 5 commits into
unslothai:mainfrom
Imagineer99:fix/connections-preserve-thinking
Sep 24, 2026
Merged

Lyxot merged 5 commits into
unslothai:mainfrom
Imagineer99:fix/connections-preserve-thinking

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Connections hides Preserve thinking and omits prior reasoning when talking to an external llama-server. This adds the existing control to the llama.cpp connection preset, forwards chat_template_kwargs.preserve_thinking, and replays previous assistant reasoning when enabled.

Reasoning survives backend history conversion, reasoning-only replies, and Studio tool-loop follow-ups. The control works without advertising an unsupported thinking-generation toggle. Other provider types retain their existing behavior; the selected llama.cpp model still needs a template that supports preserve_thinking.

Validation

  • Frontend typecheck passed.
  • 110 backend tests, 23 chat-history integration tests, and 85 frontend tests passed after updating to current main.
  • Live feature verification with Qwen3.6-27B-UD-IQ2_XXS and llama-server build 11030, through Studio's browser UI and a saved llama.cpp connection:
    • Enabled: the second turn replayed one thinking block (333 characters).
    • Disabled: the third turn sent no historical thinking.
    • Re-enabled: the fourth turn replayed all three prior blocks (1,104 characters).
    • llama-server's rendered prompt included those blocks when enabled and excluded them when disabled.
    • A live client-tool round trip preserved 134 characters of thinking alongside the tool result and returned the correct answer.

The live run exercised the feature before rebasing onto current main; the automated checks above were rerun after rebasing. Live testing used the source browser UI, not a rebuilt Desktop installer. Studio's built-in tool loop is covered by regression tests; the live tool test used a deterministic client-side function.

pull Bot pushed a commit to ShinnChow/unsloth that referenced this pull request Sep 24, 2026
…k fail (unslothai#11749)

* Chat UI driver: wait for the Recents thread to load, and let the check fail

The Recents step clicked the first sidebar row, slept 500 ms and read the
turns once. Opening a chat runs a history loader that awaits the thread, its
active runs, its messages and its research state in sequence before anything
renders. On the Windows lane, which runs two Studios and two browsers on one
runner, that took longer than 500 ms in 15 of 57 Windows runs on 2026-09-23,
so the read found turns_text=''. The server logs of those runs show the
messages request returning 200 at or after the moment the driver navigated
away; the thread was loading, not empty.

It never failed a job because the soft_fail sat inside the try whose
except Exception was meant for click errors. In STRICT mode the
AssertionError was caught, logged as "recent-thread click 0 failed", and the
step passed. The FAIL line that shows up in failing runs of unslothai#11706 and
unslothai#11731 is this swallowed message; those jobs failed on other steps.

The step now:
- picks the Recents row whose title is a prompt this run sent, falling back
  to the listed order, since the most recent row need not be ours
- waits up to 20 s for the URL to name that thread and for a user turn to
  contain one of our prompts, instead of reading once after 500 ms
- raises outside the click retry, so a thread that opens without our turns
  fails the run in STRICT mode

tests/studio/test_chat_ui_recents_step.py runs the helper in Chromium
against a page whose thread renders after 1.5 s (passes), one that never
shows our prompts (fails), and one with an unrelated chat above ours
(checks ours), plus source checks for the sleep and the swallowing except.

* Chat UI driver: keep looking for this run's chat when Recents titles are generated

With auto-titling no Recents title equals a prompt this run sent, so the
fallback tried the newest row, stopped there, and failed after 20 s when
that row was someone else's chat, even with ours next in the list.

A row titled with our prompt is ours and must still show our turns. A row
reached only by the fallback is now judged when it loads: our prompt passes,
someone else's turns or none moves on to the next row, within a 60 s budget.

* Chat UI driver: do not judge a Recents row from the previous thread's turns

The chat keeps one runtime while the next thread loads, so the previous
thread's turns stay on screen for a while after the URL changes. Judging a
fallback row on those could reject our chat as someone else's, or, with our
thread already open, pass a different chat on our stale turns.

Snapshot the user turns and open thread before each click, and count turns
identical to that snapshot as not loaded yet unless the clicked row is the
thread that was already open. The fixture can now keep stale turns on screen
until the next thread loads, as the app does.

* Chat UI driver: reopen this run's chat by id in the Recents step

The prompts are fixed, so on a reused Studio home an earlier run's chat can
carry the same title and turns, and the title match would open it and pass
without ever reopening this run's chat.

Read this run's chat id while it is open, from ?thread= or the active Recents
row, and have the Recents step open exactly that row and require our turns in
it. The title search stays as the fallback when no id is on the page. A test
evaluates the driver's capture expression itself, since it only runs there.

* Chat UI driver: find this run's chat by id anywhere in the sidebar

Pinned and project chats use the same row testid as Recents, so on a
reused home this run's chat can sit past the first 20 rows the title
search reads. Locate the captured id directly across every row, and walk
candidate rows rather than indices so a strict row, known to be ours by
id or title, still has to show our turns.

* Recents step tests: skip when another file left a Playwright stand-in

Backend CI's CPU studio shard has no Playwright, and
test_heavy_thread_measurement_integrity.py installs a stand-in
playwright.sync_api whose every name raises RuntimeError. importorskip then
succeeds, and all 12 browser tests errored in that job. A stand-in that
raises now skips, like a missing package.
# Conflicts:
#	studio/frontend/src/features/chat/shared-composer.tsx
… llama.cpp kwarg merge

The reprompt path only builds a stalled assistant message after a provider-hosted tool ran, and reasoning replay is only enabled for llama.cpp connections, which host no tools. Adds coverage for reasoning-only turns whose tool calls are all dropped server cards, and for preserve_thinking and enable_thinking sharing chat_template_kwargs. Tightens the related comments.
@Lyxot

Lyxot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Pushed a few small follow-ups on top of this PR:

  • Merged latest main to resolve the conflict in shared-composer.tsx. main also carries the window.matchMedia fix (Read the sidebar pin's width only where matchMedia exists, and expect the update card's scaled width #11700) behind the training-dataset-source-transitions frontend failure.
  • Fixed the backend CI failures. OAICompatTransport now reads client.provider_type, and the test fakes standing in for ExternalProviderClient in four test files didn't define it, so 26 tests errored. The fakes now carry provider_type; there is no production change for this.
  • Removed the reasoning_content added to the stalled reprompt message in studio_tool_loop.py. That path only runs after a provider-hosted tool, and llama.cpp connections host none, so it was unreachable.
  • Added tests for a reasoning-only turn whose tool calls are all dropped server cards, and for preserve_thinking and enable_thinking sharing chat_template_kwargs.
  • Tightened a docstring and two test comments.

@Lyxot

Lyxot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Codex review on the staging copy converged on head 70fe2f54da: Lyxot#86 (comment) ("Didn't find any major issues").

Staging CI on the same head (Lyxot#86): 59 passed, 4 skipped, 1 failed. The failure is tests/studio/test_desktop_reliability_frontend_contract.py::test_image_train_rail_matches_create_and_header in Repo tests (CPU, studio) (https://github.com/Lyxot/unsloth/actions/runs/35962125060). It fails the same way on main at the merge base 9815e76313, and this PR touches none of the media-rail files, so it comes from main. The backend and frontend jobs that failed on the previous head now pass.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Codex converged and staging CI passed on this head; also verified against latest main locally.

@Lyxot
Lyxot merged commit 4fabb25 into unslothai:main Sep 24, 2026
64 of 65 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…k fail (unslothai#11749)

* Chat UI driver: wait for the Recents thread to load, and let the check fail

The Recents step clicked the first sidebar row, slept 500 ms and read the
turns once. Opening a chat runs a history loader that awaits the thread, its
active runs, its messages and its research state in sequence before anything
renders. On the Windows lane, which runs two Studios and two browsers on one
runner, that took longer than 500 ms in 15 of 57 Windows runs on 2026-09-23,
so the read found turns_text=''. The server logs of those runs show the
messages request returning 200 at or after the moment the driver navigated
away; the thread was loading, not empty.

It never failed a job because the soft_fail sat inside the try whose
except Exception was meant for click errors. In STRICT mode the
AssertionError was caught, logged as "recent-thread click 0 failed", and the
step passed. The FAIL line that shows up in failing runs of unslothai#11706 and
unslothai#11731 is this swallowed message; those jobs failed on other steps.

The step now:
- picks the Recents row whose title is a prompt this run sent, falling back
  to the listed order, since the most recent row need not be ours
- waits up to 20 s for the URL to name that thread and for a user turn to
  contain one of our prompts, instead of reading once after 500 ms
- raises outside the click retry, so a thread that opens without our turns
  fails the run in STRICT mode

tests/studio/test_chat_ui_recents_step.py runs the helper in Chromium
against a page whose thread renders after 1.5 s (passes), one that never
shows our prompts (fails), and one with an unrelated chat above ours
(checks ours), plus source checks for the sleep and the swallowing except.

* Chat UI driver: keep looking for this run's chat when Recents titles are generated

With auto-titling no Recents title equals a prompt this run sent, so the
fallback tried the newest row, stopped there, and failed after 20 s when
that row was someone else's chat, even with ours next in the list.

A row titled with our prompt is ours and must still show our turns. A row
reached only by the fallback is now judged when it loads: our prompt passes,
someone else's turns or none moves on to the next row, within a 60 s budget.

* Chat UI driver: do not judge a Recents row from the previous thread's turns

The chat keeps one runtime while the next thread loads, so the previous
thread's turns stay on screen for a while after the URL changes. Judging a
fallback row on those could reject our chat as someone else's, or, with our
thread already open, pass a different chat on our stale turns.

Snapshot the user turns and open thread before each click, and count turns
identical to that snapshot as not loaded yet unless the clicked row is the
thread that was already open. The fixture can now keep stale turns on screen
until the next thread loads, as the app does.

* Chat UI driver: reopen this run's chat by id in the Recents step

The prompts are fixed, so on a reused Studio home an earlier run's chat can
carry the same title and turns, and the title match would open it and pass
without ever reopening this run's chat.

Read this run's chat id while it is open, from ?thread= or the active Recents
row, and have the Recents step open exactly that row and require our turns in
it. The title search stays as the fallback when no id is on the page. A test
evaluates the driver's capture expression itself, since it only runs there.

* Chat UI driver: find this run's chat by id anywhere in the sidebar

Pinned and project chats use the same row testid as Recents, so on a
reused home this run's chat can sit past the first 20 rows the title
search reads. Locate the captured id directly across every row, and walk
candidate rows rather than indices so a strict row, known to be ours by
id or title, still has to show our turns.

* Recents step tests: skip when another file left a Playwright stand-in

Backend CI's CPU studio shard has no Playwright, and
test_heavy_thread_measurement_integrity.py installs a stand-in
playwright.sync_api whose every name raises RuntimeError. importorskip then
succeeds, and all 12 browser tests errored in that job. A stand-in that
raises now skips, like a missing package.
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…lothai#11706)

Show the Preserve thinking control on llama.cpp connections, forward chat_template_kwargs.preserve_thinking alongside enable_thinking, and replay earlier assistant reasoning (frontend history, backend history conversion, and Studio tool-loop rounds) when enabled. Other providers and local models are unchanged.
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.

3 participants