Skip to content

The agent that grows with you

fix(cron): an origin-less canonical run is not_configured, not queued then delivered

Teknium582ffc368132
diff --git a/cron/scheduler.py b/cron/scheduler.py
index 5dff45b87db..ecbc571e07e 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -3141,10 +3141,16 @@ def _save_compose_deliver(
if not d.should_deliver:
return
+ d.unresolved_origin = (
+ _normalize_deliver_value(_delivery_lane_value(job, for_failure=not d.success)) == "origin"
+ and not _resolve_delivery_targets(job, for_failure=not d.success)
+ )
execution_id = job.get('execution_id')
if execution_id and not job.get('no_agent'):
from cron.delivery_queue import enqueue
- if _normalize_deliver_value(_delivery_lane_value(job, for_failure=not d.success)) == "local":
+ # Nothing to send: an origin-less job is ``not_configured``, never a queued "delivery".
+ if d.unresolved_origin or _normalize_deliver_value(
+ _delivery_lane_value(job, for_failure=not d.success)) == "local":
return
queued_job = dict(job)
if d.failure_incident_id:
@@ -3159,10 +3165,6 @@ def _save_compose_deliver(
d.delivery_attempted = True
job['last_delivery_queued'] = {'canonical': {'status': queued['status'], 'execution_id': execution_id}}
return
- d.unresolved_origin = (
- _normalize_deliver_value(_delivery_lane_value(job, for_failure=not d.success)) == "origin"
- and not _resolve_delivery_targets(job, for_failure=not d.success)
- )
try:
with fence.side_effect_fence() as owns_delivery:
if not owns_delivery:
diff --git a/tests/cron/test_queued_delivery_fencing.py b/tests/cron/test_queued_delivery_fencing.py
index 506030ab112..2141b08ec4d 100644
--- a/tests/cron/test_queued_delivery_fencing.py
+++ b/tests/cron/test_queued_delivery_fencing.py
@@ -44,3 +44,14 @@ def test_dead_drain_owner_settles_the_run_it_fenced_unknown(tmp_path, monkeypatc
assert sent == [], "an uncertain send is never retried"
assert saved["last_status"] == "delivery_failed" and "unknown" in saved["last_delivery_error"]
assert executions.get_execution(execution["id"])["delivery_outcome"] == "failed"
+
+
+def test_origin_with_no_resolvable_target_is_not_configured_never_delivered(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ monkeypatch.setattr(scheduler, "run_job", lambda job, **kw: (True, "raw", "the result", None))
+ job = jobs.create_job(prompt="p", schedule="every 1h", deliver="origin")
+ scheduler.run_one_job(job)
+ execution = executions.latest_execution(job["id"])
+ assert delivery_queue.get_status(execution["id"]) is None, "no target: nothing is queued"
+ assert execution["delivery_outcome"] == "not_configured"
+ assert jobs.get_job(job["id"])["last_status"] == "ok"