Skip to content

fix: retry model deletion on Windows when files are locked#53

Open
Bortlesboat wants to merge 1 commit intolightningpixel:mainfrom
Bortlesboat:fix/windows-model-deletion
Open

fix: retry model deletion on Windows when files are locked#53
Bortlesboat wants to merge 1 commit intolightningpixel:mainfrom
Bortlesboat:fix/windows-model-deletion

Conversation

@Bortlesboat
Copy link
Copy Markdown

Summary

  • Await the unload response instead of fire-and-forget, so the Python process actually releases file handles before deletion begins
  • Add a 1.5s delay after successful unload to give Windows time to release lingering file locks
  • Retry rm up to 3 times with incremental backoff (1s, 2s, 3s) when the error is EBUSY or EPERM
  • Return a descriptive error message if all retries are exhausted

Details

On Windows, when a model is loaded into memory by the Python backend, the OS holds file locks on the model directory. The existing model:delete handler fires the unload request without awaiting it, then immediately attempts rm — which fails with EBUSY or EPERM because handles haven't been released yet.

This fix makes the unload blocking (with a 10s timeout) and adds retry logic so transient lock failures are handled gracefully.

Only the model:delete IPC handler in electron/main/ipc-handlers.ts is modified.

Fixes #12

Test plan

  • Load a model, then delete it — should succeed on first try (unload completes, delay lets locks clear)
  • Attempt to delete a model whose files are open in another program — should retry 3 times then return a descriptive error
  • Delete a model that is not currently loaded — should succeed immediately (unload fails gracefully, rm succeeds)
  • Verify on macOS/Linux that behavior is unchanged (no EBUSY/EPERM on those platforms)

🤖 Generated with Claude Code

After unloading a model, Windows may still hold file locks briefly.
Add await on unload response and retry logic with backoff for
EBUSY/EPERM errors during directory removal.

Fixes lightningpixel#12

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Can't delete downloaded models from models tab

1 participant