diff --git a/cron/jobs.py b/cron/jobs.py index 1dfc7fe355..8a82fdcbad 100644 --- a/cron/jobs.py +++ b/cron/jobs.py @@ -2401,11 +2401,7 @@ def _record_run_outcome( job["last_status"] = status or ( "error" if not success else ("delivery_failed" if delivery_failed else "ok")) cancelled = status == "cancelled" # an operator stop is not a failure - # Sticky stamps written before #155355 can hold raw credentials, and every outcome below - # rewrites jobs.json while keeping whichever of them it doesn't replace: scrub them in place. - for retained in (job.get("last_failure"), job.get("last_fire_error")): - if isinstance(retained, dict) and retained.get("detail"): - retained["detail"] = jobs_error_text.sanitize_persisted_error(str(retained["detail"])) + jobs_error_text.scrub_retained_stamps(job) job["last_error"] = None if success or cancelled else jobs_error_text.sanitize_persisted_error(error) if success: # Healthy run: drop the alert-once dedup markers so a FUTURE break re-alerts, and clear diff --git a/cron/jobs_error_text.py b/cron/jobs_error_text.py index 751fffba49..1403aff101 100644 --- a/cron/jobs_error_text.py +++ b/cron/jobs_error_text.py @@ -27,3 +27,14 @@ def sanitize_persisted_error(error: Optional[str]) -> Optional[str]: logger.warning("Failed to redact cron error before persisting it", exc_info=True) return "[REDACTED - redaction failed]" return text[:MAX_PERSISTED_ERROR_CHARS] + + +def scrub_retained_stamps(job: dict) -> None: + """Scrub, in place, the sticky stamps a run outcome keeps (``last_failure``, ``last_fire_error``). + + Stamps written before #155355 can hold raw credentials, and every run outcome rewrites + jobs.json while keeping whichever of them it doesn't replace. + """ + for retained in (job.get("last_failure"), job.get("last_fire_error")): + if isinstance(retained, dict) and retained.get("detail"): + retained["detail"] = sanitize_persisted_error(str(retained["detail"]))