{{ message }}
fix(alerts): recover reports stuck in WORKING state after worker crash#39533
Draft
fix(alerts): recover reports stuck in WORKING state after worker crash#39533
Conversation
When a Celery worker pod crashes mid-execution, the report stays in WORKING state until working_timeout expires (up to 1 hour), then transitions to ERROR instead of retrying. This adds a stale detection threshold (ALERT_REPORTS_STALE_WORKING_TIMEOUT, default 300s). When a requeued worker sees a WORKING state older than this threshold, it resets to NOOP and re-executes rather than blocking with PreviousWorkingError. The existing working_timeout path (ERROR) is preserved for genuinely runaway jobs. Also refactors is_on_working_timeout() to accept an already-fetched log, eliminating a redundant DB query on every working-state evaluation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add actionable guidance to the working_timeout field so users know to set it relative to their report's typical execution time. Previously the description only said the field resets a stalled alert to error, with no guidance on what value to choose. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eschutho
commented
Apr 22, 2026
| ALERT_REPORTS_DEFAULT_CRON_VALUE = "0 0 * * *" # every day | ||
| # Minimum elapsed time (seconds) before a WORKING state is considered stale | ||
| # (e.g. due to a crashed Celery worker) and eligible for reset + retry. | ||
| # Must be less than working_timeout on any schedule. |
Member
Author
There was a problem hiding this comment.
Suggested change
| # Must be less than working_timeout on any schedule. | |
| # It would ideally be less than working_timeout on any schedule. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39533 +/- ##
==========================================
+ Coverage 64.54% 64.56% +0.01%
==========================================
Files 2559 2561 +2
Lines 133496 133480 -16
Branches 31028 31018 -10
==========================================
+ Hits 86168 86183 +15
+ Misses 45836 45803 -33
- Partials 1492 1494 +2 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Fixes a bug where alert/report schedules get permanently stuck in
WORKINGstate when a Celery worker pod crashes mid-execution (SC-104379).Root cause: When a pod crashes, the report stays in
WORKINGstate. On broker requeue, the new worker entersReportWorkingState.next()and raisesReportSchedulePreviousWorkingError— blocking re-execution for up to 1 hour untilworking_timeoutexpires, at which point it transitions toERRORrather than retrying.Fix: Adds a three-branch state machine in
ReportWorkingState.next():elapsed >= working_timeout→ ERROR (existing behavior — genuinely runaway job)elapsed >= ALERT_REPORTS_STALE_WORKING_TIMEOUT(new config, default 300s) → reset to NOOP and re-execute viaReportNotTriggeredErrorStateelapsed < stale threshold→PreviousWorkingError(existing behavior — might be legitimately running)Also refactors
is_on_working_timeout()to accept an already-fetched log, eliminating a redundant DB query on every working-state evaluation.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change.
TESTING INSTRUCTIONS
pytest tests/unit_tests/commands/report/execute_test.pyWORKINGstate), restart the worker, confirm the report re-executes rather than staying stuck untilworking_timeoutexpires.ADDITIONAL INFORMATION
New config key:
ALERT_REPORTS_STALE_WORKING_TIMEOUT(seconds, default 300). Must be less thanworking_timeouton any schedule.