Job backend: support job cancellation#19565
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds job cancellation functionality to MLflow's job backend, enabling users to cancel running or pending jobs via API.
Key Changes:
- Added
CANCELEDas a new job status and updated status finalization logic - Implemented
cancel_jobmethod across store interfaces (abstract and SQLAlchemy implementations) - Modified job execution polling to check for cancellation status and kill subprocess when detected
- Exposed cancellation functionality through REST API endpoint (DELETE
/ajax-api/3.0/jobs/{job_id})
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| mlflow/entities/_job_status.py | Added CANCELED status enum value and updated is_finalized() to include it |
| mlflow/store/jobs/abstract_store.py | Added abstract cancel_job method to define the interface |
| mlflow/store/jobs/sqlalchemy_store.py | Implemented cancel_job method and updated _update_job to return Job entity |
| mlflow/server/jobs/utils.py | Modified subprocess execution to poll job status and handle cancellation |
| mlflow/server/jobs/init.py | Exposed cancel_job function as public API |
| mlflow/server/job_api.py | Added DELETE endpoint for job cancellation |
| tests/server/jobs/test_jobs.py | Added integration test for job cancellation functionality |
| tests/server/jobs/test_endpoint.py | Added endpoint test for cancel operation and updated error message validation |
Comments suppressed due to low confidence (1)
mlflow/server/jobs/utils.py:149
- The docstring should be updated to reflect that the function now also handles job cancellation. Currently it only mentions timeout handling, but the function now returns None if the job is canceled as well.
"""
Executes the job function in a subprocess,
If the job execution time exceeds timeout, the subprocess is killed and return None,
otherwise return `JobResult` instance,
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Documentation preview for fd29d40 is available at: More info
|
mlflow/server/job_api.py
Outdated
| ) | ||
|
|
||
|
|
||
| @job_api_router.delete("/{job_id}", response_model=Job) |
There was a problem hiding this comment.
I think DELETE is not appropriate http method for cancellation because we don't actually remove the job record from the DB. Can we use PATCH?
There was a problem hiding this comment.
PATCH sounds like "update" operation, it might confuse user if PATCH /job_id actually cancels the job.
what about @job_api_router.post("/cancel/{job_id}", response_model=Job) to make the endpoint path clear ?
There was a problem hiding this comment.
Yeah it should be sth like PATCH /cancel/{job_id}. POST also sounds fine since the cancellation triggers some side effect. But I don't think delete is accurate because the record is still there with the cancelled state.
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Job backend: support job cancellation
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
Job backend: support job cancellation
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.