Skip to content

fix(studio): share Run settings draft across sidebar and model picker - #10851

Merged
danielhanchen merged 16 commits into
unslothai:mainfrom
Souravrajvi0:feat/shared-run-settings-draft-cf2c
Sep 14, 2026
Merged

danielhanchen merged 16 commits into
unslothai:mainfrom
Souravrajvi0:feat/shared-run-settings-draft-cf2c

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a per-model in-memory draft store so the sidebar and model-dropdown ModelConfigPage hosts edit the same Run settings state. Re-seeds from loadedConfigSignature when the resident process changes.

Split per review:

Also addressed Codex: setModelConfigDraftRemember no longer overwrites savedRemember on checkbox toggle; contract test updated for draft priming.

Fixes #10817

Test plan

  • node --test studio/frontend/tests/model-config-draft.test.ts
  • pytest tests/studio/test_model_picker_contracts.py::test_the_sidebar_settings_editor_reseeds_when_the_live_config_lands
  • node --test studio/frontend/tests/server-tuning-upgrade-downgrade-compat.test.ts

Before / after

Two isolated Studio installs, one at this PR's merge base b3dfd08 and one at head cef2b6e1, both with the same standalone GGUF resident. KV Cache Dtype is set to q8_0 in the Run settings sidebar on the right, and the model dropdown's Run settings page is then opened over the same model without being touched.

Run settings sidebar and model dropdown page, before and after

Left half of each side is the dropdown's page, right half is the sidebar.

dropdown page sidebar estimate agrees
before f16, 5.81 GiB q8_0, 3.79 GiB no
after q8_0, 3.79 GiB q8_0, 3.79 GiB yes

The memory estimate is a second, independent readout of the same split: the two panels were pricing different configurations for one model. Before, the dropdown page also has Reload model greyed out, because as far as that panel knows nothing has changed.

Two differences in the frames are not this PR's doing: the empty-thread greeting is randomised per page load, and the after side carries a "little VRAM is free right now" notice, which is a live reading of a shared GPU.

Cross-platform

Run off the org queue on a staging repo, all green: ubuntu-latest, macos-15 (Apple Silicon), windows-latest, plus a studio-live Playwright pass.

Nothing this PR touches is persisted, so there is no migration for an existing install: the draft key lives only in an in-memory Map for the life of the tab. Cross-OS correctness comes from routing that key through the same normalizeModelIdentity the settings storage key already uses, so a model spelled with Windows separators, a drive letter in either case, a trailing separator, a UNC path or a WSL mount folds to one draft. Nothing here needs more than Map, Set, JSON.stringify and useSyncExternalStore, so there is no browser-specific surface.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the two hosts still seed independent drafts on main at model-config-page.tsx:1803 and that use-active-model-config.ts never populates llamaExtraArgs, so both halves of this are real. The direction is right, but could you split the llamaExtraArgs baseline change and the instance-key removal into their own PRs so the shared draft store lands on its own?

Add a per-model in-memory draft store so sidebar and dropdown ModelConfigPage
hosts stay in sync, re-seeding from loadedConfigSignature when the resident
process changes. Keeps modelConfigInstanceKey remount behavior; editor-key
and llamaExtraArgs baseline changes are split to follow-up PRs.

Fixes unslothai#10817
@Souravrajvi0

Copy link
Copy Markdown
Contributor Author

