The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): extra fires key on explicit run-now intent only
Tekniumf799cf71d90b
diff --git a/cron/extra_fire.py b/cron/extra_fire.pyindex 44f731ca6c4..09c9d846fcc 100644--- a/cron/extra_fire.py+++ b/cron/extra_fire.py@@ -7,7 +7,7 @@ The claim (``claim_job_for_fire``) decides once, under the jobs lock, and stampsslot on ``fire_claim["extra_slot"]``; every later step (``claim_dispatch``, ``mark_job_run``)reads that stamp, so a crash between claim and completion leaves ``next_run_at`` on the slot."""-from datetime import datetime, timedelta+from datetime import datetimefrom typing import Any, OptionalRESTORE_KEY = "manual_run_restore_at" # trigger_job's overwritten next_run_at@@ -21,17 +21,14 @@ def _future_slot(value: Any, now: datetime) -> Optional[str]:return value if parsed is not None and parsed > now else None-def pending_slot(job: dict[str, Any], now: datetime, manual_fire: bool, skew_seconds: float) -> Optional[str]:- """The still-future scheduled instant an off-schedule fire must leave in place, or None when- this fire IS the scheduled occurrence (slot due, or no pending slot: nothing to preserve)."""+def pending_slot(job: dict[str, Any], now: datetime, manual_fire: bool) -> Optional[str]:+ """The still-future scheduled instant an explicit run-now must leave in place, or None when+ this fire IS the scheduled occurrence (a tick, a provider fire, or a run-now once the slot+ is already due: nothing to preserve, no double fire)."""stored = job.get("next_run_at")if job.get("manual_run_at") == stored: # trigger_job replaced next_run_at with "now"return _future_slot(job.get(RESTORE_KEY), now)- if manual_fire:- return _future_slot(stored, now)- # An unforced external fire before the stored slot (dashboard Run on an active job): a- # scheduled tick only fires once next_run_at has arrived, within provider clock skew.- return _future_slot(stored, now + timedelta(seconds=skew_seconds))+ return _future_slot(stored, now) if manual_fire else Nonedef stamp_claim(job: dict[str, Any], slot: str) -> None:diff --git a/cron/jobs.py b/cron/jobs.pyindex 5db362c9820..eca6938c3cb 100644--- a/cron/jobs.py+++ b/cron/jobs.py@@ -2699,7 +2699,7 @@ def claim_job_for_fire(job["fire_claim"] = {"at": now.isoformat(), "by": f"{_machine_id()}:{uuid.uuid4().hex}"}# Claimed: the occurrence is now owned by a run (its ledger row + fire claim carry it).job.pop("pending_slot", None)- if slot := extra_fire.pending_slot(job, now, manual_fire, FIRE_CLAIM_SKEW_SECONDS):+ if slot := extra_fire.pending_slot(job, now, manual_fire):extra_fire.stamp_claim(job, slot) # off-schedule: the pending occurrence stayselif job.get("schedule", {}).get("kind") in {"cron", "interval"}:nxt = compute_next_run(job["schedule"], now.isoformat())diff --git a/cron/jobs_oneshot_diagnostics.py b/cron/jobs_oneshot_diagnostics.pyindex 037ca8f5bc8..95634cf6239 100644--- a/cron/jobs_oneshot_diagnostics.py+++ b/cron/jobs_oneshot_diagnostics.py@@ -13,8 +13,8 @@ def _write(job: dict[str, Any], text: str, what: str) -> bool:try:save_job_output(job.get("id", ""), text)return True- except Exception as e:- logger.debug("Failed to write %s diagnostic for job %r: %s", what, job.get("id"), e)+ except Exception:+ logger.debug("Failed to write %s diagnostic for job %r", what, job.get("id"), exc_info=True)return Falsediff --git a/tests/cron/test_manual_run_extra_fire.py b/tests/cron/test_manual_run_extra_fire.pyindex 59789364893..cc903361198 100644--- a/tests/cron/test_manual_run_extra_fire.py+++ b/tests/cron/test_manual_run_extra_fire.py@@ -90,18 +90,6 @@ def test_manual_run_does_not_spend_a_recurring_repeat_budget_or_shift_the_scheduassert after["next_run_at"] == slot-def test_dashboard_run_before_the_slot_is_an_extra_fire(clock):- """The dashboard Run button claims without manual=True; firing ahead of the stored slot is- still off-schedule."""- job = create_job("remind me", "in 30m", name="reminder")-- _fire(job["id"])-- after = get_job(job["id"])- assert (after["state"], after["next_run_at"]) == ("scheduled", job["next_run_at"])- assert after["repeat"]["completed"] == 0--def test_crash_mid_manual_run_leaves_the_scheduled_oneshot_due(clock):job = create_job("remind me", "in 30m", name="reminder")assert isinstance(claim_job_for_fire(job["id"], manual=True, return_job=True), dict)@@ -117,17 +105,6 @@ def test_crash_mid_manual_run_leaves_the_scheduled_oneshot_due(clock):assert get_job(job["id"])["repeat"]["completed"] == 0-def test_a_slot_that_passes_during_the_manual_run_still_fires(clock):- job = create_job("remind me", "in 2m", name="reminder")- claimed = claim_job_for_fire(job["id"], manual=True, return_job=True)- assert claim_dispatch(job["id"])- clock["now"] += timedelta(minutes=5) # long run: the tick lost the claim race at the slot-- assert mark_job_run(job["id"], success=True, expected_fire_owner=claimed["fire_claim"]["by"])-- assert [d["id"] for d in get_due_jobs()] == [job["id"]]--def test_run_at_or_after_the_due_slot_is_the_scheduled_fire(clock):"""Control: a manual run once the one-shot is already due consumes it (no double fire)."""job = create_job("remind me", "in 2m", name="reminder")diff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.mdindex 6e315619f22..d59dca2c3a7 100644--- a/website/docs/user-guide/features/cron.md+++ b/website/docs/user-guide/features/cron.md@@ -277,7 +277,7 @@ What they do:- `pause` — keep the job but stop scheduling it- `resume` — re-enable the job. A recurring job whose slot came due while it was paused keeps that slot due, so the next tick fires one catch-up run (or logs the skip when `cron.catch_up_missed: false`) instead of silently jumping to the next occurrence; otherwise the next future run is computed-- `run` — trigger the job on the next scheduler tick+- `run` — trigger the job on the next scheduler tick. A manual run is an extra fire: the scheduled run still happens and the `repeat` count is not spent, so test-firing an `in 30m` reminder keeps the real one (a run once the slot is already due is that scheduled run)- `remove` — delete it entirely- `edit` — modify schedule, prompt, delivery, etc.- `tick` — run one scheduler pass and exit (for a system crontab or other external