Skip to content

fix: check model file existence against disk, not the scan cache#28

Open
Buckeyes1995 wants to merge 1 commit into
andersondanieln:developfrom
Buckeyes1995:fix/missing-file-existence
Open

fix: check model file existence against disk, not the scan cache#28
Buckeyes1995 wants to merge 1 commit into
andersondanieln:developfrom
Buckeyes1995:fix/missing-file-existence

Conversation

@Buckeyes1995

@Buckeyes1995 Buckeyes1995 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #15.

Summary

ModelCard was using the cached list-models scan to decide whether a template's modelPath exists. The cache only covers MODELS_DIR and registered externalModelFolders, so files picked via the Browse button from any other directory were always flagged "Missing File" — even when on disk and runnable.

Switches the existence check to an explicit fs.existsSync via a new file-exists IPC. Keeps the cache lookup as a fast optimistic path, so the IPC round-trip only fires for paths the scan didn't see.

Reproduction (before this PR)

  1. Create / edit a template
  2. Click Browse next to Model File
  3. Pick a .gguf outside models/ and outside any registered external folder
  4. Save → card shows "Missing File", Start is disabled

After

The file is correctly reported as present. The Start button enables. ModelCard.tsx:14 no longer over-rejects.

Implementation

File Change
src/main/ipc.ts New file-exists handler returning a plain boolean from existsSync(path).
src/preload/index.ts + src/renderer/src/env.d.ts Expose window.api.fileExists.
src/renderer/src/components/ModelCard.tsx Replace the cache-only check with a useEffect-driven disk check. Cache hit is the optimistic fast path; only paths missing from the cache trigger the IPC. null while in-flight is treated as "exists" so cards don't flicker into the missing state between renders.

Test plan

  • npm run build passes; zero new tsc errors vs develop baseline.
  • Template pointing at a file inside MODELS_DIR → not missing (uses cache fast path).
  • Template pointing at a file under a registered external folder → not missing (cache fast path).
  • Template pointing at an arbitrary directory via Browse → not missing (disk fallback).
  • Template pointing at a path that doesn't exist → correctly flagged "Missing File", Start disabled.

ModelCard's "Missing File" indicator and the start-button disable used
`models.some(m => m.path === card.template.modelPath)` to decide whether
the model exists. That cache only contains files under MODELS_DIR and
the registered externalModelFolders. Templates whose modelPath was set
via the Browse picker to an arbitrary path (sibling directory, outside
any registered folder) were always flagged as missing — even when the
file was present on disk and llama-server would have started fine.

Replace the cache lookup with an explicit fs.existsSync via a new
`file-exists` IPC. Keep the cache hit as a fast optimistic path so most
cards skip the IPC round-trip entirely; only modelPaths not in the cache
trigger the disk check.

- src/main/ipc.ts: new `file-exists` handler returning a plain boolean.
- src/preload/index.ts + env.d.ts: surface `window.api.fileExists`.
- src/renderer/src/components/ModelCard.tsx: useEffect-driven disk check
  with optimistic in-cache fast path. Returns to `null` (treated as
  exists) while the IPC is in flight so the card doesn't flicker.

Reported by an issue against the existing logic at ModelCard.tsx:14.
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