fix(dashboard): restore GET /api/models + fs fallbacks for comfy models/types #6

Merged
mikan merged 1 commits from fix/dashboard-ui-visibility into master 2026-10-24 00:35:57 +00:00
Collaborator

Три баги найдены из вывода /api/debug

Юзер сообщил: «в UI ни комфи (причем и типы и модели) ни ллама модели не видны» — хотя /api/debug показывает что директории существуют с файлами.

Баг 1: GET /api/models был удалён

В PR #5 я добавил DELETE /api/models?name=..., но при переписывании файла через Write tool случайно затёр существующий GET /api/models handler. Фронт получал 405 Method Not Allowed, но refreshModels() тихо глотал ошибку (try/catch без логирования).

Fix: восстановил GET handler рядом с DELETE.

Баг 2: refreshComfyModels() никогда не вызывался

Initial useEffect вызывал только refreshConfig, refreshModels, refreshComfyTypes, и interval для refreshComfyQueue. refreshComfyModels был определён как useCallback, но не вызывался при mount — таблица моделей comfy всегда была пустой пока юзер не нажмёт Refresh вручную.

Fix: добавил refreshComfyModels() в initial useEffect.

Баг 3: /api/comfy/types и /api/comfy/models падают когда model-worker offline

Оба endpoint проксировали к docker exec model-worker python3 /app/worker.py — что fails (возвращает empty / error) когда model-worker контейнер не запущен (sleep mode, или сразу после ребута до wake).

/api/debug показал что директории существуют на диске через fs.readdir — данные есть, просто не использовались.

Fix: добавил fs-based fallbacks в dashboard/src/lib/docker.ts:

  • listComfyTypesFromFs() — читает поддиректории /project/gpu/comfy/models напрямую. Аналог worker.py types, но без docker exec.
  • listComfyModelsFromFs(type?) — обходит каждую поддиректорию и листит файлы. Аналог worker.py list --json.
  • listComfyModels() и getComfyTypes() теперь сначала пробуют worker, потом fallback на fs. Если оба работают — worker выигрывает (он фильтрует metadata files типа .txt).
  • Новый export COMFY_MODELS_DIR — внутренний mount path.

Bonus: visibility ошибок

Все refresh*() callbacks теперь console.error на failure. Следующий раз когда что-то сломается — будет видно в browser DevTools console.

Verification

  • npm run build — OK, все 19 роутов (включая восстановленный GET /api/models)
  • bash dashboard/validate-build.sh — все 8 COPY источников ✓, standalone ✓
  • /api/debug всё ещё работает (использует тот же fs подход)

Files changed

  • dashboard/src/app/api/models/route.ts — восстановил GET handler
  • dashboard/src/app/page.tsx — добавил refreshComfyModels() в initial useEffect, console.error на refresh failures
  • dashboard/src/lib/docker.ts — добавил COMFY_MODELS_DIR export, fs-based fallbacks, try-worker-first-then-fs flow

После мержа

git pull && sh build.sh && docker compose up -d --force-recreate dashboard

Если модели всё ещё не видны — открой DevTools console (F12) и посмотри логи [refresh*] — там будет видно что именно падает.

