The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): manual run reports delivery_failed as a failed run; docs for the distinct status
Teknium758114bb8dfc
diff --git a/tests/tools/test_cronjob_run_delivery_notice.py b/tests/tools/test_cronjob_run_delivery_notice.pyindex ff3aebe1980..e82b2ad0908 100644--- a/tests/tools/test_cronjob_run_delivery_notice.py+++ b/tests/tools/test_cronjob_run_delivery_notice.py@@ -199,7 +199,9 @@ class TestRunnerSummaryWiring:patch("tools.cronjob_tools.get_job",return_value={- "last_status": "ok",+ # Post-#83993 record shape: mark_job_run writes+ # delivery_failed (not ok) when only delivery failed.+ "last_status": "delivery_failed","last_error": None,"last_delivery_error": "telegram send failed: 400",},@@ -214,6 +216,9 @@ class TestRunnerSummaryWiring:assert "delivery FAILED" in summaryassert "telegram send failed: 400" in summaryassert "delivered there by the job itself" not in summary+ # The headline must not read "Result: ok" over an undelivered run.+ assert "Result: FAILED" in summary+ assert "Result: ok" not in summarydef test_empty_deliver_summary_states_local_not_phantom_target(self):"""End-to-end: an empty stored deliver must render as the local targetdiff --git a/tests/tools/test_cronjob_run_immediate.py b/tests/tools/test_cronjob_run_immediate.pyindex beb8c098c3c..aa0eb8b97f7 100644--- a/tests/tools/test_cronjob_run_immediate.py+++ b/tests/tools/test_cronjob_run_immediate.py@@ -291,3 +291,37 @@ class TestCronjobRunExecutesImmediately:assert len(calls) >= 2, callsfinally:set_activity_callback(None)+++class TestManualRunReportsDeliveryFailure:+ """#83993: a manual run whose agent succeeded but whose delivery failed+ must not come back as success=True with no error — the calling agent+ relays that result to the user."""++ def test_delivery_failed_status_is_not_success_and_surfaces_reason(self):+ refreshed = {+ "id": "job-run-1",+ "last_status": "delivery_failed",+ "last_error": None,+ "last_delivery_error": "live adapter send failed: 502 (target telegram:123)",+ }+ with patch("tools.cronjob_tools.claim_job_for_fire",+ return_value={**_JOB, "fire_claim": {"by": "manual-owner"}}), \+ patch("cron.scheduler.run_one_job", return_value=True), \+ patch("tools.cronjob_tools.get_job", return_value=refreshed):+ res = _execute_job_now(dict(_JOB))++ assert res["claimed"] is True+ assert res["success"] is False+ assert "502" in res["error"]++ def test_plain_ok_is_still_success_with_no_error(self):+ with patch("tools.cronjob_tools.claim_job_for_fire",+ return_value={**_JOB, "fire_claim": {"by": "manual-owner"}}), \+ patch("cron.scheduler.run_one_job", return_value=True), \+ patch("tools.cronjob_tools.get_job",+ return_value={"id": "job-run-1", "last_status": "ok", "last_error": None,+ "last_delivery_error": None}):+ res = _execute_job_now(dict(_JOB))+ assert res["success"] is True+ assert res["error"] is Nonediff --git a/tools/cronjob_tools.py b/tools/cronjob_tools.pyindex ec55fdce799..6326ec59c79 100644--- a/tools/cronjob_tools.py+++ b/tools/cronjob_tools.py@@ -1124,11 +1124,21 @@ def _run_claimed_job(_registered = Falserelease_running_job(job_id)refreshed = get_job(job_id) or {}- ok = refreshed.get("last_status") == "ok"+ last_status = refreshed.get("last_status")+ # "delivery_failed" (#83993): the agent run itself succeeded but the+ # output never reached the user. That is NOT a success for the caller+ # — the calling agent relays this result — so report it as failed+ # and surface the delivery error, which lives in last_delivery_error+ # (last_error is None for these runs, and a bare success=False with+ # error=None reads as an unexplained failure).+ ok = last_status == "ok"+ run_error = refreshed.get("last_error")+ if last_status == "delivery_failed" and not run_error:+ run_error = refreshed.get("last_delivery_error")return {"claimed": True,"success": bool(processed and ok),- "error": refreshed.get("last_error"),+ "error": run_error,}except Exception as e:diff --git a/website/docs/user-guide/features/cron.md b/website/docs/user-guide/features/cron.mdindex 410237b6f5e..1290dbdd79c 100644--- a/website/docs/user-guide/features/cron.md+++ b/website/docs/user-guide/features/cron.md@@ -440,6 +440,19 @@ When scheduling jobs, you specify where the output goes:The agent's final response is automatically delivered to the configured `deliver:` target — the agent does not send messages itself, so there is nothing to call in the cron prompt.+### Delivery failures are a distinct status++Execution and delivery are tracked separately. When the agent run succeeds but+the output never reaches the target (platform 5xx, rate limit, stale session,+adapter returned no positive evidence of a send), the job records+`last_status: delivery_failed` — never a plain `ok` — with the reason in+`last_delivery_error`. `hermes cron list` shows it in yellow as+`delivery_failed: <reason>`, `hermes cron doctor` reports it as a delivery+issue, and a manual `cronjob run` reports `success: false` with the delivery+error. A delivery failure does not count toward the job's `failure_streak`+(the agent did its job); the next fully successful run returns the status to+`ok`.+### Bot Chat delivery (`bot-chat`)`bot-chat` delivers the output **into a profile's canonical "Bot Chat" session as a real message**. Unlike every other target — where the recipient is a human reading a channel — the recipient here is the bot itself: it receives the output as an incoming message, acts on anything that needs action, and responds in its chat. Use it when scheduled output should be *processed*, not just posted.