Repository navigation
Studio: link a saved preset to a model and apply it on every switch - #15279
debojyoti-dev wants to merge 25 commits into
Conversation
…nslothai#14900) Run settings gets a "Use for this model" switch under the preset picker. Turning it on links the active custom preset to the loaded model; from then on, selecting that model puts the preset on exactly as picking it by hand would. Edits made afterwards stay temporary until saved, and the next switch back puts the linked preset on again. The picker marks the linked preset, and a model linked to a preset other than the active one says so with an Unlink action. Deleting a preset removes its links. The links persist in chat settings as modelPresets, a map from model id to preset name that the server merges per model; a null entry removes one link and is dropped rather than stored.
|
Main measures 2046.8 KB transfer / 6783.7 KB raw, on #15276's build against
The |
`studio/backend/tests/test_mcp_servers.py::test_get_enabled_mcp_tools_caches_discovery` fails now and then in `(Python 3.13, g-r)`, for example on #15279, and passes when run alone: ``` tests/test_mcp_servers.py:1336: in test_get_enabled_mcp_tools_caches_discovery E assert 0 == 1 E + where 0 = len([]) ``` ## Cause The tests, not the product. `core.inference.mcp_client` keeps discovered tools (`_tool_cache`) and failed-probe cool-offs (`_probe_cooloff_until`) as module state keyed by server id, and most MCP tests name their server `s1`. 1. `test_mcp_apps.py::test_a_rediscovery_that_fails_or_races_an_edit_caches_nothing` (from #9301) runs a probe that fails. That correctly records a cool-off for `s1`, and nothing removes it. 2. When `test_get_enabled_mcp_tools_caches_discovery` later runs on the same worker, it resets the tool cache but not the cool-off map. `get_enabled_mcp_tools()` then skips discovery for its own `s1`, so the fake probe is never called. How it was found: I ran the 151 MCP-related backend test files with a detector on that state. It named this leak, plus `test_mcp_tool_read_off_event_loop.py` leaving `s1` in the tool cache. Running the two tests in that order reproduces the CI failure every time. ## Fix - An autouse fixture in `studio/backend/tests/conftest.py`, `_forget_mcp_discovery_state`, clears both maps before and after every test. It follows the other module-state resets already there and does nothing when `mcp_client` has not been imported. - `test_mcp_discovery_state_reset_between_tests.py` pins it: two tests in one xdist group. The first records a cool-off and a cache entry the way the client does; the second asserts neither survived. ## Verification - The leak order (`test_mcp_apps.py::test_a_rediscovery...`, then `test_get_enabled_mcp_tools_caches_discovery`), plus the new pair: 5 passed here. Without the fixture, 2 failed: the caching test and the pair's second test. - All 40 backend test files that touch `mcp_client`: 5703 passed here against 5701 on main, which is the 2 new tests. The same 5 failures on both sides come from this host's environment (`test_blender_managed.py` x4 and `test_validate_url_rejects_bad[noscheme.com]`).
A linked preset stayed active on the next model with no link, so a model never visited before ran the linked model's sampling and system prompt, and a visited one showed the linked preset's name over its own values (a Save then overwrote that preset). Leaving a linked model for an unlinked one now puts back the pick from before the link took over, with the destination's own memory replayed over it. Also drop the dead provider lookup for custom presets, correct the hint about load settings, and trim comments. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c06fa017c
ℹ️ 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".
| for (const [modelId, linkedName] of Object.entries(modelPresets)) { | ||
| if (linkedName === name) setModelPreset(modelId, null); |
There was a problem hiding this comment.
Remove deleted-preset links from the server's current map
If another browser links an additional model to this preset after this tab hydrates, that model is absent from this local modelPresets snapshot, so deletion never emits its null entry. The backend's per-key merge retains that link; it is ignored while the preset is missing, but saving a new preset with the same name reactivates it on that model. Perform deletion cleanup atomically against the server's current link map rather than relying only on links known to the deleting tab.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not fixing: needs a second browser to link another model to this preset after this tab loaded, then a delete here and a new preset under the same name. The stale link is inert until that recreate, and the server-side merge stays per key by design.
Keep a restored edit of the linked preset when the first model of the page arrives after settings, restore the exact pre-link values and provenance rather than the preset definition, and ignore the checkpoint round trip a background auto-load makes when it puts the visible model back. [skip ci]
…ross reloads Leaving a linked model now gives an open conversation its own values back the way the link took them, as chat edits, and the pick from before the link survives a reload on the linked model. [skip ci]
The stored pick is dropped on sign-out and on a new sign-in, a chat other than the one open when the link applied keeps its own sampling, and a pick deleted while on the linked model falls back to Default.
A link now puts its preset on the live settings without saving it to the settings DB, a chat or the model's memory, so the stored pick and the installation defaults stay the user's own. Reloading on a linked model finds that pick and applies the link over it again; leaving the model writes the pick back, undoing edits made over the link. Drops the localStorage copy and auth listeners the persisted version needed. [skip ci]
Status and load merges for a model with no link honour the pick the link displaced, so leaving a link under Default applies the new model's recommendation at once (adoption included) instead of the linked model's; the restore no longer lays the old recommendation back over it. [skip ci]
The link drops the linked model's memory in this tab only, so a later status replay cannot lay it back over the preset; leaving a link for an external model puts every earlier value back, since no status merge brings a recommendation there. [skip ci]
Replays lay the model's memory and the open chat's pins back on; a link still showing unedited now stays on top of them instead of the link dropping the model's memory, so neither snapshot is touched.
The overlay and chat snapshots compare against the values the link last applied rather than a fresh copy, so a reload that moves the context cap keeps the capped linked budget instead of reading it as an edit.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b81d549bfc
ℹ️ 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".
| freezePendingChatWrite(shown); | ||
| recommendationMergedFor = null; | ||
| state.setParams(linkedParams(state.params, preset), { persist: false }); |
There was a problem hiding this comment.
Preserve pairing-held edits before applying a linked preset
If a chat's settings read is pending, a sampling edit is held in heldThreadScopedEdits rather than in the debounce handled by freezePendingChatWrite(). Selecting a linked model here replaces that live edit, and when the read resolves, applyThreadScopedSettings() processes held sampling fields by rereading the now-linked values instead of their captured values. A single temperature edit to 0.77, followed more than 400 ms later by selecting a 0.2 link, is lost and the chat ultimately restores its old 0.4. Preserve the held per-field values across this non-persisting update so delayed chat hydration cannot discard them.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not fixing: needs a chat settings read still pending while the user both edits and switches onto a linked model; that read is a local call and the race is not practically reachable. Edits around a link without a pending read are covered.
A chat's own settings arriving after a link applied (a reload in a chat, or opening one on a linked model) now go under the link in this tab, as a replay's do, instead of replacing it while the picker names the link. [skip ci]
Putting a shown link back after a chat's settings arrive now touches only the chat-scoped keys that restore displaced, so a Max Tokens edit or other non-chat override stays. [skip ci]
The link is put back after chat settings land only on keys the user had not moved, so a no-op or first-chat pairing call cannot reset an edit made before sending. [skip ci]
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
export function suspendLinkedPresetSync(..._args: any[]): any {
return () => {};
}Match the real return shape if the region uses the result. Main is green for this test, so this one is specific to the PR. |
The sliced chat-adapter region now calls it, so the harness preamble needs a no-op like its other imports.
Moving a slider on a linked model saved "modified" as the pick's source and the edited value as the installation default, so a reload before leaving the model handed the edit to every unlinked model. Over a link the edit now reaches only the model's own memory, and the stored source stays the earlier pick's. Deleting the linked preset while it showed through the link replaced the stored pick with Default. It now restores the earlier pick, as unlinking does.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 047735e38a
ℹ️ 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".
| queueMicrotask(() => syncLinkedPreset(modelId, false)); | ||
| } | ||
| } else { | ||
| modelPresets[modelId] = presetName; |
There was a problem hiding this comment.
Sync links added to the currently loaded model
When the user enables the switch for the already-loaded model, this branch updates only modelPresets and never calls syncLinkedPreset, leaving linkShown and pickBeforeLink unset even though the UI marks the preset as linked. A subsequent slider edit therefore follows the normal global-persistence path, and switching to an unlinked model leaves the edit in place instead of restoring the pre-link values. Sync the active model when adding the link so edits are treated as temporary as soon as the switch is enabled.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not fixing: when the switch is turned on for the loaded model, the preset on screen is the one picked by hand, so it is already the stored pick and there is no earlier pick to put back. A slider edit after that behaves exactly as it does with no link: the stored pick, its source and the values are the same with the switch on or off, and returning to the model shows the saved preset again. Edits made while the link itself put the preset on screen stay out of the stored pick, which is the case 047735e covers.
…edit (#18011) Editing the system prompt on Default stops Studio from applying each new model's recommended sampling. Load Qwen3-0.6B, type a system prompt in Run settings, then load Gemma 4 E2B for the first time: Gemma keeps Qwen's temperature 0.6 and top-k 20 instead of its own 1.0 and 64. Switching away then saves those values as Gemma's settings. Any preset edit sets `activePresetSource` to `modified`. Model loads and Qwen thinking-mode changes only apply recommended values under `builtin-default`, so a prompt edit blocks every sampling value. Moving one slider has the same problem: changing Temperature also keeps the previous model's top-k, max tokens and the rest. With this PR, `presetEditedKeys` records which sampling controls the user changed. A prompt edit no longer blocks recommended sampling. Changing Temperature keeps that temperature, while the other values follow the next model. The same rule is used for model loads, status refreshes, comparison panes and Qwen thinking changes. Custom presets still keep all their values, and a model with remembered settings still uses them. Picking a preset clears the edited keys. The edited keys are saved one key at a time, so edits from two open tabs add up instead of overwriting each other. Settings saved as `modified` before this change have no record of which controls changed. When the backend starts, it marks every control as edited for them, so they keep the old behavior until a preset is picked again. ## Verification Studio before and after, starting with empty settings. Edits were made in Run settings; models were loaded through the API and picked up by a fresh `/chat` page load. These are the temperature / top-p / top-k values in the outgoing chat request: | Scenario | Before | After | |---|---|---| | Qwen3-0.6B, edit the system prompt, then Gemma 4 E2B | 0.6 / 0.95 / 20 | 1.0 / 0.95 / 64 | | Gemma 4 E2B, set Temperature to 0.3, then Qwen3-0.6B | 0.3 / 0.95 / 64 | 0.3 / 0.95 / 20 | The edited system prompt was still sent after the switch in both builds. These runs used the first revision of this PR. Later commits changed how the edited keys are saved, not how they are applied. New tests cover prompt and slider edits, preset changes, per-model memory, Qwen thinking changes, saving and restoring the edited keys, edits made before settings finish loading, two open tabs, and the backend upgrade of older settings. Typecheck and the backend chat settings and chat history route tests (116) pass. The full frontend suite has 18 failures, and none of them are in chat settings or presets: some test files need a newer Node than the one I ran, and the others depend on locale or time zone. This touches the same Qwen checks as #15279, so whichever merges second will need a rebase. --------- Co-authored-by: Lyxot <[email protected]>
Closes #14900.
Before: a saved preset applied to whatever model was loaded. Switching between models with different sampling needs meant reopening the preset list every time, and it was easy to run one model on another's temperature or system prompt.
After: Run settings has a Use for this model switch under the preset picker. Turning it on links the active custom preset to the loaded model, and from then on selecting that model applies the preset automatically. Several models can share one preset.
The preset's sampling settings and system prompt are applied when the model is selected. Load settings stored in a preset keep the existing behaviour (applied on the next reload), so switching models never triggers a second load.
How
modelPresets(model id → preset name) is a new chat setting. The backend schema accepts it, and the existing per-key deep merge keeps every other model's link when one changes. Anullentry removes a link and is dropped from storage instead of being kept.setModelPreset. A store subscription watches the active checkpoint. When it changes to a linked model, the subscription applies the preset the same way picking it in Run settings does (applyPresetForProvider,fromPreset, so the per-model memory is handled as for a manual pick). It runs one microtask after the load path's ownsetParams, so the model's defaults are filed first. When settings finish hydrating under a model that is already loaded, the linked preset is applied unless it is already the active one. That way a restored temporary override isn't thrown away on reload.getLinkedPresetinpreset-policy.tsresolves a link and ignores built-in names and presets that no longer exist.Testing
tests/preset-model-link.test.tsruns the real store against the settings HTTP stub. It covers hydrating links (including a removednullone), auto-apply on switch, separate presets per model, unlinked models keeping Default's recommendation, a temporary override not moving the link or the saved preset, a link to a missing preset being ignored, and links and unlinks saved per model.nullvalue is accepted, junk is rejected) and the per-model merge and removal instudio_db, through both the plain merge and compare-and-set.npm run typecheckpasses. The full frontend suite passes (13,950 passed, 11 skipped, 0 failed). ESLint on the touched files reports only issues that were already there.test_chat_history_storage.py,test_chat_history_routes.py,test_min_p_mode_settings.py,test_account_chat_settings.py,test_chat_settings_payload.py,test_media_generation_preset_settings.pyandmulti_account/test_downgrade_sim.pypass.test_search_images.pyfails here only becauseddgsisn't installed on this machine. That is unrelated to this change.Maintainer changes
Reviewing this, linking one model made its preset leak into every other model: after visiting a linked model, an unlinked model you had never opened ran the linked preset's temperature and system prompt, and a model you had opened kept its own values while the picker named the linked preset, so a Save overwrote that preset. The link now applies to the open tab only. It never writes the settings DB, a chat, or a model's remembered settings, so the stored pick stays your own: leaving a linked model, or reloading on one, puts back exactly what you had before.
Tests:
tests/preset-model-link.test.tsgrew to 44 store-level cases, each new one failing on the commit before its fix. Full frontend suite 16053/16053 on the merged branch, backend chat-settings tests 167/167. Studio regression switchboard base vs head: no functional regression; the only visual difference is the new switch row in Run settings.Run settings with a GGUF loaded (gemma-3-270m, CPU): the new switch, on after linking Research.
Preset list: the linked preset is marked "This model".