From 51e263894cfd8d6f8d7270031b1353c39c638606 Mon Sep 17 00:00:00 2001 From: MorAlekss Date: Sat, 25 Apr 2026 02:54:59 -0700 Subject: [PATCH] fix(cron): silent skip when context_from job has no output yet --- cron/scheduler.py | 22 ++++------------------ tests/cron/test_cron_context_from.py | 6 ++++-- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/cron/scheduler.py b/cron/scheduler.py index 5924ba19e6..32b351aa04 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -685,22 +685,14 @@ def _build_job_prompt(job: dict, prerun_script: Optional[tuple] = None) -> str: try: job_output_dir = OUTPUT_DIR / source_job_id if not job_output_dir.exists(): - prompt = ( - f"[Context job '{source_job_id}' has no output yet.]\n\n" - f"{prompt}" - ) - continue + continue # silent skip — no output yet output_files = sorted( job_output_dir.glob("*.md"), key=lambda f: f.stat().st_mtime, reverse=True, ) if not output_files: - prompt = ( - f"[Context job '{source_job_id}' has no output yet.]\n\n" - f"{prompt}" - ) - continue + continue # silent skip — no output yet latest_output = output_files[0].read_text(encoding="utf-8").strip() # Truncate to 8K characters to avoid prompt bloat _MAX_CONTEXT_CHARS = 8000 @@ -715,16 +707,10 @@ def _build_job_prompt(job: dict, prerun_script: Optional[tuple] = None) -> str: f"{prompt}" ) else: - prompt = ( - f"[Context job '{source_job_id}' has no output yet.]\n\n" - f"{prompt}" - ) + continue # silent skip — empty output except (OSError, PermissionError) as e: logger.warning("context_from: failed to read output for job %r: %s", source_job_id, e) - prompt = ( - f"[Context job '{source_job_id}' output could not be read.]\n\n" - f"{prompt}" - ) + # silent skip — do not pollute the prompt with error messages # Always prepend cron execution guidance so the agent knows how # delivery works and can suppress delivery when appropriate. diff --git a/tests/cron/test_cron_context_from.py b/tests/cron/test_cron_context_from.py index 014a8d7aa7..e3103f76fe 100644 --- a/tests/cron/test_cron_context_from.py +++ b/tests/cron/test_cron_context_from.py @@ -132,9 +132,11 @@ class TestBuildJobPromptContextFrom: prompt="Summarize", schedule="every 2h", context_from=job_a["id"] ) - # job_a ещё не запускался — output dir не существует + # job_a never ran — output dir does not exist + # expect silent skip: no placeholder injected, base prompt intact prompt = _build_job_prompt(job_b) - assert "no output yet" in prompt.lower() or "not found" in prompt.lower() + assert "no output" not in prompt.lower() + assert "not found" not in prompt.lower() assert "Summarize" in prompt def test_injects_multiple_context_jobs(self, cron_env):