Conversation
…odels folder model.py bound the models path with `from services.generator_registry import MODELS_DIR`, capturing it at import time. POST /settings/paths rebinds that module global when the models folder is moved in Settings, but /model/hf-download and /model/hf-download-sources kept resolving against the old folder, so a model downloaded afterwards landed in the previous location and still showed as not downloaded. Read registry.MODELS_DIR at call time instead, the same way generation.py reads WORKSPACE_DIR. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
After changing the models folder in Settings → Storage, downloading a model from the Models page writes its weights into the previous folder until the app is restarted. The download reports success, but the model still shows as not downloaded, because the registry and Electron both check the new folder. If the old folder was moved or deleted, the download silently recreates it.
Why it triggers
api/routers/model.pyimported the path by name:POST /settings/paths→GeneratorRegistry.update_paths()rebinds the module global and repoints every generator'smodel_dir, but the router's own copy keeps the import-time value:This is the models-folder counterpart of #287, which fixed the same stale binding for
WORKSPACE_DIRingeneration.py.Fix
Import the module and read
registry.MODELS_DIRat call time, asgeneration.pyand the settings router already do. Inhf_download_sourcesit is read once into a local, so the model root and every source destination come from the same folder.Tests
The existing fixture redirected
model_router.MODELS_DIR, a name that no longer exists after the fix, so it now redirectsregistry.MODELS_DIR. Followingtest_generation_router.py, it also points any stale module copy at the same temp tree. That way a stale read fails an assertion instead of writing into the real models folder.New in
api/tests/test_model_router.py:test_multi_source_download_follows_a_moved_models_folder: fails before, passes after.test_single_repo_download_follows_a_moved_models_folder: fails before, passes after.test_moved_models_folder_still_refuses_a_non_node_model_id: passes before and after. A model id that doesn't name one extension node is still rejected with 400 after the folder moves. That proves reading the live path doesn't loosen the model-root validation, so the change is not a widening.The multi-source test's
events[-1] == {"percent": 100, "status": "done"}assertion also holds before and after. The stale path always reported success, which is why it went unnoticed.Fail-before output, with
api/routers/model.pyreverted and the tests kept. It is verbatim except that the local checkout/temp path prefix is replaced with<repo>/<tmp>, and the registry's import-time path banner that follows it is omitted:After the fix,
python -m unittest tests.test_model_routerpasses all 7 tests (Ran 7 tests in 14.102s/OK).Whole suite,
python -m unittest discover -s testsinapi/(venv withfastapi+python-multipart+httpx):devRan 93 tests/OK (skipped=3)Ran 96 tests/OK (skipped=3)test_model_router.pyThe 3 skips were already there on
dev.Lint: the repo configures no Python linter, and ESLint ignores
api/**. As a spot check,ruff check --isolatedon the two touched files reports 32 findings ondevand the same 32 on this branch, so nothing new. No TypeScript touched.🤖 Generated with Claude Code