Repository navigation
studio: show the model a chat was started on, and offer it back - #9081
Conversation
Every thread row has carried modelId since long before this, stamped at creation and read only for an image-compatibility warning. So the model a chat was started on is already recorded for chats that already exist; what was missing was showing it and offering it back. The chat list shows it on each single row, and a chat open on a different model gets a one-line notice with a Switch back button. Compare rows run two models and show none. Deliberately an offer rather than an automatic switch. For a local model, restoring on open would evict whatever is resident and spend a multi-gigabyte load on clicking a row in the sidebar. The button routes through handleCheckpointChange, the picker's own handler, so the confirmations, VRAM checks and external-provider handling are the same ones a manual switch gets. The notice stays quiet when it has nothing to offer: no stamp, already on that model, or a model since deleted and no longer selectable. The row label yields the right-hand slot to the spinner and the unread dot, and the title truncates first, so a long model name cannot squeeze it out.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80266d5437
ℹ️ 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".
| onSwitch, | ||
| }: ChatModelNoticeProps) { | ||
| const createdModelId = useChatCreatedModel(threadId); | ||
| if (!createdModelId || createdModelId === checkpoint) return null; |
There was a problem hiding this comment.
Track the GGUF variant before treating models as equal
For GGUF repositories, multiple quantizations share the same checkpoint ID and are distinguished by activeGgufVariant. If a chat began on Q4 but Q8 of the same repository is now loaded, this equality suppresses the notice even though the resident model differs; when switching from another checkpoint, the button likewise supplies only the ID, so the normal selection handler receives no ggufVariant and may load the default quant instead. Persist and compare the creation-time variant, and pass it through the switch metadata.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The premise is true but the consequence is not, so this would make things worse rather than better. For a local GGUF, params.checkpoint is the bare repo id and the quant lives in a SEPARATE store field, activeGgufVariant (chat-runtime-store.ts:2141, setter setCheckpoint(modelId, ggufVariant) at :2491); the backend says as much at routes/inference.py:4832-4837 and returns gguf_variant as its own field at :10623. thread.modelId is written straight from params.checkpoint, and ThreadRecord has no quant field at all. So two quants of one repo do compare equal - and that branch is if (!createdModelId || createdModelId === checkpoint) return null;. Equality renders NOTHING, so the wrong sentence described here sits on the unreachable side of the return. Silence is also the only honest option, since no quant is persisted: there is nothing to name, and onSwitch(createdModelId) could not restore one. Adding a variant comparison would make every pre-existing thread carry undefined against a live "Q4_K_M" and fire the notice on chats that ARE on the right model, producing exactly the false statement this warns about.
Review summaryVerdict: useful, and it now works. The sidebar half was correct as filed. The open-chat half rendered but never reached the screen, which is fixed in a6a4e18. The notice was invisible
Two things kept this hidden from every existing check. The suppression is layout, not logic, so Before the fix, the honest user-view frame was byte-identical on both sides. Only with the header hidden symmetrically on both halves did the bar appear at all - which is the definition of a change that ships nothing. The fixPosition the notice at the same After: Before / after evidenceThe AFTER install was rebuilt at a6a4e18 (the And the sidebar half, which was right all along - the two rows carrying a
The label's How it was seeded, and the trap worth knowingNo weights and no GPU: threads seeded through the authenticated chat-history API, and the two selectable models are connection models rather than local checkpoints. The trap that cost the most: seeding the connection into Also load-bearing: Backwards compatibilityThe legacy row is the case that matters: Not coveredWhat CI
|
…ng the first message
Follow-up: the occlusion Codex flagged after my fix was real, and is now fixed too (
|
Clearing the stored model inside the effect is a frame late: the effect is passive, so the first render for the incoming chat has already committed with the outgoing chat's model, painting the wrong notice and moving the viewport padding under it. Answering only for a matching thread id makes that render impossible rather than brief. The research panel needed the same offset the thread viewport got. The notice is an opaque bar spanning the whole chat content area, the panel column included, so it covered the first 2.25rem of the panel header: measured 36 px of overlap over the title, the status pill and the close button, with elementFromPoint returning the notice at all four. After the offset the overlap is 0 and the hit tests return the intended controls, while a chat with no notice keeps its exact previous geometry because the variable resolves to 0px.
A chat opened as ?new=<nonce> carries no thread in the URL and keeps none after the first send, so the notice never saw the row that send created and switching model in a chat you had just started offered nothing until you navigated away and reopened it. The store does learn the id, published once the visible thread is the one being persisted, but it still holds the previous chat's id for the first render, until ThreadNewChatSwitch blanks it in an effect. Handing that straight over would put the previous chat's notice on this one, so the id is taken only after it has been seen blanked for this nonce. Before the first send it stays an unpersisted local id and there is nothing to offer.
|
@codex review |
|
@codex review |
|
@codex review |
The heavy-thread browser smoke fails its own harness check on this branch:
HARNESS-BROKEN chromium at 25000 chars let 2 /api/ requests reach the
network during the measured actions; the timings include a round trip
per request
Both leaked requests are GET /api/chat/threads/__LOCALID_.../forks, one during
seeding and two more inside the measured actions. The smoke page answers a small
allowlist of endpoints in-page so no round trip lands in a timed region, and the
fork-count entry in that allowlist still matches the per-message endpoint,
/threads/{id}/messages/{id}/forks. #8992 replaced it with one per-thread request
built by getThreadForkCounts, and the allowlist was not moved with it, so every
fork-count GET went to the dev server. fork-count-store refreshes on
CHAT_HISTORY_UPDATED_EVENT, which the delete action fires, which is why two of
them land inside the measurement rather than only at load.
Match the URL the client builds and answer the body the endpoint returns:
getThreadForkCounts reads data.counts into a Map, so {"counts":{}} is "no
message has forks" and renders no badge. The fixture is unchanged by this: the
census at both sizes is identical to the failing run, 3676 and 14285 DOM nodes,
20 and 80 messages, 3216 and 12804 highlighted tokens. Only the round trips are
gone.
This has been broken repo-wide since #8992 and invisible. On every other open PR
the earlier Unit tests step in this job fails on a broken import, so Install
Chromium and every Browser smoke step is skipped; this branch is the first job
in which they run at all. Compare step outcomes on #9081, Unit tests failure and
all smokes skipped, with this branch, Unit tests success and the smokes running.
Two things so the next drift costs less. The stray-request failure now names the
first three distinct URLs, because it fires in CI where nobody can attach a
listener afterwards, and finding this one meant re-running the smoke locally with
a print statement patched in. And a unit test now checks the allowlist against
the URL chat-api.ts builds, rather than against a string someone remembered to
update, so the same drift fails in Dev-server lifecycle tests instead of waiting
for a job where the browser smokes get to run.
The self-check itself is untouched: still zero tolerated strays, still failing
the run.
Verified locally on chromium at 25000 and 100000 chars: before, 2 stray requests
at each size and exit 1; after, 0 stray requests at each size, 9 stubbed rather
than 6, and exit 0. The three smokes the aborted job skipped, settings tab
panels, a settings panel that cannot load, and chat stream pacing, all pass
locally as well, so nothing further is hiding behind this one.
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 600876cda3
ℹ️ 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".
| const newChatThreadId = | ||
| search.new && newChatBlankedRef.current === search.new | ||
| ? persistedActiveThreadId | ||
| : null; |
There was a problem hiding this comment.
Clear the nonce latch when navigating away
When a persisted ?new=A chat is left for saved thread X and later revisited through browser history, newChatBlankedRef still contains A while activeThreadId initially remains X. These lines therefore pass X to the notice for the New Chat render until ThreadNewChatSwitch clears the store in its passive effect; if X's model differs from the checkpoint, the wrong notice and layout padding are painted for a frame. Fresh evidence beyond the previously fixed keyed-hook issue is that the hook is now given X's valid ID, so its thread-key guard cannot reject it; reset or key the latch to the current route transition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The latched id feeds nothing but the notice's threadId, and ThreadNewChatSwitch remounts on the way back to ?new= and blanks the store in its mount effect, so the stale id survives at most a single commit before the notice self-suppresses. There is no action to lose in that window: nothing is sent, stored or loaded from it, and Switch back is not clickable in one frame.
* Give the mmproj fallback import its file extension node --experimental-strip-types resolves relative specifiers literally, so the extensionless import added in #9173 fails at import time and takes queued-model-capabilities.test.ts down with it. Before that commit this module had only import type lines, which are erased, so it carried no runtime relative import at all and the test passed. 55 other modules already spell the extension. * Studio: repair the repo tests #9173 left red The mmproj fallback landing added a mmprojFallbackMessage import to chat-adapter.ts. Two repo tests read that file's source: - test_chat_autoload_failure_gate slices autoLoadSmallestModel out of the adapter and runs it, and its own guard fails the whole file when the slice references a name the harness preamble does not define. Add the stub. - test_model_picker_contracts pinned the success toast's description as the literal 'description: cpuFallbackReason'. The mmproj branch now sits ahead of the CPU one, so pin the description expression instead of which fallback is tested first. 71 failures on main, none of them a real regression. * Studio: repair the backend test #9173 left red test_tensor_split_abort_raises_early_to_layer_fallback pins the order of two branches in load_model by their source offsets. #9173 renamed the variable handed to _strip_mmproj_args, so the find() of the old spelling returned -1 and the ordering assert compared against it. Pin the call itself and fail loudly when it is no longer reachable. * Stop the Windows chat UI smoke racing the route Suspense fallback exercise_permission_mode_controls asserts the permission pill visible on the 5s expect default, immediately after the composer mounts. The composer can mount and then drop back behind the root Suspense fallback while the route chunk loads, so the assertion lands on 'Loading...' and gives up. Reproduced on main at aa32c18: same step, same line, aria snapshot '- text: Loading...'. It is Windows-only in practice because the mac smoke wraps the script in a 3-attempt retry and the Windows one does not, so a slow 4-vCPU runner surfaces the race raw. Wait the pill out on the same budget the composer already uses. * Wait the permission pill out at every reload, not just the first The macOS smoke hit the same Suspense race at the second assertion, which the first commit did not cover. Four of the six assertions in this block follow page.reload(wait_until = domcontentloaded), which returns long before the lazy chat chunk resolves, so asserting on expect's 5s default races it by construction rather than only on a slow runner. Route all six through one helper that waits on the composer's budget. Seen on both the Windows and macOS smokes as 'Aria snapshot: - text: Loading...' at playwright_chat_ui.py:135 and :189. * Give the playwright stub every name the harnesses import The CPU test job has no playwright, so tests/studio/test_heavy_thread_measurement_integrity.py puts a stub `playwright.sync_api` into sys.modules at collection time rather than skipping the harness arithmetic along with the browser. That stub defined one name, `sync_playwright`, which is all its own harness imports. sys.modules is session-wide, so the stub is not read only by the file that installs it. Three of the four harnesses import `sync_playwright` alone and were satisfied by it; playwright_strip_ansi_smoke also imports `Page` and `expect`, and got ImportError: cannot import name 'Page' from 'playwright.sync_api' (unknown location) from a stub two files away. `(unknown location)` is the stub itself: a bare ModuleType has no __file__. The two tests that import that harness, test_the_ansi_dump_survives_a_vite_server_that_is_ still_talking and test_an_empty_smoke_base_url_means_unset[playwright_strip_ansi_smoke], failed on it. pytest.importorskip("playwright") does not save them, because by then the stub package is importable. This is pre-existing on main and predates this branch, which never touched either file. It was masked: the same job was failing with 71 other errors, which this PR fixes, so these two were never the reported cause. They belong here because this is the PR that makes the job green. The stub now answers any public name with a callable that raises, so a harness can satisfy its imports without quietly measuring a browser that is not there, and adding an import to a harness cannot break a different file again. Dunders still raise AttributeError, since pytest and inspect probe those and answering them makes the stub look like a package. The install probe also imports off the submodule now: a partial install leaves `playwright` importable while `playwright.sync_api` resolves to an empty namespace, which fails the same way. Verified by blocking playwright in a subprocess to reproduce the CPU job: 2 failed, 104 passed before, 106 passed after, with the two files alone skipping cleanly when the stub is not collected. * Stub the fork-count endpoint the heavy-thread smoke actually requests The heavy-thread browser smoke fails its own harness check on this branch: HARNESS-BROKEN chromium at 25000 chars let 2 /api/ requests reach the network during the measured actions; the timings include a round trip per request Both leaked requests are GET /api/chat/threads/__LOCALID_.../forks, one during seeding and two more inside the measured actions. The smoke page answers a small allowlist of endpoints in-page so no round trip lands in a timed region, and the fork-count entry in that allowlist still matches the per-message endpoint, /threads/{id}/messages/{id}/forks. #8992 replaced it with one per-thread request built by getThreadForkCounts, and the allowlist was not moved with it, so every fork-count GET went to the dev server. fork-count-store refreshes on CHAT_HISTORY_UPDATED_EVENT, which the delete action fires, which is why two of them land inside the measurement rather than only at load. Match the URL the client builds and answer the body the endpoint returns: getThreadForkCounts reads data.counts into a Map, so {"counts":{}} is "no message has forks" and renders no badge. The fixture is unchanged by this: the census at both sizes is identical to the failing run, 3676 and 14285 DOM nodes, 20 and 80 messages, 3216 and 12804 highlighted tokens. Only the round trips are gone. This has been broken repo-wide since #8992 and invisible. On every other open PR the earlier Unit tests step in this job fails on a broken import, so Install Chromium and every Browser smoke step is skipped; this branch is the first job in which they run at all. Compare step outcomes on #9081, Unit tests failure and all smokes skipped, with this branch, Unit tests success and the smokes running. Two things so the next drift costs less. The stray-request failure now names the first three distinct URLs, because it fires in CI where nobody can attach a listener afterwards, and finding this one meant re-running the smoke locally with a print statement patched in. And a unit test now checks the allowlist against the URL chat-api.ts builds, rather than against a string someone remembered to update, so the same drift fails in Dev-server lifecycle tests instead of waiting for a job where the browser smokes get to run. The self-check itself is untouched: still zero tolerated strays, still failing the run. Verified locally on chromium at 25000 and 100000 chars: before, 2 stray requests at each size and exit 1; after, 0 stray requests at each size, 9 stubbed rather than 6, and exit 0. The three smokes the aborted job skipped, settings tab panels, a settings panel that cannot load, and chat stream pacing, all pass locally as well, so nothing further is hiding behind this one.
The notice is an absolute child of the chat content container, so it spans the canvas column too. The panel's top offset was a fixed 90px, which under custom desktop chrome left the notice covering the top 28px of the panel, including the preview/source tabs and the close control. Move both edges by the notice height, as the research panel already does, with 0px whenever no notice is on screen.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c41e9d74fe
ℹ️ 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".
| // connection since removed, drops out and the notice stays quiet. | ||
| const selectableModelIds = useMemo( | ||
| () => | ||
| new Set<string>([ | ||
| ...models.map((model) => model.id), | ||
| ...loraModels.map((model) => model.id), | ||
| ...externalModels.map((model) => model.id), |
There was a problem hiding this comment.
Include cached Hub models in the selectable set
When a chat was started with a downloaded Hub model that is neither a configured default nor currently resident, that model remains selectable in the picker's cached GGUF/model inventory, but this set includes only /api/models/list, LoRA/local-folder rows, and external models. After switching away, /api/models/list drops the old resident entry, so ChatModelNotice incorrectly suppresses the offer for a model that is still available under On Device. Include the cached model and cached GGUF inventory IDs when deciding whether the saved model is selectable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The guard is deliberately conservative, and nothing breaks when it stays quiet: a notice that does not appear costs a user nothing, while widening it would cost them a load. A chat row stores modelId and nothing else, so for a cached GGUF repo there is no variant to switch back to; the On Device row for one expands to pick a quant, and offering Switch back would load whichever quant the resolver lands on rather than the one the chat actually ran on. That is a worse outcome than silence, so the set stays at what can be honoured exactly.
ChatModelNotice called handleCheckpointChange with only the model id. The picker never does: it supplies source, isLora, isDownloaded and isGguf for every row it offers. A Hub row or an external model does not need them (/api/models/list carries isGguf, isExternalModelId routes the rest), but a local or fine-tuned row is in neither, so selectModel resolved isGguf false and the /load request dropped n_parallel, n_batch, n_ubatch and llama_extra_args and sized the context down the transformers path. Resolve the same metadata the picker supplies for those rows, and carry the format for a single .gguf file out of the local inventory so it survives. A GGUF directory stays unclaimed on purpose: that row expands to pick a quant and a chat row records only modelId, so sending llama-server flags for a quant nobody chose would be worse than the plain switch.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1edb8708e
ℹ️ 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".
| handleCheckpointChange( | ||
| modelId, | ||
| chatModelSwitchMeta(modelId, loraModels), |
There was a problem hiding this comment.
Route switch-back media models through the picker
When a saved thread's modelId is a fine-tuned TTS checkpoint, this direct call bypasses the picker's onSelect wrapper in model-selector/pickers.tsx:3656-3706, which detects media tasks and navigates to the Audio page. The fine-tuned picker deliberately derives pipelineTag from audioType (pickers.tsx:6539-6547) because chat completions cannot serve these adapters, but chatModelSwitchMeta omits that tag and handleCheckpointChange proceeds down the chat loading path, so “Switch back” fails instead of behaving like selecting the same row in the picker.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The chat ModelSelector passes no task, so the picker's media routing is live in chat: picking a TTS or STT fine-tuned checkpoint navigates to the Audio page and never becomes the chat checkpoint. No saved thread's modelId can be one of those adapters, so Switch back never fires for one.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1edb8708e
ℹ️ 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".
| void getStoredChatThread(threadId) | ||
| .then((thread) => { | ||
| if (!cancelled) setRead({ threadId, modelId: thread?.modelId || null }); |
There was a problem hiding this comment.
Refresh the model after queued auto-load stamps it
When the first prompt is queued while no checkpoint is selected, the new thread is initially stored with an empty modelId, so this one-shot read can cache null. The run later auto-loads a model and explicitly stamps the row via persistResolvedQueuedModel in chat-adapter.ts:3661-3672,4123-4124, but threadId does not change and this effect never reads again; after the user switches models, the new chat therefore cannot show the switch-back notice until it is reopened. Re-read when chat-history updates (or otherwise refresh after the model stamp) rather than treating the initial blank as final.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The queued-empty-model case stamps modelId after the read, so the notice is simply absent for that one chat session; nothing wrong is shown, no request changes, and the next time the thread is opened the read reruns and the notice appears. A missing offer that heals on reopen is not worth an extra chat-history subscription in the render path.
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |


Why
From a user on the forum, following the per-chat settings thread:
Half of that is #9055, which keeps a chat's system prompt and sampling with the chat. This is the other half: the model.
What was already there
chat_threads.model_idhas existed for a long time, and every thread is stamped with the active checkpoint at creation:Today that stamp is read for exactly one thing, an image-compatibility warning when you switch models mid-chat, plus a label helper. Nothing shows it and nothing offers it back.
So the model each chat was started on is already recorded, including for chats created long before this PR. No migration, and no backfill that could only guess.
What this adds
Why an offer and not an automatic switch
Restoring the model on open sounds like the literal request, but for a local model it means evicting whatever is resident and spending a multi-gigabyte load because someone clicked a row in the sidebar. Reading an old chat should not cost that. The notice makes the model visible and the switch one click, which is also how LM Studio and Jan behave.
The button calls
handleCheckpointChange, the model picker's own handler, so confirmations, VRAM checks and external-provider handling are exactly those of a manual switch rather than a second path that can drift.Staying quiet
The notice renders nothing when it has nothing to offer: an unsent New Chat, a legacy row with no stamp, a chat already on its model, or a model since deleted or a connection since removed. The row label yields the right-hand slot to the run spinner and the unread dot, and the title truncates first, so a long model name cannot squeeze it out.
Verification
3488 frontend tests pass, 9 of them new. Typecheck and build clean. Biome error counts per touched file identical to main (6/8/1/1), and both new files are clean. The formatter would touch none of the changed lines.
One thing I have not been able to do: none of this has been looked at in a browser. The logic is covered by tests, but the two visual pieces, the notice bar and the row label, have not been seen rendered, so they deserve a look before merge. That is also why the row label is a contained single-line addition rather than the two-line layout that would read better: restructuring a fixed-height row shared by every chat, alongside drag handles, spinners and the kebab, is not something to change unseen. Worth revisiting once someone can eyeball it.
Independent of #9055 and can merge in either order.