refactor(cron): trim will_retry docstring and rename its yield test

WHY: the salvaged docstring narrated the incident and referenced another PR;
replace it with the invariant the predictor must hold. The test only covers
the yield branch, so drop "terminal_paths" from its name.
This commit is contained in:
kshitijk4poor
2026-09-26 18:23:36 +05:30
committed by kshitij
parent a31e3a6b94
commit 27760e6715
2 changed files with 4 additions and 21 deletions

View File

@@ -68,26 +68,9 @@ def _is_recurring(job: Dict[str, Any]) -> bool:
def will_retry(job: Dict[str, Any]) -> bool:
"""Predict whether ``plan_retry`` will schedule a re-run for this flagged failure —
used by the scheduler to suppress the interim failure notice.
Must mirror ``plan_retry`` (and the ``mark_job_run`` guards around it) decision-for-
decision, so a notice is held exactly when a re-run really is coming:
- exhausted ladder / disabled / paused / non-recurring → no re-run;
- the yield branch: when the schedule's own next occurrence lands at or before the
pending rung, ``plan_retry`` schedules nothing (the natural fire IS the retry).
Without this mirror, a job on a cadence at or under a rung held EVERY failure
notice for as long as the outage lasted: each failure yielded without consuming an
attempt, so the "once the ladder is exhausted, the next failure alerts normally"
escape in the suppression contract was unreachable and the operator saw silence.
(The final run of a finite repeat is a separate terminal-state edge handled by
#109991.)
Called before ``mark_job_run`` records the run; the occurrence is recomputed exactly
as ``_advance_after_run`` will (delivery-time skew between here and the store write
can only err toward delivering the notice, never toward suppressing it unheard).
"""
"""True iff ``plan_retry`` will park a re-run for this flagged failure, so the scheduler
may hold the interim notice: recurring, unpaused, ladder not exhausted, enabled, and the
rung strictly before the natural occurrence. Called before ``mark_job_run``."""
if not _is_recurring(job) or job.get("state") == "paused":
return False
state = job.get(STATE_KEY) or {}

View File

@@ -75,7 +75,7 @@ def test_unreachable_failure_pulls_next_run_earlier_then_ladder_exhausts(
assert weekly["id"] not in {due["id"] for due in get_due_jobs()}
def test_will_retry_mirrors_plan_retry_yield_and_terminal_paths(tmp_cron_home):
def test_will_retry_mirrors_plan_retry_yield(tmp_cron_home):
"""The notice-suppression predictor must mirror what ``plan_retry`` will actually do
for THIS failure: