docs/features/orphaned_model_removal.md
This feature adds a UI for synchronizing the models directory by finding and removing orphaned model files. Orphaned models are directories that contain model files but are not referenced in the InvokeAI database.
OrphanedModelsServiceinvokeai/app/services/orphaned_models/find_orphaned_models(): Scans the models directory and database to find orphaned modelsdelete_orphaned_models(paths): Safely deletes specified orphaned model directoriesAdded to invokeai/app/api/routers/model_manager.py:
GET /api/v2/models/sync/orphaned: Returns list of orphaned models with metadataDELETE /api/v2/models/sync/orphaned: Deletes selected orphaned modelsOrphanedModelInfo: Contains path, absolute_path, files list, and size_bytesDeleteOrphanedModelsRequest: Contains list of paths to deleteDeleteOrphanedModelsResponse: Contains deleted paths and errorsSyncModelsButton.tsx
colorScheme="error" for visual prominenceSyncModelsDialog.tsx
useGetOrphanedModelsQuery and useDeleteOrphanedModelsMutation hooks to services/api/endpoints/models.tsAdded to public/locales/en.json:
The system treats model paths as directories:
model-id/file.safetensors, the entire model-id/ directory belongs to that modelTest with orphaned models:
Test with no orphaned models:
Test partial selection:
Test error scenarios:
invokeai/app/services/orphaned_models/__init__.py (new)invokeai/app/services/orphaned_models/orphaned_models_service.py (new)invokeai/app/api/routers/model_manager.py (modified)invokeai/frontend/web/src/services/api/endpoints/models.ts (modified)invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManager.tsx (modified)invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManagerPanel/SyncModelsButton.tsx (new)invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManagerPanel/SyncModelsDialog.tsx (new)invokeai/frontend/web/public/locales/en.json (modified)Potential improvements for future versions: