Skip to content

Fix On Device model picker startup ordering - #6994

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
Imagineer99:fix/on-device-startup-flicker
Jul 20, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
Imagineer99:fix/on-device-startup-flicker

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • keep the On Device model picker in its loading state until downloaded/local model scans finish
  • gate Fine-tuned, Custom Folders, LM Studio, and Local models behind the same cachedReady state used for downloaded rows
  • gate keyboard option keys for those lower sections so focus order does not briefly target rows before the final ordering is known

Root cause

On cold startup, downloaded model rows waited for cachedReady, but Fine-tuned and other lower On Device sections rendered immediately. If fine-tuned rows were available before the downloaded scan completed, Fine-tuned appeared as the first visible section, then Downloaded loaded above it and reordered the menu.

Validation

  • npm ci
  • npm run typecheck
  • git diff --check
  • manually verified startup no longer flashes Fine-tuned before Downloaded

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@Imagineer99
Imagineer99 marked this pull request as ready for review July 10, 2026 10:27

@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: 4de4dfbba4

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

) : null}

{showCustom ? (
{showCustom && cachedReady ? (

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 Don't gate cached local folders on download scans

When a user has only custom/LM Studio/local-dir models cached, cachedReady still initializes false because alreadyCached only checks _cachedGgufCache and _cachedModelsCache. This new guard hides the already cached local sections on every picker mount until the unrelated downloaded-model API calls finish, so users briefly lose access to local models/folder controls despite the module-level local caches being populated; the same issue applies to the LM Studio and Local models guards below.

Useful? React with 👍 / 👎.

@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: 830c254c1f

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

@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: 74267e3f84

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

Lyxot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Pushed the picker readiness follow-ups in 74267e3f8 and 80c037e44.

Why this change is needed

The original startup gate waited for the downloaded-model requests but not local discovery. On a cold opening, Fine-tuned or the empty state could therefore render before Custom Folders, LM Studio, and Local Models arrived, causing the picker to reorder after it became interactive.

Combining those requests into one startup snapshot exposed a second race on warm openings: an older startup result could resolve early and remain buffered behind a slower source. If the user deleted a model or changed a custom folder during that interval, the newer interactive refresh could apply first, then be overwritten by the buffered startup result. That could resurrect a deleted row, hide a newly added row, and leave keyboard options out of sync with the actual current inventory.

How it was fixed

  • Cached GGUF, cached model, and local-model discovery now form one bounded startup snapshot, with cancellation on unmount and a 30-second deadline.
  • Each inventory source has an independent request version, so only the newest request for that source may publish. A later deletion or folder refresh invalidates the older startup result without discarding valid results from unrelated sources.
  • Accepted cache publications are shared across mounted or newly mounted picker instances, including monotonic readiness synchronization, so a mutation finishing after its original picker closes still updates the active picker.
  • Rendered sections and keyboard option keys continue to use the same readiness gate, preserving a stable first-visible order while keeping reusable cached results immediately available on later openings.

@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: 80c037e442

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

@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: 8bd0841621

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

@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: 9d0867d029

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

@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: 002a3e5549

ℹ️ 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 +1774 to +1775
bounded(listCachedGguf(controller.signal)),
bounded(listCachedModels(hfToken || undefined, controller.signal)),

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 Preserve slow downloaded-cache scans after timeout

When either downloaded-cache scan takes longer than 30 seconds, passing controller.signal here aborts and permanently discards its eventual result while the picker remains open. Both backend handlers synchronously call _all_hf_cache_scans() (studio/backend/routes/models.py:3117-3121,3168-3178), so large or slow Hugging Face caches can exceed this bound; unlike the retained localRequest, these requests have no late-result path or retry, leaving downloaded GGUF or safetensors rows unavailable until a remount or another explicit refresh.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks — this is accurate, but the 30-second cutoff is intentional here. Publishing a downloaded-cache result after the barrier releases would insert Downloaded / Other rows above already-visible Fine-tuned and local rows, recreating the row reorder and keyboard-focus instability this PR is fixing. Late local results are safe to retain because those sections render below the stable upper groups. If HF cache scans regularly exceed the bound, the smaller root-cause follow-up is to share or cache _all_hf_cache_scans() on the backend rather than publish downloaded rows late. Leaving this unchanged in this PR.

@Lyxot

Lyxot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 002a3e5549

ℹ️ 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
danielhanchen merged commit e092895 into unslothai:main Jul 20, 2026
35 of 36 checks passed
VectorCipher pushed a commit to VectorCipher/unsloth that referenced this pull request Jul 20, 2026
* Fix on-device model picker startup ordering

* Fix on-device picker cached local remounts

* fix(studio): stabilize on-device picker readiness

* fix(studio): prevent stale picker refreshes

* fix(studio): retry incomplete picker scans

* fix(studio): preserve replacement picker readiness

* fix(studio): preserve slow local scans

---------

Co-authored-by: Long Yixing <[email protected]>
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.

3 participants