Skip to content

Studio: recover saved context when switching back to a snapshot path - #10447

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
claxman:fix/10338-switch-back-resident-config
Sep 8, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
claxman:fix/10338-switch-back-resident-config

Conversation

@claxman

@claxman claxman commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Switch Back looks up remembered load settings through resolveInitialConfig (#10338). That misses a repo-keyed record when the thread id is a Hugging Face snapshot path, so the switch loads without the saved context pin.

rememberedConfigFor now uses resolveResidentInitialConfig, the same alias apply-inference-status-to-store.ts already uses for a resident snapshot path.

cd studio/frontend && node --experimental-strip-types --test tests/chat-remembers-its-model.test.ts -> 26 passed. Reverting chat-page.tsx to upstream/main -> 2 failed (tests 23 and 24, the switch-back cases).

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits chat-page.tsx where rememberedConfigFor still calls resolveInitialConfig, so a repo-keyed context pin is dropped when the id is a snapshot path, unlike apply-inference-status-to-store.ts which already uses the resident alias. Will get this reviewed.

The new call sits at 89 columns, past biome's default 80, so running the
repo's own `npm run biome:fix` rewraps it across four lines. Both new tests
assert on the source text of `rememberedConfigFor` and match the single-line
form, so the formatter breaks them.

Wrap the call here and match either form in the tests, the way
llama-extra-args-panel-hydration.test.ts already does. With this the tests
pass whether or not the file has been formatted, and still fail against the
old `resolveInitialConfig` call.
@danielhanchen

Copy link
Copy Markdown
Member

Reviewed and verified end to end. The change is correct, and I pushed one small commit to the branch (details at the bottom).

The fix works, measured rather than read

Two Studio installs, the PR's own merge base (e0f84159e) and its head, driven through the same flow: a Q4_K_M GGUF loaded by path out of the HF cache, a chat started on it, a switch to Q8_0, then reopening the chat and pressing Switch back. A customContextLength of 8192 was saved under the repo id Qwen/Qwen2.5-0.5B-Instruct-GGUF while the chat recorded the snapshot directory, which is exactly the mismatch this PR is about.

before and after

Same model, same chat, same quant on both sides. Only the context differs:

BEFORE (e0f84159e) AFTER (this PR)
POST /api/inference/load max_seq_length 0 8192
/api/inference/status loaded_context_length 32768 8192
header chip 38 / 32.8k 48 / 8.2k

model_path and gguf_variant are byte-identical across the two, so nothing but the pin moved. The run also confirmed the precondition the PR rests on: thread.modelId really is the models--Qwen--...-GGUF/snapshots/<sha> directory, with modelGgufVariant Q4_K_M.

Why the swap is safe

resolveResidentInitialConfig is a strict superset of resolveInitialConfig: a direct hit is returned unchanged, and only a miss retries under publicModelId(...), gated on alias !== modelId && alias.includes("/"). So rememberedConfigFor can only go from null to a config, never to a different one, and the source === "external" early return is untouched.

I ran a matrix over the real module to hold that rather than assert it. 45 cases, all green: 12 snapshot path forms (Linux, macOS, macOS with spaces, Windows drive letter, lowercase drive, UNC, mixed separators, WSL, relative, ~, trailing slash, non-ASCII), storage schema versions 1-5, a future-version record still correctly refused through the alias, the legacy modelId::variant key form, corrupt stores, variant case folding, variant isolation (Q8_0 never adopted for a Q4_K_M ask), and nine ids that must resolve identically under both resolvers. The invariant case sweeps the cross product and asserts that a direct hit is returned byte for byte, that a miss never becomes a different miss, and that some misses do become hits.

Old installs are fine: the diff touches only chat-page.tsx, so neither the storage format nor the id normalisation changes, and a store written by either build reads identically in the other. A record keyed under the snapshot path, which is what an older install would have written, still wins over the repo alias.

Also ran it under Chromium, Firefox and WebKit against a real localStorage, since the newly reached path goes through hfCacheRepoId and its replaceAll. All three returned byte-identical results. Full frontend suite 6974/6974, typecheck and lint clean.

And the test is load-bearing: reverting only the chat-page.tsx hunk while keeping the new tests fails exactly the two switch-back cases.

One thing worth knowing about the reachable flow

The bar is suppressed unless the chat's stored model id is still selectable (chat-model-notice.tsx:85), and a raw snapshot path is only in that set while it is the resident identifier. I measured this: after loading a different model, notice_visible_after_other_model is false on both sides, because the load calls refresh() and the snapshot path drops out of selectableModelIds.

So the local-to-local repro in #10338 does not reach this lookup at all. The flows that do are a variant change on the same resident snapshot (what the screenshots use) and a switch to an external provider, which leaves the local model resident. That does not make the PR wrong, it is a genuine fix on a genuine path, but if @jimster480's repro was local-to-local then the remaining half belongs in selectableModelIds becoming alias-aware, which would be a separate change.

Two smaller notes

shared-composer.tsx:1290 (ensureModelLoaded, compare pane) still uses the literal resolveInitialConfig, and model1 is seeded from the live checkpoint at chat-page.tsx:1062-1067, so it can receive the same snapshot path and drop the pin the same way. Happy for that to be a follow-up rather than grown into this PR.

Separately, and unrelated to this change: the notice renders as "This chat was started on 9217f5db79a29953eb74d5343926648285ec7e67" because compareModelDisplayName takes the last path segment and a snapshot path ends in the revision sha. Visible in the screenshots. Cosmetic, but it looks broken.

What I pushed

One commit, 0fb5c9de3. The new call sat at 89 columns, past biome's default 80, so npm run biome:fix rewrapped it across four lines and broke both new tests, which match on the single-line source text. I confirmed that failure before fixing it. The commit wraps the call and relaxes the two regexes with \s* so they match either form, the way llama-extra-args-panel-hydration.test.ts:282 already does. Tests pass formatted or not, and still fail against the old resolveInitialConfig call. I kept it to those lines rather than formatting the whole file, which would have been a 988-line diff.

# Conflicts:
#	studio/frontend/src/features/chat/chat-page.tsx
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-08T10:12:40.835990Z d1ced96 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.

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: d1ced96de0

ℹ️ 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 added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Re-ran the before/after capture after the merge with main, since both ends of the comparison moved (base is now a37dea7f4, head d1ced96de). Both Studio installs were rebuilt rather than reused, so neither half is a picture of older code.

Same result, so the merge changed nothing about the behaviour:

before and after

BEFORE (a37dea7f4) AFTER (d1ced96de)
POST /api/inference/load max_seq_length 0 8192
/api/inference/status loaded_context_length 32768 8192
header chip 44 / 32.8k 61 / 8.2k

Same model, same quant, same chat on both sides (Qwen2.5-0.5B-Instruct-GGUF, GGUF Q4_K_M), with a customContextLength of 8192 saved under the repo id while the chat records the snapshot directory. model_path and gguf_variant are byte-identical across the pair, so the pin is the only thing that moved.

Cross-platform and browser

Ran the branch through per-OS CI and a live Studio Playwright pass on a staging repo rather than the org queue. On the merged branch: ubuntu-latest green, macos-15 green, and the studio-live Playwright job green (Studio boots, the chat page renders, the seeded token reaches localStorage, streamed text and an image arrive, video is captured). windows-latest was cancelled mid-flight by concurrency.cancel-in-progress when I pushed a fix to the harness, and is re-running now; I will follow up if it says anything different from the other two.

Separately I ran the resolver itself under Chromium, Firefox and WebKit against a real localStorage. All three returned byte-identical results, which matters here because the path this PR newly reaches goes through hfCacheRepoId and its String.prototype.replaceAll.

Merge conflict

The PR had gone CONFLICTING against main after #9886 landed. I resolved it and pushed. It was a single import-block conflict: main added modelConfigHandoffForDestination and kept resolveInitialConfig, whose only use in chat-page.tsx was the exact line this PR replaces, so the resolution keeps both new symbols and drops the now-unused one. Full frontend suite 7041/7041, typecheck and lint clean on the merged tree, and the PR is MERGEABLE again.

@danielhanchen

Copy link
Copy Markdown
Member

Following up on the windows run, and correcting something I said about the Playwright job.

windows-latest is green, so the OS triple is complete on the merged branch: ubuntu-latest, macos-15 and windows-latest all pass.

The correction: I described the studio-live Playwright job as showing that "the chat page renders". That is not what it does. The smoke stands up its own stub HTML page on a local port and drives Playwright against that, while Studio itself runs separately and is only checked for a /healthz response. So the honest scope of that job is: Studio installs and serves, and the browser-driving harness works end to end (localStorage seeding, screenshot, streamed text, a data-URL image, webm plus mp4 capture). It never photographs Studio's own UI, so it is not evidence about this change and I am not posting its screenshot as if it were.

The before/after composite in my previous comment remains the only artifact here that compares base against head, and it stands: max_seq_length 0 to 8192, loaded_context_length 32768 to 8192, chip 44 / 32.8k to 61 / 8.2k, with the model, quant and chat identical on both sides.

@claxman

claxman commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Taking the compare-pane lookup as a separate PR. ensureModelLoaded in shared-composer.tsx still calls resolveInitialConfig, and model1 is seeded from the live checkpoint so sel.id can be a snapshot path.

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