@danielhanchen Split as requested: this PR is draft-store only (#10851). Follow-ups are #10869 (editor instance-key removal) and #10870 (loaded llamaExtraArgs in useActiveModelConfig). Unrelated Studio llama-server logging is not on this branch. Codex P1/P2 on remember baseline and contract tests are fixed on the latest push.

danielhanchen and others added 3 commits September 14, 2026 01:20
…'s lifetime

Follow-ups on the shared draft store, found by running the two hosts against the real
module under React and by the three contract tests this branch had left pointing at the
old spellings.

Draft key. draftStorageKey joined the raw id and quant, but the settings the draft stands
for are stored under modelStorageKey, which normalizes. A Windows path spelled with either
separator, a drive letter in either case, a trailing separator and a repo id in another
case all reach one settings row, and the sidebar and the picker do not spell a model the
same way: the sidebar keys off inferenceParams.checkpoint as /status echoes it back, the
picker off the row's advertised id. Those cases handed the two panels separate drafts for
the model they are both showing, which is the bug this branch is fixing. The key now goes
through normalizeModelIdentity and normalizeGgufVariantIdentity, and a JSON pair replaces
the `${id}:${variant}` join, which folded "repo:quant with no variant" together with "repo
at variant quant" -- ollama ids carry a colon. Nothing persists this key, so there is
nothing to migrate.

Draft lifetime. The Map had no eviction, so a draft outlived every editor showing it: a
value typed into the dropdown and never applied came back as the model's settings the next
time the panel opened, and a row saved elsewhere in the meantime was never read. An
unmounted useState used to do that job. Editors now retain the draft while mounted and the
last one out discards it, along with the hydration mark, so the sidebar still keeps the
draft alive while the dropdown opens and closes over it.

The retain is a LAYOUT effect, above the priming one, because both hosts key this component
on loadedConfigSignature: every live config change deletes the instance and mounts a new one
under the same draft key in one commit. A deleted fiber's layout cleanup runs in the mutation
phase, before the incoming instance's layout effects. Released passively it ran after, so it
deleted the draft the new instance had just seeded and the panel stopped taking edits at all
until the next model change -- and only in production, since StrictMode's replayed layout
effects re-primed it in development.

Server-override read. resetExtraArgsHydrationForDraft ran on every editor mount, so opening
the dropdown re-ran the read and wrote the stored row back over what the sidebar was showing:
the configRef.current === configAtStart guard only covers edits made after the request went
out. The mark now lives as long as the draft, so the read happens once per draft, and the
effect's dependency list goes back to what it was.

Priming dependencies. loadedConfig, initialConfig and gpuDevices are object identities that
change on every status poll, and priming only acts on the key or the signature, so listing
them re-read localStorage on every render for a call that was already a no-op.

Tests: re-pointed llama-extra-args-diagnostics, llama-extra-args-panel-hydration and the
model-picker contract test at the new spellings; added key-identity, lifetime and
double-release cases to model-config-draft.test.ts.
Opening comment-reduction pass: 68 added comment lines down to 26, comments only.
Each survivor names an invariant or the mistake it prevents; restatements and the
narration of how the layout-effect ordering was found are gone.
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 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 ✅ Completed 2026-09-14T09:08:40.956190Z cef2b6e Manual request
🔒 Security Review ✅ Completed 2026-09-14T01:57:41.967067Z f3b476d Manual request
ℹ️ 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

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: f3b476d02c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Reset passes setConfig a plain object, and DEFAULT_PER_MODEL_CONFIG names no GPU
field at all, so merging it could not clear a manual placement: the GPU rows kept
the pick and the next Run still used it. Every other caller passes an updater, so
restoring the useState contract for a non-function action touches nothing else.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

commit publishes parsed tokens on every keystroke, valid or not, and the verdict
was held per row. With both editors mounted an unclosed quote therefore disabled
Run in the editor being typed into while the other re-quoted the same tokens into
balanced text, judged them loadable and kept its Run button live, so a click there
launched the half-typed line. The text now lives on the shared draft, keyed by the
same draft key, so both rows hold the same characters and reach the same verdict.

An edit stands until something outside the box replaces llamaExtraArgs, which is
what Reset and the panel's hydration do; the edit records what it published so
that replacement is still told apart from the echo of the user's own typing.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The mark is keyed per draft now, but the identity string it holds was a raw join of
loadId, configId and modelOverrideKey, none of which normalize. The two hosts spell
one model differently, so they share a draft key and still produce different marks:
opening the second editor re-read the server row and replaceModelConfigDraft wrote
it back over a field the first had already edited, which the in-flight guard does
not cover because nothing changed during the request.

Only the mark is normalized. `keys` still travels to the backend as spelled, since
its resolver owns the folding for a real lookup.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

The two Run settings editors reach one model through differently shaped
candidate lists: the picker carries the load-path candidates while the
sidebar, built from inferenceParams.checkpoint, carries only the
checkpoint. Normalizing each candidate does not make lists of different
shapes equal, so the second editor still missed the mark, started another
override read, and restored server values over an unsaved edit that was
already in configAtStart when the request went out.

Nothing reachable within one draft key changes what that read returns, so
the draft key is the whole identity. The mark is now a set of hydrated
draft keys, released with the draft.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
The sidebar host stays mounted for the whole of a model's residency, so a
hydration mark kept for the life of the retained draft meant the read
never ran again. A tab could not notice settings another origin saved,
and Run with Remember on mirrored its stale copy back over them through
syncModelOverride.

Retaining the draft now retires the mark, so opening the other editor
re-reads the row. Never over an unsaved edit: by the time a second read
returns, that edit is already in the config the request compared itself
against, so the before/after guard reads as untouched. Edits are marked
where the user makes them, and the mark is retired by a save, a re-seed
from the resident process, or a replacement.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Two gaps in the edited mark the previous commit introduced.

Unticking Remember is a pending Forget, but it went through a setter the
save path also calls, so it was left unmarked. The next editor's read
captured the already-changed value, its own guard therefore passed, and
replaceModelConfigDraft re-ticked the box. Marked at the checkbox rather
than in the setter, which the save path calls again to settle the box.

And the mark was cleared whether or not the write landed. A blocked or
full localStorage leaves the unsaved values on screen, so a later read
could replace them with the older stored row.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19415959a7

ℹ️ 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".

Comment on lines +2906 to +2908
if (!saveFailed) {
// What the draft holds is now what is stored, so a later read may apply a newer row again.
clearModelConfigDraftEdited(draftKey);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Delay clearing dirty state until server sync finishes

When local storage succeeds but syncModelOverride's asynchronous server PUT fails or is still pending, this clears the draft's edited marker immediately. Opening the other editor then causes retainModelConfigDraft to invalidate hydration; the subsequent GET can return the stale server row, pass the !isModelConfigDraftEdited(draftKey) guard, and persist that row over the user's newly saved local settings. Keep the marker until the server mirror succeeds, or otherwise prevent a stale server response from superseding the newer local save.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The analysis is right, but this is pre-existing on the merge base rather than something this PR introduces, so I am leaving it out of scope here.

On b3dfd08 the same adopt path runs with the same two guards, and it persists the server row over local storage the same way:

if (resolvedRow && serverConfig &&
    configRef.current === configAtStart &&
    rememberRef.current === rememberAtStart) { ... savePerModelConfig(configId, target.ggufVariant, rememberedConfig, hydrationEvicted) ... }

and the base keys hydration on a per-instance useRef, so the picker's editor re-reads on every open already. A local save followed by a failed mirror is therefore overwritten by the next open on the base too. The edited marker this PR adds is a new guard on top of that path; clearing it after a save returns to base behaviour and does not enable anything the base did not already do.

Fixing it properly means syncModelOverride reporting whether the mirror landed. It returns void today and swallows its own promise, and it has other callers, so that is a contract change and belongs in its own PR rather than this one, which is the first of a three-way split.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

Thanks for splitting it, this branch is now the shared draft store on its own, and main still has the per-instance const [initial] = useState(resolveInitial) at model-config-page.tsx:1803 that lets the sidebar and the dropdown page price different configs for one model. Will get this reviewed.

The shared raw edit stood or fell on whether its tokens still formatted
to the current value, and token equality cannot tell an A to B to A round
trip from never having changed. A noncanonical edit discarded by Reset, a
hydration or a re-seed stayed in the map, and the next external value
that happened to format to the same tokens made it current again,
restoring the old text along with the verdict it carried, which could
leave Run disabled over something the user never typed.

The edit is now dropped wherever the config is replaced from outside the
box, so the token comparison is a safety net rather than the whole
mechanism.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 3 commits September 14, 2026 08:10
Run read the config from its render closure. The peer editor's focused
numeric input commits on blur during that same click, straight into the
shared draft, and each editor's imperative commit refs only reach its own
inputs, so a context, GPU layer or MoE layer value typed in one surface
was shown but not launched. Run now reads the draft.

And the panel consumed only a shared refusal. An editor keeps its own
refusal after its row unmounts, by design, so once the peer corrected the
text the first editor stayed disabled over something that was already
fine. A matching positive verdict now lifts it.
Comments only, no code change: 162 added comment lines down to 90.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: cef2b6e1fd

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@danielhanchen
danielhanchen merged commit 03af220 into unslothai:main Sep 14, 2026
27 of 35 checks passed
Souravrajvi0 added a commit to Souravrajvi0/unsloth that referenced this pull request Sep 16, 2026
Keep modelConfigEditorKey on the shared draft storage key; export both
editor and draft keys from the model-picker barrel. Contract tests assert
draft priming and stable editor keys together.
Souravrajvi0 added a commit to Souravrajvi0/unsloth that referenced this pull request Sep 17, 2026
Stop including loadedConfig in ModelConfigPage React keys. Pair with the
shared draft store in unslothai#10851 for live config sync via loadedConfigSignature.
bestoffersdirect-fork-sync Bot pushed a commit to BestOffersDirect/unsloth that referenced this pull request Oct 19, 2026
…ll settings (unslothai#14210)

Fixes unslothai#8039

## Summary

When another tab, or an API auto-switch, reloads the MLX model that is
already resident with a different KV cache width or Int8 Prefill
setting, this tab kept the old width, the old baseline and the old
verdict. The status poll only seeded the MLX group on a model change,
plus a recovery branch that needs every field still empty, so once the
group held values a same-model reload was ignored. The editor then
showed the old width, its verdict badge described a load that is no
longer running, and the next Apply re-sent the old width, undoing the
other client's change.

The rest of the per-model load settings group already handles this on
`main`: `kvCacheDtype`, `tensorParallel`, `specDraftNMax`,
`speculativeType` and `chatTemplateOverride` advance their loaded
baseline on every settled status and move the control only while it
still sits on that baseline (unslothai#10627, `resolveChatTemplateSeed`). The
shared Run settings draft (unslothai#10851), the matching editor keys in the
sidebar and the model picker, and the `syncGeneration` fence on status
reads cover the other parts the issue listed.

This PR puts the MLX group on that same rule and drops the separate
recovery branch it no longer needs:

- `loadedMlxKvQuantRequested`, `loadedMlxInt8PrefillRequested` and the
verdict fields (`mlxKvQuantReason`, `mlxKvQuantNote`,
`chatTemplateOverrideReason`) follow every settled MLX status.
- `mlxKvQuant` and `mlxInt8Prefill` follow while they equal their
baseline, or on a model change. A value staged in this tab is kept, and
its baseline still advances.
- A non-MLX status still retires the verdict and leaves the width
dormant.

## Test plan

- [x] `node --experimental-strip-types --test
tests/same-model-reload-load-settings.test.ts`: on the merge base the
two MLX same-model reload cases fail (`'8' !== '4'`, `'8' !== null`);
with this change all 5 pass. The GGUF case passes on both and pins the
existing behaviour.
- [x] Full frontend suite (`npm test`): 12681 tests, 0 failures.
- [x] `tsc -p tsconfig.app.json --noEmit` clean.
- [x] `pytest tests/studio/test_model_picker_contracts.py
tests/studio/test_chat_autoload_failure_gate.py
tests/studio/test_cli_attach_load_knobs.py`: 355 passed.

## Before / after

Two isolated Studio installs, one at this PR's merge base `a33463f` and
one at head `927c1a4`. This host has no MLX, so the page is given the
status an MLX backend reports for a resident model loaded at 8-bit KV,
on a Mac. The status then switches to the same model reloaded at 4-bit
by another client, and the window regains focus, which is when Studio
re-reads status.

Before, Run settings still shows 8-bit and the 8-bit verdict over a
model now running at 4-bit, so Reload would put it back to 8-bit. After,
it shows 4-bit and the 4-bit verdict.

![Run settings KV Cache Dtype after a same-model MLX reload, before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14210/pr14210_kv_width_panel-51f5fb4c0358.png)

On real Apple Silicon (staging `macos-15`), a tiny MLX model was loaded
twice through Studio's MLX backend at 8-bit and then 4-bit; feeding the
two statuses it reported through the merge base leaves the control on 8,
and through this PR moves control and baseline to 4.
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.

[Bug] Unsloth Studio / Desktop: the Run settings sidebar and the model dropdown's Run settings page keep separate drafts and silently disagree

2 participants