fix(cron): silent skip when context_from job has no output yet

This commit is contained in:
MorAlekss 2026-04-25 02:54:59 -07:00
parent eebeced7c4
commit 51e263894c
2 changed files with 8 additions and 20 deletions

View file

@ -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.

View file

@ -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):