## Три баги найдены из вывода `/api/debug` Юзер сообщил: «в UI ни комфи (причем и типы и модели) ни ллама модели не видны» — хотя `/api/debug` показывает что директории существуют с файлами. ### Баг 1: `GET /api/models` был удалён В PR #5 я добавил `DELETE /api/models?name=...`, но при переписывании файла через Write tool случайно затёр существующий `GET /api/models` handler. Фронт получал 405 Method Not Allowed, но `refreshModels()` тихо глотал ошибку (try/catch без логирования). **Fix:** восстановил GET handler рядом с DELETE. ### Баг 2: `refreshComfyModels()` никогда не вызывался Initial useEffect вызывал только `refreshConfig`, `refreshModels`, `refreshComfyTypes`, и interval для `refreshComfyQueue`. `refreshComfyModels` был определён как useCallback, но не вызывался при mount — таблица моделей comfy всегда была пустой пока юзер не нажмёт Refresh вручную. **Fix:** добавил `refreshComfyModels()` в initial useEffect. ### Баг 3: `/api/comfy/types` и `/api/comfy/models` падают когда model-worker offline Оба endpoint проксировали к `docker exec model-worker python3 /app/worker.py` — что fails (возвращает empty / error) когда model-worker контейнер не запущен (sleep mode, или сразу после ребута до wake). `/api/debug` показал что директории существуют на диске через `fs.readdir` — данные есть, просто не использовались. **Fix:** добавил fs-based fallbacks в `dashboard/src/lib/docker.ts`: - `listComfyTypesFromFs()` — читает поддиректории `/project/gpu/comfy/models` напрямую. Аналог `worker.py types`, но без docker exec. - `listComfyModelsFromFs(type?)` — обходит каждую поддиректорию и листит файлы. Аналог `worker.py list --json`. - `listComfyModels()` и `getComfyTypes()` теперь сначала пробуют worker, потом fallback на fs. Если оба работают — worker выигрывает (он фильтрует metadata files типа `.txt`). - Новый export `COMFY_MODELS_DIR` — внутренний mount path. ### Bonus: visibility ошибок Все `refresh*()` callbacks теперь `console.error` на failure. Следующий раз когда что-то сломается — будет видно в browser DevTools console. ## Verification - `npm run build` — OK, все 19 роутов (включая восстановленный GET /api/models) - `bash dashboard/validate-build.sh` — все 8 COPY источников ✓, standalone ✓ - `/api/debug` всё ещё работает (использует тот же fs подход) ## Files changed - `dashboard/src/app/api/models/route.ts` — восстановил GET handler - `dashboard/src/app/page.tsx` — добавил `refreshComfyModels()` в initial useEffect, `console.error` на refresh failures - `dashboard/src/lib/docker.ts` — добавил `COMFY_MODELS_DIR` export, fs-based fallbacks, try-worker-first-then-fs flow ## После мержа ```sh git pull && sh build.sh && docker compose up -d --force-recreate dashboard ``` Если модели **всё ещё** не видны — открой DevTools console (F12) и посмотри логи `[refresh*]` — там будет видно что именно падает.
super-z-bot added 1 commit 2026-10-24 00:08:35 +00:00
## Three bugs found from /api/debug output

User reported: 'in UI ни комфи (причем и типы и модели) ни ллама модели не
видны' — even though /api/debug shows the directories exist with files in
them.

### Bug 1: GET /api/models was deleted

In PR #5 I added `DELETE /api/models?name=...` but accidentally removed
the existing `GET /api/models` handler when I rewrote the file with the
Write tool. The frontend was getting 405 Method Not Allowed, but
`refreshModels()` silently swallowed the error (try/catch with no logging).

Fix: restore the GET handler alongside DELETE.

### Bug 2: refreshComfyModels() was never called

The initial useEffect only called refreshConfig, refreshModels,
refreshComfyTypes, and an interval for refreshComfyQueue.
refreshComfyModels was defined as a useCallback but never invoked on
mount — so the Comfy models table was always empty until the user
clicked Refresh manually.

Fix: add refreshComfyModels() to the initial useEffect.

### Bug 3: /api/comfy/types and /api/comfy/models fail when model-worker is offline

Both endpoints proxied to `docker exec model-worker python3 /app/worker.py` —
which fails (returns empty / error) when the model-worker container isn't
running (e.g. during sleep mode, or right after a reboot before wake).

The /api/debug endpoint showed that the directories exist on disk via
fs.readdir — so we have the data, just weren't using it.

Fix: add fs-based fallbacks in dashboard/src/lib/docker.ts:

  - `listComfyTypesFromFs()` — reads subdirectories of
    /project/gpu/comfy/models directly. Same as what `worker.py types` does,
    but no docker exec required.

  - `listComfyModelsFromFs(type?)` — walks each subdirectory and lists
    files. Same as what `worker.py list --json` does, but no docker exec.

  - `listComfyModels()` and `getComfyTypes()` now try the worker first,
    then fall back to fs. If both succeed, the worker's output wins (it
    filters out metadata files like .txt).

  - New export `COMFY_MODELS_DIR` — the internal mount path, used by both
    the fallback functions and /api/debug.

### Bonus: error visibility

All `refresh*()` callbacks in page.tsx now `console.error` on failure
instead of silently swallowing. The next time something breaks, you'll see
it in the browser DevTools console.

## Verification

- `npm run build` — OK, all 19 routes (including restored GET /api/models)
- `bash dashboard/validate-build.sh` — all 8 COPY sources ✓, standalone ✓
- /api/debug still works (uses the same fs approach)

## Files changed

- dashboard/src/app/api/models/route.ts — restored GET handler
- dashboard/src/app/page.tsx — added refreshComfyModels() to initial
  useEffect, console.error on refresh failures
- dashboard/src/lib/docker.ts — added COMFY_MODELS_DIR export, fs-based
  fallbacks for comfy types/models, try-worker-first-then-fs flow
mikan merged commit ff180be9b5 into master 2026-10-24 00:35:57 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mikan/GPU-Node#6