Skip to content

Studio: resync model state after a llama.cpp update unloads it - #6998

Merged
oobabooga merged 5 commits into
unslothai:mainfrom
oobabooga:studio-llama-update-model-resync
Jul 13, 2026
Merged

oobabooga merged 5 commits into
unslothai:mainfrom
oobabooga:studio-llama-update-model-resync

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Reported on Discord (Jimster480): if you update llama.cpp from the in-app banner while a model is loaded, the update unloads that model, but the UI keeps showing it as active. Your next chat message then fails with a bare 400. The only way out is to reload the page, which finally shows "select model".

Fix

After an update that unloaded the model, the selector now drops to "select model" on its own, the same way it does when you unload a model yourself. No page refresh, and no failed send. This also covers running the update in another tab.

If you had an external provider model selected (OpenAI, Anthropic, and so on), that selection is left alone, since a llama.cpp update does not affect it.

Verification

Built and ran Studio, confirmed the app loads clean, and confirmed an update genuinely unloads a loaded model. Typecheck, lint, and build are green.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to resynchronize the chat runtime status after a server-side model change (such as a llama.cpp update that unloads the active model). It refactors the model status synchronization logic in use-chat-model-runtime.ts into a module-level function syncInferenceStatusToStore and exposes resyncInferenceStatusAfterServerModelChange to clear local checkpoints and trigger a status refresh. The useLlamaUpdateCheck hook is updated to accept an onReloadRequired callback, which is triggered when an update succeeds and requires a reload, ensuring the UI drops the model selector to "select model" instead of pointing to an unloaded model. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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: 3d4db194c9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +141 to +142
if (s.job.reload_required) {
onReloadRequiredRef.current?.();

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 Handle completed cross-tab updates

When another tab starts and finishes an update between this hook's hourly checks, this block is never reached: surfaceIfAvailable only starts startJobPoll() for job.state === "running", and a later /api/llama/update-status returns the persisted success job with update_available typically false after the install. Because the reload callback only runs here, the tab that missed the running window keeps the stale local checkpoint and still hits the bare 400 the patch is meant to prevent; handle success && reload_required in the surface path as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 45be13c: surfaceIfAvailable now handles job.state==="success" && reload_required (not just "running"), keyed by finished_at so two separate completions a tab only ever sees in the persisted success phase are not conflated.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@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: 45be13c864

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +190 to +194
if (
next.job.state === "success" &&
next.job.reload_required &&
next.job.finished_at !== reloadNotifiedForRef.current
) {

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 Avoid replaying old update completions

Because /api/llama/update-status keeps returning the last success job until another update starts, and reloadNotifiedForRef resets on remount, this branch fires again after a tab/page reload for an already-handled update. If the user has since reloaded a local model or staged a new one before this hook's first/hourly check, the callback calls resyncInferenceStatusAfterServerModelChange(), whose clearCheckpoint() cancels pendingSelection and clears local model state before the fresh status can restore anything. Persist the last handled finished_at or verify the server is actually unloaded before clearing so old successes don't clobber current selections.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ae8e8fe: the handled finished_at is now persisted to localStorage (seeded on mount), not just a component ref, so a fresh mount after this tab (or another tab) already resynced for a completed job no longer replays it.

Comment on lines 86 to +88
useLlamaUpdateCheck({
enabled: enabled && showBannerPref,
onReloadRequired: resyncInferenceStatusAfterServerModelChange,

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 Keep reload resync active when the banner is hidden

This registers the only global reload_required resync through LlamaUpdateBanner, but the same hook is disabled by enabled: enabled && showBannerPref. If a user has turned off the llama update banner (or is on a route that passes enabled=false) while another tab applies an update that unloads the local model, this tab never polls /api/llama/update-status, so the selector remains pointed at the unloaded model and the next local send can still hit the bare 400. Decouple the background reload-required listener from banner visibility, or keep the hook enabled while suppressing only the UI.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ae8e8fe: the hook's enabled no longer includes showBannerPref, only the render-time show is gated on it, so muting the banner keeps the background resync alive and only suppresses the UI.

Comment on lines +151 to +156
if (
s.job.reload_required &&
s.job.finished_at !== reloadNotifiedForRef.current
) {
reloadNotifiedForRef.current = s.job.finished_at;
onReloadRequiredRef.current?.();

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 Handle reloads returned by a stale update click

The reload callback only runs from the polling success path here, so a tab that still shows a stale update banner after another tab already completed the update can miss the resync: clicking Update makes POST /api/llama/update return started: false/up_to_date with the persisted job, but apply() returns an error before starting this poll or inspecting that job. In that window the local selector remains pointed at the model the other tab unloaded until the next scheduled status check, so sending can still hit the 400 this change is trying to prevent; process action.job.reload_required or fetch status before returning from the non-started path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ae8e8fe: the non-started early return in apply() now parses action.job and runs it through the same notifyReloadIfNeeded used by the poll and surface paths before returning the error.

oobabooga pushed a commit to oobabooga/unsloth that referenced this pull request Jul 9, 2026
@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@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: ae8e8fe644

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// a tab that missed the running window entirely (mounted, or only checks
// hourly and misses both the running and just-finished moments) still
// needs to resync here, not just from the poll path above.
notifyReloadIfNeeded(next.job);

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 Resync open tabs promptly after cross-tab updates

When another already-open tab starts and finishes a llama.cpp update after this tab's initial check, this notification path is not reached until the hourly reminder because the hook only starts fast polling if this tab happens to observe running. During that window the store still points at the server-unloaded local model and the next chat send can still hit the bare 400, so the cross-tab case this change intends to cover remains stale for up to an hour. Please add a prompt cross-tab signal or polling path when an update starts/completes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in fb5d0d7: added a storage-event listener (mirroring the pattern already used by use-llama-update-pref.ts) so another open tab is nudged to recheck status immediately when a different tab's update resolves, instead of waiting for the hourly reminder.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

oobabooga pushed a commit to oobabooga/unsloth that referenced this pull request Jul 9, 2026
oobabooga pushed a commit to oobabooga/unsloth that referenced this pull request Jul 9, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: fb5d0d79a5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@oobabooga
oobabooga merged commit 85f5292 into unslothai:main Jul 13, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant