The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): deliver [CRON_FAILURE] evidence verbatim, not through provider heuristics
teknium19f48f4ed04ef
diff --git a/cron/scheduler.py b/cron/scheduler.pyindex 8a20a250e61..d7cf8d38ca0 100644--- a/cron/scheduler.py+++ b/cron/scheduler.py@@ -2567,10 +2567,12 @@ def _classify_delivery_outcome(def _compose_run_delivery(job: dict, *, success: bool, error, final_response: str, output_file,+ agent_declared: bool = False,) -> tuple[str, bool, bool, bool, Optional[str]]:"""Text to deliver for a finished run. Returns ``(deliver_content, blocked_config,silent_alert, incident_acked, failure_incident_id)``; ``silent_alert``: an alert-once marker- says the operator was already told, deliver nothing."""+ says the operator was already told, deliver nothing. ``agent_declared``: *error* is the+ agent's own ``[CRON_FAILURE]`` evidence, delivered verbatim."""err = str(error) if error else ""# Failed jobs always deliver, except blocked-config runs, which alert exactly ONCE.blocked_config_silent = BLOCKED_CONFIG_SILENT_MARKER in err@@ -2593,6 +2595,14 @@ def _compose_run_delivery()if incident_acked:deliver_content = ""+ elif agent_declared:+ # The agent already diagnosed the failure in prose; the summarizer's substring+ # heuristics would re-diagnose it ("timed out" -> blame the model service, "401" ->+ # "sign in again") and attach the wrong remediation. Deliver the evidence as-is.+ from cron.scheduler_failure_copy import generic_failure_notice+ deliver_content = generic_failure_notice(+ job.get("name") or job["id"], job["id"], err.strip().rstrip("."),+ ) + _failure_streak_nudge(job)else:deliver_content = (_summarize_cron_failure_for_delivery(job, error) + _failure_streak_nudge(job)@@ -2649,6 +2659,9 @@ class _RunDelivery:should_deliver: bool = Falseunresolved_origin: bool = Falseblocked_config: bool = False+ # True when ``error`` is the agent's own ``[CRON_FAILURE]`` evidence rather than a runtime+ # error string, so composition must not run it through the provider-error heuristics.+ agent_declared: bool = Falseincident_acked: bool = Falsefailure_incident_id: Optional[str] = Noneside_effect_ownership_lost: bool = False@@ -2684,7 +2697,7 @@ def _save_compose_deliver(deliver_content, d.blocked_config, _silent_alert, d.incident_acked, d.failure_incident_id,) = _compose_run_delivery(job, success=d.success, error=d.error, final_response=final_response,- output_file=output_file)+ output_file=output_file, agent_declared=d.agent_declared)# Whitespace-only == empty: skip delivery; the guard below marks it a soft failure.d.should_deliver = bool(deliver_content.strip()) and not _silent_alertif d.should_deliver and not d.success and job.get("_model_unreachable"):@@ -2946,14 +2959,15 @@ def _run_one_job_body(# An agent can finish its own turn after a delegated child has failed. Let it explicitly# declare that semantic failure so the existing failure path updates status, streaks,# ledger, and notification routing instead of recording a false healthy result.+ agent_declared = Falseif success and not job.get("no_agent"):marker_error = _cron_failure_marker_error(final_response)if marker_error is not None:- success, error = False, marker_error+ success, error, agent_declared = False, marker_error, True# Agent is still live through delivery; wrap ALL of save/compose/deliver in try/finally so a# raise anywhere still tears the deferred agent down.- d = _RunDelivery(job=job, success=success, error=error)+ d = _RunDelivery(job=job, success=success, error=error, agent_declared=agent_declared)try:_save_compose_deliver(d, fence, final_response, output, adapters=adapters, loop=loop, verbose=verbose,diff --git a/tests/cron/test_run_one_job.py b/tests/cron/test_run_one_job.pyindex ec95a0efdcb..60fd0f66be5 100644--- a/tests/cron/test_run_one_job.py+++ b/tests/cron/test_run_one_job.py@@ -92,6 +92,22 @@ def test_run_one_job_agent_declared_failure_uses_failure_bookkeeping(monkeypatchassert calls[-1] == ("mark", "declared-failure", False)+def test_run_one_job_agent_declared_failure_is_delivered_verbatim(monkeypatch):+ """The agent's own evidence reaches the operator as written, not re-diagnosed by the+ provider-error heuristics (a child that "timed out" is not a model-service timeout)."""+ delivered = []+ evidence = "The export subagent timed out after 30 minutes waiting on the database."+ _patch_pipeline(monkeypatch, final=f"[CRON_FAILURE]\n{evidence}")+ monkeypatch.setattr(+ s, "_deliver_result", lambda job, content, **kw: delivered.append(content))++ s.run_one_job({"id": "verbatim", "name": "nightly export", "deliver": "telegram"})++ assert len(delivered) == 1+ assert evidence.rstrip(".") in delivered[0]+ assert "model service" not in delivered[0]++def test_run_one_job_marker_mentioned_in_report_stays_successful(monkeypatch):"""Only the exact first line is control text; quoted markers remain report content."""calls = _patch_pipeline(