Support ML async job cancellation, fail jobs on redis errors#13
Closed
Support ML async job cancellation, fail jobs on redis errors#13
Conversation
JobState(str, OrderedEnum) was using str's lexicographic __gt__ instead of OrderedEnum's definition-order __gt__, because str comes first in the MRO. This caused max(FAILURE, SUCCESS) to return SUCCESS, silently discarding failure state in concurrent job progress updates. Fix: __init_subclass__ injects comparison methods directly onto each subclass so they take MRO priority over data-type mixins. Also preserve FAILURE status through the progress ternary when progress < 1.0, so early failure detection isn't overwritten. Co-Authored-By: Claude <noreply@anthropic.com>
The NATS message is ACK'd at line 145, before update_state() and _update_job_progress(). If either of those raises, the except block was logging "NATS will redeliver" when it won't. Co-Authored-By: Claude <noreply@anthropic.com>
… carlosg/redisatomic
…livery For async_api jobs, the Celery task completes after queuing images to NATS, so task.revoke() has no effect. The worker kept pulling tasks via the /tasks endpoint because it only checked final_states(), not CANCELING. - Add JobState.active_states() (STARTED, RETRY) for positive task-serving check - /tasks endpoint returns empty unless job is in active_states() - Job.cancel() for async_api jobs: clean up NATS/Redis, then set REVOKED Co-Authored-By: Claude <noreply@anthropic.com>
canRetry now excludes CANCELING so the Retry button stays hidden during the drain period, matching the backend's transitional state. Co-Authored-By: Claude <noreply@anthropic.com>
When a job is canceled, NATS/Redis cleanup runs before in-flight results finish processing. The resulting "Redis state missing" message is expected, not an error. Co-Authored-By: Claude <noreply@anthropic.com>
Covers all monitoring points for NATS async jobs: Django ORM, REST API, tasks endpoint, NATS consumer state, Redis counters, Docker logs, and AMI worker logs. Linked from CLAUDE.md and the test_ml_job_e2e command. Co-Authored-By: Claude <noreply@anthropic.com>
Tests need to set job status to STARTED since the /tasks endpoint now only serves tasks for jobs in active_states() (STARTED, RETRY). Co-Authored-By: Claude <noreply@anthropic.com>
mihow
approved these changes
Feb 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request builds on RolnickLab#1150 and it's based off
carlos/redisatomicThis pull request introduces a new chaos testing management command for fault injection and refactors async job cleanup logic to improve reliability and resilience. The most important changes include the addition of a manual chaos testing utility, improved job log handling to prevent lost logs, and a more robust cleanup of async resources for jobs using Redis and NATS. The cleanup logic is now more consistent and reliable, especially in failure and cancellation scenarios.
chaos_monkey.pymanagement command for manual fault injection of Redis and NATS, allowing developers to flush or pause these services to simulate outages and test job resilience.cleanup_async_job_resourcesto accept job ID and logger instead of a Job instance, ensuring cleanup can occur even if the Job object is unavailable and improving logging consistency._fail_jobhelper to mark jobs as failed and trigger async resource cleanup when Redis state is missing, improving failure handling in NATS pipeline results.REVOKEDfor async jobs._stream_existscheck in NATS queue orchestration to avoid unnecessary stream creation and improve error handling when reserving tasks.How to Test the Changes
Start a job with e.g.:
Then either cancel it in the UI or flush/stop Redis
Screenshots
Known Issues
Occasionally the Error logs get overwritten by another worker and hence the error won't be displayed, which is a known issue with the job logger.
Deployment Notes
Include instructions if this PR requires specific steps for its deployment (database migrations, config changes, etc.)
Checklist