Skip to content

fix: delete a model without stopping the AI server - #3105

Merged
wkentaro merged 5 commits into
mainfrom
fix/remove-model-on-worker
Nov 14, 2026
Merged

wkentaro merged 5 commits into
mainfrom
fix/remove-model-on-worker

Conversation

@wkentaro

@wkentaro wkentaro commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

 _remove_ai_model(model)                       # UI thread
-  osam_worker.release()                       # kills the server; waits up to 10 s on a running request
-  model_manager.remove(model)
+  model_manager.start_removing(model)         # shows "Deleting…", unusable
+  osam_worker.unload(model)                   # queued after the running request
+
+worker thread
+  client.load(model, keep_alive=0)            # server and its other models stay loaded
+  -> unloaded(model) -> model_manager.remove(model)   # deletes the files
  • Requests for the model fail with "AI model removed" until its files are deleted, so nothing reloads it from files about to go.
  • Quitting while a delete waits deletes the files at once.
  • release, the worker's lock and its request-id bookkeeping are gone: only the worker thread touches its client now.
  • A delete error reaches the models dialog through ModelManager.remove_failed.

Evidence

  • Before: deleting a model during AI inference froze the window until the server stopped, and every other loaded model loaded again.
    After: test_unload_waits_for_the_running_request_and_keeps_the_server checks that the unload waits for the running request, fails queued and new requests for the model, and keeps the same client. test_shutdown_deletes_a_model_waiting_on_the_running_request and the deleting state check in test_existing_files_count_as_downloaded_until_deleted cover the other two cases.
  • The full suite passes (2573 passed, 11 skipped), lint is clean, and the catalogs are up to date.

Merge Danger

Door: two-way

Blast Radius: small

It touches model deletion and the AI worker's shutdown.

Codex review, three rounds, all fixed:

  • A request could reload the model between unload and delete. Requests for it now fail until the delete finishes.
  • Quitting during a pending delete lost it. Quitting now deletes the files at once.
  • A model with a pending delete could be selected. It now shows as Deleting….

Known limits:

  • On Windows, quitting during a pending delete can fail, because the server may still hold the files open. The error then shows.
  • Choosing the model from a picker's download list while its delete is pending does nothing.
  • No screenshots: "Deleting…" shows only while a delete waits on a running request.

Deleting a model stopped the AI worker's server on the UI thread so it
would let go of the model's files. With a request running, that froze
the window for up to 10 s, and every other loaded model had to load
again.

The worker now unloads the model on its own thread, after the running
request, and the files are deleted once it reports back. The server
and its other models stay loaded. With release gone, only the worker
thread touches its client, so the lock and the request-id bookkeeping
that guarded it go too. A delete error now reaches the models dialog
through ModelManager.remove_failed.
The worker unloads a model, then the UI deletes its files. A request
made in between could load the model again from files about to go.
Requests for the model now fail until the files are deleted.
A delete waiting on a running request relied on the worker thread's
report, which comes after the app quits, so the files stayed. Quitting
now deletes them at once; the thread's late report deletes nothing.
While a delete waited on a running request, the model still counted
as downloaded, so it could be selected again and then fail. It now
shows as Deleting… and cannot be selected or downloaded until its
files are deleted.
@wkentaro

Copy link
Copy Markdown
Owner Author

This was generated by AI (gpt-6.1-sol) during PR review.

recommend-merge

  • Meaningful: main stops the entire AI server during deletion, blocking the UI and unloading unrelated models.
  • Worth adding: keeping deletion responsive justifies the limited worker and model-state changes.
  • Right approach: the worker thread owns its client and queues unloading after inference; deletion waits for its completion signal.
  • Correct: no verified defects found. All 32 focused worker, manager, and model-management tests passed. The deletion tests exercise behavior absent on the base branch.
  • Minimal: the changes cover deletion, pending requests, shutdown, error reporting, and the translated deleting state.

Windows locked-file behavior was not verified; the PR documents possible deletion failure during shutdown.

@wkentaro wkentaro added the recommend-merge pr: Agent finalized and endorses it: review and merge label Nov 14, 2026
@wkentaro
wkentaro merged commit 9e61ae9 into main Nov 14, 2026
22 checks passed
@wkentaro
wkentaro deleted the fix/remove-model-on-worker branch November 14, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

recommend-merge pr: Agent finalized and endorses it: review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant