Skip to content

fix: make failed alert completion recoverable - #741

Merged
MateoLostanlen merged 4 commits into
mainfrom
fix/recover-sequence-completion
Nov 18, 2026
Merged

MateoLostanlen merged 4 commits into
mainfrom
fix/recover-sequence-completion

Conversation

@frgfm

@frgfm frgfm commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Problem: After five alert-attachment failures, an already-validated sequence was permanently abandoned and its validation reason overwritten.

Change: Separate alert completion from validation and add admin APIs to list and retry failures. Recovery preserves the verdict and existing alert links, skips model inference, and sends no webhook, Telegram, or Slack notifications for the recovered event. Legacy NULL completion states can also finish safely.

Benefit: Admins can recover stranded alerts without database edits or rerunning validation.

Checks: 806 passed, 1 skipped; concurrency and migration checks passed.

Deployment: Stop old workers, apply the included migration, then restart. Existing failures require an explicit admin retry.


revision: str = "a9c2e5f7b1d3"
down_revision: Union[str, None] = "ff5b6d1f9e3f"
branch_labels: Union[str, Sequence[str], None] = None
revision: str = "a9c2e5f7b1d3"
down_revision: Union[str, None] = "ff5b6d1f9e3f"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Comment thread src/app/models.py
# Terminal states: the queue must never resurrect these.
TERMINAL_VALIDATION_STATUSES = (WINDOW_EXHAUSTED, VALIDATION_FAILED)
# Alert completion has its own retry budget; failures must never overwrite a verdict.
COMPLETION_PENDING = "pending"
Comment thread src/app/models.py
TERMINAL_VALIDATION_STATUSES = (WINDOW_EXHAUSTED, VALIDATION_FAILED)
# Alert completion has its own retry budget; failures must never overwrite a verdict.
COMPLETION_PENDING = "pending"
COMPLETION_COMPLETED = "completed"
Comment thread src/app/models.py
# Alert completion has its own retry budget; failures must never overwrite a verdict.
COMPLETION_PENDING = "pending"
COMPLETION_COMPLETED = "completed"
COMPLETION_FAILED = "failed"
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.73%. Comparing base (ba56d3c) to head (1a1499c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
+ Coverage   95.68%   95.73%   +0.05%     
==========================================
  Files          65       65              
  Lines        3685     3732      +47     
==========================================
+ Hits         3526     3573      +47     
  Misses        159      159              
Flag Coverage Δ
backend 95.89% <100.00%> (+0.05%) ⬆️
client 91.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frgfm frgfm self-assigned this Nov 6, 2026

@MateoLostanlen MateoLostanlen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @frgfm, thanks for the PR! Clean design, and the concurrency and migration tests are great.

A few small points, none blocking:

  • (nit) finish_sequence_completion only matches completion_status = 'pending'. If an old worker validates a row after the migration, the status stays NULL and the row loops forever in the queue. Accepting NULL too would make this safe even if the deploy order slips.
  • An admin retry days later still sends Telegram/Slack/webhook notifications for an old event. Is that what we want? Maybe skip notifications on retry, or past a certain age.
  • (nit) The code-quality bot comments on the Alembic globals and the COMPLETION_* constants are false positives, safe to ignore.

Happy to merge as is, or after the first point if you want to add it.

@frgfm frgfm added the type: fix Something isn't working label Nov 9, 2026
@frgfm
frgfm requested a review from MateoLostanlen November 9, 2026 09:41
@frgfm

frgfm commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

@MateoLostanlen all addressed ✅

import sqlalchemy as sa
from alembic import op

revision: str = "a9c2e5f7b1d3"
from alembic import op

revision: str = "a9c2e5f7b1d3"
down_revision: Union[str, None] = "f8b5c0d4e6a3"

@MateoLostanlen MateoLostanlen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @frgfm! I merged main and chained the migration after f8b5c0d4e6a3 to keep a single Alembic head. LGTM.

@MateoLostanlen
MateoLostanlen merged commit 156fec7 into main Nov 18, 2026
23 checks passed
@MateoLostanlen
MateoLostanlen deleted the fix/recover-sequence-completion branch November 18, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants