Skip to content

Fix crash when a job's tasks all end up canceled - #262

Open
NumericalAdvantage wants to merge 2 commits into
mainfrom
fix/job-all-tasks-canceled
Open

Fix crash when a job's tasks all end up canceled#262
NumericalAdvantage wants to merge 2 commits into
mainfrom
fix/job-all-tasks-canceled

Conversation

@NumericalAdvantage

@NumericalAdvantage NumericalAdvantage commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Mirrors openradx/adit#387 — RADIS has the identical bug.

Bug: update_job_state() derives a finished job's status from success/warning/failure tasks. A job whose tasks are all canceled matches no branch and hits raise AssertionError. Reproduced on current main.

Fix: a canceled branch, placed last so it only applies when no success, warning or failure task exists.

Also: a job with one succeeded + one canceled task reported "All tasks succeeded." — untrue, and for an analysis job misleading. The existing "Some tasks ..." wording is now used whenever canceled tasks are present. Statuses are unchanged; only messages.

Note: removes test_job_update_job_state_with_only_canceled_tasks, added in #147, which asserted the crash was correct behaviour (pytest.raises(AssertionError)). The scenario is now covered with the expected outcome instead. Worth knowing the crash was observable in the suite since Nov 2025.

Tests: 4 added (all-canceled; canceled must not mask a failure; and the two message cases). Full suite: 621 passed, ruff + pyright clean.

⚠️ Overlaps #256, which edits the same function (top and save). Whichever lands first, the other needs a rebase.

Summary by CodeRabbit

  • New Features

    • Added canceled as a terminal status for jobs and tasks.
    • Job results now accurately reflect canceled tasks, including mixed outcomes and jobs where all tasks are canceled.
  • Bug Fixes

    • Improved status and message reporting when cancellations occur alongside successes, warnings, or failures.
  • Tests

    • Added coverage for canceled-task scenarios and mixed job outcomes.

update_job_state() derived a finished job's status from success, warning and
failure tasks only. A job whose tasks are all CANCELED matched no branch and
fell through to the AssertionError, so cancelling every task of a job crashed
instead of leaving the job canceled.

Add a canceled branch as the last case, so it only applies when no success,
warning or failure task is present.

Also stop reporting "All tasks ..." when some tasks were canceled: a job with
one succeeded and one canceled task claimed "All tasks succeeded.", which is
untrue. The existing "Some tasks ..." wording is now used whenever canceled
tasks are present.

Removes test_job_update_job_state_with_only_canceled_tasks, which asserted the
crash was correct behaviour; the scenario is now covered with the expected
outcome instead.

This mirrors the same fix for ADIT (openradx/adit#387).
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The job status flow now supports CANCELED. AnalysisJob.update_job_state handles canceled tasks in mixed and all-canceled outcomes. Tests cover status, messages, timestamps, and failure precedence. Documentation lists CANCELED as a terminal outcome.

Changes

Canceled job state handling

Layer / File(s) Summary
Canceled task aggregation and validation
radis/core/models.py, radis/core/tests/test_models.py, AGENTS.md
update_job_state evaluates canceled tasks, assigns CANCELED when all tasks are canceled, preserves failure precedence, and reports mixed outcomes. Tests cover these states, and the documented terminal statuses include CANCELED.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • openradx/radis#256: Both PRs modify AnalysisJob.update_job_state and its tests for CANCELED outcomes, with different handling for aggregation and concurrent cancellation races.

Suggested reviewers: medihack, mhumzaarain

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing a crash when all tasks in a job are canceled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/job-all-tasks-canceled

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NumericalAdvantage
NumericalAdvantage marked this pull request as ready for review August 4, 2026 09:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@AGENTS.md`:
- Line 71: Update the status flow documentation in AGENTS.md to show that
CANCELED may follow CANCELING and may result when a job has no remaining tasks
or only canceled tasks, rather than implying it only follows IN_PROGRESS.
Preserve the existing transitions and clearly separate these cancellation
outcomes while maintaining the document’s current structure.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a1d32ac-3048-4e66-9b99-fa17cb822ee2

📥 Commits

Reviewing files that changed from the base of the PR and between 28b474e and afde0f2.

📒 Files selected for processing (3)
  • AGENTS.md
  • radis/core/models.py
  • radis/core/tests/test_models.py

Comment thread AGENTS.md

- An **AnalysisJob** contains multiple **AnalysisTasks**
- Status flow: `UNVERIFIED` -> `PREPARING` -> `PENDING` -> `IN_PROGRESS` -> `SUCCESS`/`WARNING`/`FAILURE`
- Status flow: `UNVERIFIED` -> `PREPARING` -> `PENDING` -> `IN_PROGRESS` -> `SUCCESS`/`WARNING`/`FAILURE`/`CANCELED`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document the cancellation paths accurately.

CANCELED can follow CANCELING. It can also result when a job has no remaining tasks or only canceled tasks. The linear flow in Line 71 implies that CANCELED only follows IN_PROGRESS.

Proposed documentation update
- Status flow: `UNVERIFIED` -> `PREPARING` -> `PENDING` -> `IN_PROGRESS` -> `SUCCESS`/`WARNING`/`FAILURE`/`CANCELED`
+ Completion flow: `UNVERIFIED` -> `PREPARING` -> `PENDING` -> `IN_PROGRESS` -> `SUCCESS`/`WARNING`/`FAILURE`
+ Cancellation outcome: `CANCELING`, jobs with no tasks, and jobs with only canceled tasks become `CANCELED`.

As per coding guidelines, “Maintain clear structure of agent descriptions, capabilities, and usage in AGENTS.md”.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Status flow: `UNVERIFIED` -> `PREPARING` -> `PENDING` -> `IN_PROGRESS` -> `SUCCESS`/`WARNING`/`FAILURE`/`CANCELED`
- Completion flow: `UNVERIFIED` -> `PREPARING` -> `PENDING` -> `IN_PROGRESS` -> `SUCCESS`/`WARNING`/`FAILURE`
- Cancellation outcome: `CANCELING`, jobs with no tasks, and jobs with only canceled tasks become `CANCELED`.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@AGENTS.md` at line 71, Update the status flow documentation in AGENTS.md to
show that CANCELED may follow CANCELING and may result when a job has no
remaining tasks or only canceled tasks, rather than implying it only follows
IN_PROGRESS. Preserve the existing transitions and clearly separate these
cancellation outcomes while maintaining the document’s current structure.

Source: Coding guidelines

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.

1 participant