The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): fire an outage-skipped one-shot whose fire claim never landed
kshitijk4poor54a079f76c83
diff --git a/cron/jobs.py b/cron/jobs.pyindex 8c132fe0e60..198299d93a3 100644--- a/cron/jobs.py+++ b/cron/jobs.py@@ -3159,7 +3159,11 @@ def _retire_expired_oneshot(d: _DueJob) -> bool:# Due during an outage of its store: it was skipped, not missed; fire it once on recovery.if store_health.outage_covers(_current_cron_store().cron_dir, d.next_run_dt.timestamp(), ONESHOT_GRACE_SECONDS):return False- if not (d.job.get("run_claim") or d.job.get("fire_claim")):+ claim = d.job.get("run_claim")+ # An outage-covered claim that never reached its fire claim never started: it stays covered.+ if isinstance(claim, dict) and claim.get("outage") and not d.job.get("fire_claim"):+ return False+ if not (claim or d.job.get("fire_claim")):_write_missed_oneshot_diagnostic(d.job, d.next_run)d.scan.retire(d.job["id"])d.scan.on_saved.append(lambda job=d.job: record_cron_missed(job))@@ -3286,6 +3290,8 @@ def _evaluate_due_job(job: Dict[str, Any], scan: _DueScan, run_claim_ttl: float)# fixed window is not enough for a run that outlives a tick. The other process sees the# fresh claim and skips; mark_job_run() clears it. The TTL only covers a tick that DIES.claim = {"at": now.isoformat(), "by": _machine_id()}+ if _elapsed_seconds(now, d.next_run_dt) > ONESHOT_GRACE_SECONDS: # only an outage lets it through+ claim["outage"] = Truejob["run_claim"] = claimscan.persist(job["id"], run_claim=claim)diff --git a/tests/cron/test_due_scan_save_failure.py b/tests/cron/test_due_scan_save_failure.pyindex 242e825e15e..2e0c3c44b66 100644--- a/tests/cron/test_due_scan_save_failure.py+++ b/tests/cron/test_due_scan_save_failure.py@@ -249,6 +249,11 @@ def test_skipped_oneshot_survives_recovery_by_any_save(cron_store, monkeypatch):assert [d["id"] for d in get_due_jobs()] == ["once"]save_jobs(load_jobs()) # second recoveryassert [d["id"] for d in get_due_jobs()] == ["once"]+ # Its fire claim never landed: the live run claim skips it (that saved scan ends the+ # recovery window), and once the claim expires it still fires instead of staying stuck.+ assert get_due_jobs() == []+ clock["now"] += timedelta(minutes=31)+ assert [d["id"] for d in get_due_jobs()] == ["once"]stale = dict(once, id="stale") # due during the outage, first scanned after the recovery scansave_jobs(load_jobs() + [stale])assert "stale" not in [d["id"] for d in get_due_jobs()]