Skip to content

Job backend: support job cancellation#19565

Merged
WeichenXu123 merged 9 commits intomlflow:masterfrom
WeichenXu123:job-backend-cancellation
Dec 24, 2025
Merged

Job backend: support job cancellation#19565
WeichenXu123 merged 9 commits intomlflow:masterfrom
WeichenXu123:job-backend-cancellation

Conversation

@WeichenXu123
Copy link
Collaborator

@WeichenXu123 WeichenXu123 commented Dec 22, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19565/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19565/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/19565/merge

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

Job backend: support job cancellation

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

Job backend: support job cancellation

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How 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" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

Yes should be selected for bug fixes, documentation updates, and other small changes. No should 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?
  • Minor release: a release that increments the second part of the version number (e.g., 1.2.0 -> 1.3.0).
    Bug fixes, doc updates and new features usually go into minor releases.
  • Patch release: a release that increments the third part of the version number (e.g., 1.2.0 -> 1.2.1).
    Bug fixes and doc updates usually go into patch releases.
  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
@WeichenXu123 WeichenXu123 requested review from B-Step62, BenWilson2 and Copilot and removed request for BenWilson2 and Copilot December 22, 2025 13:19
@github-actions github-actions bot added area/evaluation MLflow Evaluation area/prompts MLflow Prompt Registry and Optimization area/tracing MLflow Tracing and its integrations rn/feature Mention under Features in Changelogs. labels Dec 22, 2025
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CANCELED as a new job status and updated status finalization logic
  • Implemented cancel_job method 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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Documentation preview for fd29d40 is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
Copy link
Collaborator

@B-Step62 B-Step62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review feedback

Copy link
Collaborator

@B-Step62 B-Step62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by claude

)


@job_api_router.delete("/{job_id}", response_model=Job)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

@WeichenXu123 WeichenXu123 Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Collaborator

@B-Step62 B-Step62 Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Collaborator

@B-Step62 B-Step62 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Signed-off-by: Weichen Xu <weichen.xu@databricks.com>
@WeichenXu123 WeichenXu123 added this pull request to the merge queue Dec 24, 2025
Merged via the queue into mlflow:master with commit 226a005 Dec 24, 2025
47 checks passed
@WeichenXu123 WeichenXu123 deleted the job-backend-cancellation branch December 24, 2025 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/evaluation MLflow Evaluation area/prompts MLflow Prompt Registry and Optimization area/tracing MLflow Tracing and its integrations rn/feature Mention under Features in Changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants