Skip to content

fix(studio): preserve chat tool selections across model unloads - #13621

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
Sneakr:fix/chat-tool-selection-persistence
Oct 14, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
Sneakr:fix/chat-tool-selection-persistence

Conversation

@Sneakr

@Sneakr Sneakr commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Unloading a model cleared the chat’s tool selections and could save those cleared values back into the chat. Preserve Search, Code, and other tool selections across model unload/reload using the existing settings persistence. Model capabilities and transient runtime state still reset normally.

Validation:

  • Added 14 regression cases covering enabled/disabled selections, per-chat settings, pending writes, and tool exclusivity.
  • Passed 17 related test files and TypeScript checks.

Before / after

Composer pills: load, eject, load again, before vs after

Same chat, unsloth/Qwen3-0.6B-GGUF: Search and Tools turned on, then picker > Eject model, then the same model loaded again. Before, both pills come back off and the chat stores them off; with this PR they stay on (the reloaded prompt carries the tool definitions again, 43 -> 961 tokens). MCP and RAG selections also survive an unload now.

@Sneakr
Sneakr requested a review from danielhanchen as a code owner October 13, 2026 15:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-14T19:40:50.221527Z df5c1f6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU, studio) fails here on tests/studio/test_deep_research_frontend_contract.py::test_research_presentation_is_integrated:

assert 'saveBool(CHAT_DEEP_RESEARCH_ENABLED_KEY, false)' in checkpoint_update

This one is specific to this PR; the test passes on current main. The contract pins that setCheckpoint in the chat runtime store turns deep research off (and persists false) when the model changes. That is exactly the behavior this PR changes, so preserving the deep research selection across a model unload no longer goes through that line.

If keeping deep research on across an unload is intended, the assertion at tests/studio/test_deep_research_frontend_contract.py:284-287 needs updating in this PR to pin the new rule. That would be resolveToolsEnabledOnLoad(...) deciding deepResearchEnabled on load. If it is not intended, setCheckpoint should keep the saveBool(CHAT_DEEP_RESEARCH_ENABLED_KEY, false) reset.

The other reds on this PR are fixed on main (#13640 for the bundle budget, #13646 for test_text_io_encoding) and clear on a rebase.

…rence

A pill now follows the live store unless the selected model clamps it
off or a model is still loading. In those cases the chat's stored value
stands in, so a clamp never overwrites the preference and the composer
never shows a tool the model cannot run.

- Kimi: a non-persisted Search-off is no longer re-armed from storage,
  so opening or leaving a chat keeps Thinking on.
- A settings write during a model load no longer stores the previous
  model's clamp over the chat's Search, Code or Research.
- Unloading re-derives the clamped pills from the preference, so a
  provider default does not outlive its model.
- Restoring defaults after a held edit, and applying a chat's stored
  pills, both go through the capability clamp.
- Revert the out-of-scope composer gating port; keep only the Research
  menu gate for local models without tools.
- Re-pin the deep research contract test to the new setCheckpoint rule.
A pill's recorded value now follows the live store while the chat's
settings write is still waiting on its debounce, the same way that
write reads it, unless the model clamps the pill off or is loading.
It used to keep the value from the moment of the click, so a change
that does not persist, such as Kimi turning Search off when Thinking
is enabled, could be undone by switching models before the write ran.

- Kimi: Search, then Thinking, then a quick switch to another
  provider no longer turns Search back on or saves it as on.
- The external model patch reapplied after a cancelled local load no
  longer carries a cached Research value, so a Research click made in
  between is kept. setCheckpoint and the chat page's provider effect
  already set Research for the new model.
- Tests cover both Kimi orderings and the incognito checks on the
  Research paths, and the reload matrix only checks the pills a local
  load controls.
- The deep research contract test drops two assertions that also
  matched upstream and pins the Research menu clause instead.
- Remove comment text that no longer matches the code and restore the
  still accurate part of an upstream doc comment.
Three places where the branch had moved away from upstream behaviour.

- Research support for an external model is read from the providers
  store with the same rule the composer menu uses. The previous lookup
  parsed the provider list from localStorage on every snapshot and
  hydration pass. When that read failed it refused Research while the
  menu item stayed enabled, so the click did nothing.
- A chat's own pill override no longer falls back to the default
  captured when the chat was opened. Chats saved before the pill keys
  existed reach the stored global value and the provider default
  again, so picking Anthropic or OpenAI in one turns Search on as
  upstream does.
- A same-model reload keeps the Search and Code pills the model was
  running with, as upstream does, instead of reading them back from
  storage, which can hold a stale value after a failed write.
- Tests cover each case.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: c3aee5fe99

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen self-assigned this Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from Sneakr Oct 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 14, 2026
@unslothai unslothai deleted a comment from Sneakr Oct 14, 2026
@unslothai unslothai deleted a comment from Sneakr Oct 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 14, 2026
# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
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