Skip to content

Fix cached models missing from chat picker - #7680

Closed
ousamabenyounes wants to merge 1 commit into
unslothai:mainfrom
ousamabenyounes:fix/issue-7676
Closed

ousamabenyounes wants to merge 1 commit into
unslothai:mainfrom
ousamabenyounes:fix/issue-7676

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Summary

  • include usable Hugging Face cache-only models in the chat model picker
  • preserve active repository IDs and inactive snapshot load paths
  • deduplicate only complete cache entries with the same repository and model format
  • make projected local models searchable through the existing local sections

Validation

  • RED → GREEN: removing hf_cache projection fails with the reported model absent; restoring it passes.
  • RED → GREEN: repository-only dedup removes the GGUF fallback beside cached Safetensors; repository-plus-format keeps it.
  • RED → GREEN: untrimmed repository IDs leak a duplicate; normalized IDs deduplicate it.
  • npm test (77/77 passing)
  • npm run typecheck
  • npm run build
  • ESLint and Biome checks for all changed files
  • 100% statements, branches, functions, and lines for the new inventory projector
  • Chromium verification of search, inactive load-path preservation, and duplicate suppression

Full local suite: passed.

Closes #7676

@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and resolved the conflicts in pickers.tsx and
use-chat-picker-inventory.ts.

The conflict mattered: main had since hardened the local-model filter with a
diffusion-task exemption (canChat || studioPageForTask(row.task)) and an
allowedHiddenModelIds bypass. This rework keeps that filter verbatim and
only layers the fix on top:

  • add hf_cache to PICKER_LOCAL_SOURCES;
  • drop an hf_cache row only when the same repo+format is already surfaced as a
    complete cached model (isHfCacheDuplicate, keyed on repoId\nmodelFormat;
    partial / live-downloading cached rows are intentionally excluded so the cache
    copy stays visible until the download finishes);
  • project hf_cache rows under the models_dir source. This is required, not
    cosmetic: the picker buckets localModels by source into exactly
    lmstudio / models_dir / custom (pickers.tsx), so an entry left as
    hf_cache would match no bucket and stay invisible — the very bug this fixes.

The reusable matching/dedup logic moved into a pure, unit-tested module
(chat-picker-inventory-sources.ts).

Verification (local):

  • chat-picker-inventory-sources.test.ts: 5/5 pass; mutation-checked (breaking
    the format in the dedup key fails a case, so the test is not vacuous).
  • full frontend test suite: 2707/2707 pass (no regression).
  • tsc typecheck: clean.
  • eslint: 0 new errors vs the main baseline (pre-existing pickers.tsx
    warnings unchanged).
  • Not run in this environment: a real browser pass on the picker screen.

@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: 71b482bb14

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

return (
row.source === LOCAL_MODEL_SOURCE.HF_CACHE &&
row.repoId !== null &&
completeCachedKeys.has(inventoryKey(row.repoId, row.modelFormat))

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 Normalize non-GGUF cache rows before deduplicating

When a complete Diffusers/video repository is returned by both inventory endpoints, its cached row is classified as safetensors, while _scan_hf_cache reports the non-GGUF local twin as unknown. Requiring the formats to match therefore retains both rows; the task exemption in useChatPickerInventory then admits the unknown local row, so the Images/Video picker displays the same snapshot once as cached and again under Local models. Normalize this HF-cache format before comparison, or otherwise treat this known unknown/safetensors pair as a duplicate while preserving genuinely distinct GGUF copies.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits use-chat-picker-inventory.ts where PICKER_LOCAL_SOURCES still omits hf_cache, so a cache-only repo never reaches the local lists, and the rebase kept the canChat and hidden-id filter intact. Will get this reviewed.

@danielhanchen

Copy link
Copy Markdown
Member

Re-checked against current main, where PICKER_LOCAL_SOURCES in use-chat-picker-inventory.ts still lists lmstudio, models_dir, ollama, hermes and custom with no hf_cache, so the gap you describe is still there. Could you rebase once more so the new hermes source is carried through, and I will get this reviewed.

@VTplus

VTplus commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Cross-linking a small complementary backend change that keeps a scan-folder copy stored in HF-cache layout classified as custom: #12258. Your frontend change remains the visibility fix for genuine cache rows.

@danielhanchen danielhanchen self-assigned this Oct 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thank you for the PR and for keeping it rebased. Closing this as superseded: the bug behind #7676 is already fixed on main, and the reporter confirmed it on the issue before it was closed.

Root cause: a Hugging Face cache repo whose refs/main pointed at a commit with no snapshots/<commit>/ directory made scan_cache_dir raise CorruptedCacheException. That dropped the repo from /api/hub/cached-models and /api/hub/cached-gguf, while /api/hub/local still listed it as an hf_cache row. The Hub showed the model as on device, and the chat picker, which takes cache models from the cached endpoints, did not. #7375 (merged Aug 1) prunes those dangling refs, so the cached endpoints list the repo again.

I checked this against the backend inventory services directly, using a tiny safetensors repo and a tiny GGUF repo in an isolated cache:

Tree Cache state Cached endpoints hf_cache local rows Missing from picker
before #7375 healthy 2 2 0
before #7375 dangling refs/main 0 2 2
this PR's merge base healthy / legacy cache / dangling ref 2 2 0
current main healthy / legacy cache / dangling ref 2 2 0

On current main, every complete chat-capable hf_cache row already has a cached twin. So adding hf_cache to PICKER_LOCAL_SOURCES would not surface any new model. It would only add a second path for the same weights (relabelled as models_dir) and the dedup logic that comes with it. The picker leaves hf_cache local rows out on purpose because the cached rows already cover them. The remaining variant (a scan folder holding a copy in HF-cache layout) is handled on the backend by #12258, without changing the picker.

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] Local model not being displayed in list of local models, but can be loaded through Search Hub

3 participants