Skip to content

The agent that grows with you

fix(cron): isolate fire claim skew constant

KoNit-Kf967d9b8f11d
diff --git a/cron/constants.py b/cron/constants.py
new file mode 100644
index 00000000000..6c2896399e1
--- /dev/null
+++ b/cron/constants.py
@@ -0,0 +1,6 @@
+"""Stable cron constants safe for lazy imports after an on-disk upgrade."""
+
+# A hosted/webhook fire for the armed slot can arrive a few seconds before the stored
+# ``next_run_at`` (the fire scheduler's clock runs ahead of ours). Claims that early still own
+# the slot; only claims further ahead are off-tick manual/dashboard fires.
+FIRE_CLAIM_SKEW_SECONDS = 60
diff --git a/cron/jobs.py b/cron/jobs.py
index 98e26aa0b24..71c77030ec6 100644
--- a/cron/jobs.py
+++ b/cron/jobs.py
@@ -28,6 +28,7 @@ except ImportError: # pragma: no cover - non-Windows
from datetime import datetime, timedelta, timezone
from pathlib import Path
from hermes_constants import get_hermes_home
+from cron.constants import FIRE_CLAIM_SKEW_SECONDS
from cron.env_settings import cron_env_setting
from typing import Optional, Dict, List, Any, Callable, Set, Tuple, Union, Collection
@@ -928,10 +929,6 @@ _TELEMETRY_RECENT_HISTORY = 20
# A fire_claim younger than this is a live run (heartbeat cadence is 60 s). One value
# for claiming, one-shot re-arm, and stale-error recovery so they cannot disagree.
FIRE_CLAIM_TTL_SECONDS = 300
-# A hosted/webhook fire for the armed slot can arrive a few seconds before the stored
-# ``next_run_at`` (the fire scheduler's clock runs ahead of ours). Claims that early still own
-# the slot; only claims further ahead are off-tick manual/dashboard fires.
-FIRE_CLAIM_SKEW_SECONDS = 60
_persisted_error_recoveries_recent: list = []
diff --git a/cron/occurrences.py b/cron/occurrences.py
index 59e5d02cca3..bd0fd3464ef 100644
--- a/cron/occurrences.py
+++ b/cron/occurrences.py
@@ -20,8 +20,8 @@ def scheduled_instant(value):
def completed_occurrence(job, instant):
"""Unknown/failed/pruned attempts cannot prove completion: keep them eligible."""
+ from cron.constants import FIRE_CLAIM_SKEW_SECONDS
from cron.executions import _transaction
- from cron.jobs import FIRE_CLAIM_SKEW_SECONDS
instant = scheduled_instant(instant)
if instant is None:
diff --git a/tests/cron/test_upgrade_module_skew.py b/tests/cron/test_upgrade_module_skew.py
index 439f92366e1..a8511660af8 100644
--- a/tests/cron/test_upgrade_module_skew.py
+++ b/tests/cron/test_upgrade_module_skew.py
@@ -27,6 +27,18 @@ sys.modules.pop("cron.{store}", None)
import cron.{store}
"""
+_OCCURRENCES_SKEW_SCRIPT = """
+import cron.jobs as jobs
+
+# Model a daemon that loaded cron.jobs before this constant existed, then
+# lazy-loads the newer occurrences module from disk during a due scan.
+jobs.__dict__.pop("FIRE_CLAIM_SKEW_SECONDS", None)
+
+from cron.occurrences import completed_occurrence
+
+assert not completed_occurrence({"id": "job"}, "2026-01-01T00:00:00+00:00")
+"""
+
@pytest.mark.parametrize("store", ["notepad", "incidents", "executions", "delivery_queue"])
def test_lazy_cron_stores_import_against_pre_upgrade_sqlite_util(store):
@@ -40,3 +52,16 @@ def test_lazy_cron_stores_import_against_pre_upgrade_sqlite_util(store):
)
assert result.returncode == 0, result.stderr
+
+
+def test_occurrences_uses_skew_constant_without_cached_jobs_export():
+ repo_root = Path(__file__).resolve().parents[2]
+ result = subprocess.run(
+ [sys.executable, "-c", _OCCURRENCES_SKEW_SCRIPT],
+ cwd=repo_root,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+
+ assert result.returncode == 0, result.stderr