Skip to content

feat: cancel an Ollama model download and uninstall models - #754

Open
jansans04 wants to merge 4 commits into
developmentfrom
753-cancel-download-uninstall-models
Open

jansans04 wants to merge 4 commits into
developmentfrom
753-cancel-download-uninstall-models

Conversation

@jansans04

Copy link
Copy Markdown
Member

Cancel an Ollama model download and uninstall models

Backend for #753.

Why

  • A pull cannot be stopped once it starts. A model can be several GB, and the only way out is closing the app.
  • An installed model cannot be removed from the app. The only way is ollama rm inside the container.

What changed

  • Cancelling a pull: when the client closes the pull request, the backend closes its HTTP response to Ollama. No success line is sent and the catalog refresh does not run. Closing the stream before it is iterated also closes the connection, which was left open before.
  • Active pulls are tracked in a set protected by a lock, so a model that is being downloaded cannot be deleted.
  • DELETE /api/v1/system/llm/models takes a JSON body {"model": "...", "provider": "ollama"} (provider is optional and defaults to ollama). The name goes in the body because it can contain / or :. It checks the name, the provider, the OLLAMA_MODELS restrictions and that the model is installed. It refuses the global default model, Ollama's default model and a model with an active pull. On success it refreshes the Ollama catalog cache and returns {"model": "...", "deleted": true}.
  • Errors: 422 for an invalid name, a provider other than Ollama, Ollama being off or a model outside OLLAMA_MODELS; 404 LLM_MODEL_NOT_INSTALLED; 409 LLM_MODEL_IN_USE; 503 LLM_UNAVAILABLE if Ollama cannot be reached or fails; 502 LLM_BAD_RESPONSE for an unexpected answer.
  • OllamaLLM.delete_model() calls Ollama's DELETE /api/delete. Everything stays Ollama specific, so other providers and registry.resolve() are unchanged.
  • Contracts and docs/multi-llm-support/ updated.

Notes

  • The tracking of active pulls is per process. With several workers (GUNICORN_WORKERS) the check for a download in progress is best effort.
  • Cancelling means closing the HTTP request to POST /system/llm/pull. After cancelling, Ollama kept the partial download and a new pull resumed from where it stopped.
  • The frontend (Cancel button and delete action in Settings) is in fireform-frontend.

Testing

  • python -m pytest: 431 passed (413 before). Ruff passes on the modified files.
  • The new tests use simulated responses and cover cancelling, the Ollama errors and the success, validation, 404 and 409 cases.

Closes #753

@jansans04 jansans04 changed the title feat: Cancel an Ollama model download and uninstall models feat: cancel an Ollama model download and uninstall models Oct 31, 2026

This branch has not been deployed

No deployments
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.

[FEAT]: Cancel a model download and uninstall Ollama models

1 participant