Skip to content

feat job cancellation#759

Open
Felipedino wants to merge 2 commits into
developfrom
feat/cancel-job
Open

feat job cancellation#759
Felipedino wants to merge 2 commits into
developfrom
feat/cancel-job

Conversation

@Felipedino

Copy link
Copy Markdown
Collaborator

This pull request introduces robust job cancellation and atomic file handling to prevent data corruption during job interruptions. It adds new atomic write utilities, improves backend job cancellation logic, and ensures that partially-written files and directories are properly cleaned up if a job is cancelled. The UI is also updated to distinguish between cancelling and deleting jobs.

Backend improvements:

  • Added an atomic.py module with context managers (atomic_open, atomic_directory, atomic_save_path) for atomic file and directory writes, ensuring outputs are not left in a corrupt state if a process is killed mid-write.
  • Updated dataset, model, and explainer job code to use atomic write helpers when saving files and directories, protecting against partial writes on cancellation. [1] [2] [3] [4] [5]
  • Implemented a cancel method in BaseJobQueue and updated API endpoints to support cancelling both queued and running jobs, with improved logic to ensure jobs are properly terminated and resources released. [1] [2] [3]
  • Added on_cancel hooks to jobs, especially DatasetJob, to clean up any temporary directories, partially-written datasets, and database records if a job is cancelled before completion. [1] [2] [3]

Job isolation and worker management:

  • Introduced ISOLATED and RESETS_WORKER flags to BaseJob and set them in jobs where necessary, allowing certain jobs to run inline without subprocess isolation or to trigger worker restarts when needed. [1] [2] [3]

Frontend and localization:

  • Updated the job queue widget to show "Cancel job" or "Delete job" depending on job status, and added corresponding translations. [1] [2] [3]

These changes make job management more robust, prevent data corruption, and provide clearer UI feedback when cancelling or deleting jobs.

…ion, and improve job management

- Added atomic file and directory write helpers in `atomic.py` to ensure safe writes and prevent data corruption during job cancellations.
- Refactored `save_dataset` in `dashai_dataset.py` to utilize atomic directory operations for saving datasets.
- Introduced a `cancel` method in `BaseJobQueue` to handle job cancellations, including both queued and running jobs.
- Enhanced `HueyJobQueue` to support job cancellation and added a watchdog to detect crashed worker subprocesses.
- Updated `BaseJob` to include `on_cancel` method for cleanup after job cancellation.
- Implemented cleanup logic in `DatasetJob` to remove partially written artifacts upon cancellation.
- Modified various job classes to support atomic operations for saving files.
- Updated front-end components and translations to reflect new job cancellation functionality.
Copilot AI review requested due to automatic review settings July 8, 2026 20:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves job cancellation semantics across the stack and adds “atomic write” helpers intended to prevent partially-written artifacts when jobs are interrupted. It extends the Huey-backed queue to support cancelling queued/running jobs, adds cancellation cleanup hooks for jobs that write to disk/DB, and updates the UI/i18n to distinguish cancel vs delete.

Changes:

  • Added atomic file/directory write helpers and adopted them in dataset/model/explainer persistence paths.
  • Implemented job cancellation in the backend queue + API (including worker PID tracking and a watchdog for crashed workers).
  • Updated the job queue UI and translations to show “Cancel job” for running jobs vs “Delete job” for terminal jobs.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
DashAI/back/core/atomic.py New atomic write utilities for files/dirs/paths used to reduce corruption on interruption.
DashAI/back/dependencies/job_queues/base_job_queue.py Adds cancel() to the queue interface.
DashAI/back/dependencies/job_queues/huey_job_queue.py Implements cancellation for queued/running jobs, persistent worker management, PID tracking, watchdog, and status guards.
DashAI/back/api/api_v1/endpoints/jobs.py Updates endpoints to cancel (not delete) jobs, including async handling for cancellation.
DashAI/back/job/base_job.py Adds ISOLATED/RESETS_WORKER flags and an on_cancel() hook for cleanup.
DashAI/back/job/dataset_job.py Adds cancellation cleanup to remove partial artifacts + early persistence of file_path for cleanup.
DashAI/back/job/model_job.py Uses atomic save path when persisting model runs.
DashAI/back/job/explainer_job.py Uses atomic file writes for explanation artifacts.
DashAI/back/job/pipeline_job.py Marks PipelineJob as non-isolated due to non-serializable args/async run.
DashAI/back/job/sync_components_job.py Marks job non-isolated and forces worker reset due to registry mutation.
DashAI/back/dataloaders/classes/dashai_dataset.py Writes datasets via atomic directory swap to avoid partial dataset directories.
DashAI/front/src/components/jobs/JobQueueWidget.jsx UI now labels the action as cancel vs delete depending on job status.
DashAI/front/src/utils/i18n/locales/en/common.json Adds cancelJob translation key.
DashAI/front/src/utils/i18n/locales/de/common.json Adds cancelJob translation key.
DashAI/front/src/utils/i18n/locales/es/common.json Adds cancelJob translation key.
DashAI/front/src/utils/i18n/locales/pt/common.json Adds cancelJob translation key.
DashAI/front/src/utils/i18n/locales/zh/common.json Adds cancelJob translation key.
Comments suppressed due to low confidence (1)

DashAI/front/src/components/jobs/JobQueueWidget.jsx:577

  • This button now represents either “Cancel job” (for started) or “Delete job” (for other non-deleted statuses), but aria-label is always "delete". Screen readers will announce the wrong action for running jobs. Make the aria-label conditional to match the tooltip text.
                                <IconButton
                                  edge="end"
                                  aria-label="delete"
                                  size="small"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DashAI/back/core/atomic.py Outdated
Comment thread DashAI/back/job/explainer_job.py Outdated
Comment thread DashAI/back/api/api_v1/endpoints/jobs.py
@Irozuku Irozuku changed the base branch from production to develop July 8, 2026 20:52
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.

2 participants